Skip to content

Commit

Permalink
Remove deprecated class usage introduced with doctrine/orm ^2.14
Browse files Browse the repository at this point in the history
  • Loading branch information
dsentker committed Oct 6, 2023
1 parent 0e8890b commit 19abb92
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 32 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea/*
.idea/*
vendor/
composer.lock
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You can use this library to track changes to Doctrine Entities. Use annotations
* @Column(type="string")
* @WatchedField // <-- Watcher now tracks changes related to this field
*/
protected $emailAddress;
protected string $emailAddress;
```

***
Expand Down Expand Up @@ -96,7 +96,7 @@ Bugs and feature request are tracked on GitHub.

## ToDo
* Use interfaces for everything
* Easy Symfony4 integration
* Easy Symfony integration
* Write tests
* Optimize performance (group changes?)

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
}
],
"require": {
"php": "^5.5 || ^7.0",
"doctrine/orm": "2.*",
"php": "^7.3 || ^8.0",
"doctrine/orm": "2.14.*",
"doctrine/annotations": "1.*",
"psr/log": "^1.0",
"ext-mbstring": "*"
Expand Down
3 changes: 2 additions & 1 deletion src/Watcher/Annotations/WatchedField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Watcher\Annotations;

use Doctrine\ORM\Mapping\Annotation;
use Doctrine\ORM\Mapping\MappingAttribute;
use Watcher\ValueFormatter;

/**
* @Annotation
* @Target("PROPERTY")
*/
final class WatchedField implements Annotation
final class WatchedField implements MappingAttribute
{

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Watcher/EventListener/FlushListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function getUpdateHandler()
* @return WatchedField|null
* @throws \ReflectionException
*/
private function getWatchedFieldAnnotation(Reader $reader, WatchedEntity $entity, $field)
private function getWatchedFieldAnnotation(Reader $reader, WatchedEntity $entity, string $field): ?WatchedField
{

$dotPosition = strpos($field, '.');
Expand Down Expand Up @@ -159,7 +159,7 @@ private function getWatchedFieldAnnotation(Reader $reader, WatchedEntity $entity
public function onFlush(OnFlushEventArgs $args)
{

$em = $args->getEntityManager();
$em = $args->getObjectManager();
$uow = $em->getUnitOfWork();

$reader = $this->getAnnotationReader();
Expand Down Expand Up @@ -206,8 +206,6 @@ public function onFlush(OnFlushEventArgs $args)

// Associations
foreach ($uow->getScheduledCollectionUpdates() as $collectionUpdate) {
/** @var $collectionUpdate \Doctrine\ORM\PersistentCollection */


if ($collectionUpdate->getOwner() === $entity) {
// This entity has an association mapping which contains updates.
Expand All @@ -231,6 +229,5 @@ public function onFlush(OnFlushEventArgs $args)
}
}
}

}
}
13 changes: 4 additions & 9 deletions src/Watcher/EventListener/LoadListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Watcher\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\Persistence\Event\LifecycleEventArgs;
use Watcher\Entity\LogAccessor;
use Watcher\Repository\EntityLogRepository;

Expand All @@ -17,12 +17,7 @@ class LoadListener
/** @var string */
private $entityLogClassname;

/**
* LoadListener constructor.
*
* @param string $entityLogClassname
*/
public function __construct($entityLogClassname)
public function __construct(string $entityLogClassname)
{
if(!class_exists($entityLogClassname)) {
throw new \RuntimeException(sprintf('Invalid entity log classname "%s": Must be a full-qualified class name of the EntityLog.', $entityLogClassname));
Expand All @@ -36,12 +31,12 @@ public function __construct($entityLogClassname)
*/
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entity = $args->getObject();

if ($entity instanceof LogAccessor) {

/** @var EntityLogRepository $logRepo */
$logRepo = $args->getEntityManager()->getRepository($this->entityLogClassname);
$logRepo = $args->getObjectManager()->getRepository($this->entityLogClassname);
$entity->setLogs($logRepo->getLogsFromEntity($entity));
}

Expand Down
5 changes: 0 additions & 5 deletions src/Watcher/UpdateHandler/LogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ class LogHandler implements UpdateHandler
private $logLevel;


/**
* LogHandler constructor.
*
* @param LoggerInterface $logger
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
Expand Down
9 changes: 2 additions & 7 deletions src/Watcher/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
class Watcher
{

/**
* @param UpdateHandler $handler
*
* @return EventManager
*/
public static function createEventManager(UpdateHandler $handler)
public static function createEventManager(UpdateHandler $handler): EventManager
{
$listener = FlushListener::createWithHandler($handler);
$eventManager = new EventManager();
Expand All @@ -32,7 +27,7 @@ public static function createEventManager(UpdateHandler $handler)
}

/**
* @return bool
* @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
*/
public static function registerAnnotations()
{
Expand Down

0 comments on commit 19abb92

Please sign in to comment.