diff --git a/.gitignore b/.gitignore index bc8a670..d420f37 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.idea/* \ No newline at end of file +.idea/* +vendor/ +composer.lock \ No newline at end of file diff --git a/README.md b/README.md index ec399b8..3e2d5bd 100644 --- a/README.md +++ b/README.md @@ -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; ``` *** @@ -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?) diff --git a/composer.json b/composer.json index 1d92efe..70afaf9 100644 --- a/composer.json +++ b/composer.json @@ -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": "*" diff --git a/src/Watcher/Annotations/WatchedField.php b/src/Watcher/Annotations/WatchedField.php index 843bd2a..e423aa8 100644 --- a/src/Watcher/Annotations/WatchedField.php +++ b/src/Watcher/Annotations/WatchedField.php @@ -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 { /** diff --git a/src/Watcher/EventListener/FlushListener.php b/src/Watcher/EventListener/FlushListener.php index eb81af4..2000629 100644 --- a/src/Watcher/EventListener/FlushListener.php +++ b/src/Watcher/EventListener/FlushListener.php @@ -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, '.'); @@ -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(); @@ -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. @@ -231,6 +229,5 @@ public function onFlush(OnFlushEventArgs $args) } } } - } } \ No newline at end of file diff --git a/src/Watcher/EventListener/LoadListener.php b/src/Watcher/EventListener/LoadListener.php index 200e47a..3d99c65 100644 --- a/src/Watcher/EventListener/LoadListener.php +++ b/src/Watcher/EventListener/LoadListener.php @@ -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; @@ -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)); @@ -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)); } diff --git a/src/Watcher/UpdateHandler/LogHandler.php b/src/Watcher/UpdateHandler/LogHandler.php index 758a337..533415e 100644 --- a/src/Watcher/UpdateHandler/LogHandler.php +++ b/src/Watcher/UpdateHandler/LogHandler.php @@ -21,11 +21,6 @@ class LogHandler implements UpdateHandler private $logLevel; - /** - * LogHandler constructor. - * - * @param LoggerInterface $logger - */ public function __construct(LoggerInterface $logger) { $this->logger = $logger; diff --git a/src/Watcher/Watcher.php b/src/Watcher/Watcher.php index 97c3080..218fc0a 100644 --- a/src/Watcher/Watcher.php +++ b/src/Watcher/Watcher.php @@ -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(); @@ -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() {