Skip to content

Commit 19abb92

Browse files
committed
Remove deprecated class usage introduced with doctrine/orm ^2.14
1 parent 0e8890b commit 19abb92

File tree

8 files changed

+17
-32
lines changed

8 files changed

+17
-32
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.idea/*
1+
.idea/*
2+
vendor/
3+
composer.lock

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You can use this library to track changes to Doctrine Entities. Use annotations
1818
* @Column(type="string")
1919
* @WatchedField // <-- Watcher now tracks changes related to this field
2020
*/
21-
protected $emailAddress;
21+
protected string $emailAddress;
2222
```
2323

2424
***
@@ -96,7 +96,7 @@ Bugs and feature request are tracked on GitHub.
9696

9797
## ToDo
9898
* Use interfaces for everything
99-
* Easy Symfony4 integration
99+
* Easy Symfony integration
100100
* Write tests
101101
* Optimize performance (group changes?)
102102

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^5.5 || ^7.0",
20-
"doctrine/orm": "2.*",
19+
"php": "^7.3 || ^8.0",
20+
"doctrine/orm": "2.14.*",
2121
"doctrine/annotations": "1.*",
2222
"psr/log": "^1.0",
2323
"ext-mbstring": "*"

src/Watcher/Annotations/WatchedField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Watcher\Annotations;
44

55
use Doctrine\ORM\Mapping\Annotation;
6+
use Doctrine\ORM\Mapping\MappingAttribute;
67
use Watcher\ValueFormatter;
78

89
/**
910
* @Annotation
1011
* @Target("PROPERTY")
1112
*/
12-
final class WatchedField implements Annotation
13+
final class WatchedField implements MappingAttribute
1314
{
1415

1516
/**

src/Watcher/EventListener/FlushListener.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function getUpdateHandler()
125125
* @return WatchedField|null
126126
* @throws \ReflectionException
127127
*/
128-
private function getWatchedFieldAnnotation(Reader $reader, WatchedEntity $entity, $field)
128+
private function getWatchedFieldAnnotation(Reader $reader, WatchedEntity $entity, string $field): ?WatchedField
129129
{
130130

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

162-
$em = $args->getEntityManager();
162+
$em = $args->getObjectManager();
163163
$uow = $em->getUnitOfWork();
164164

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

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

212210
if ($collectionUpdate->getOwner() === $entity) {
213211
// This entity has an association mapping which contains updates.
@@ -231,6 +229,5 @@ public function onFlush(OnFlushEventArgs $args)
231229
}
232230
}
233231
}
234-
235232
}
236233
}

src/Watcher/EventListener/LoadListener.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Watcher\EventListener;
44

5-
use Doctrine\ORM\Event\LifecycleEventArgs;
5+
use Doctrine\Persistence\Event\LifecycleEventArgs;
66
use Watcher\Entity\LogAccessor;
77
use Watcher\Repository\EntityLogRepository;
88

@@ -17,12 +17,7 @@ class LoadListener
1717
/** @var string */
1818
private $entityLogClassname;
1919

20-
/**
21-
* LoadListener constructor.
22-
*
23-
* @param string $entityLogClassname
24-
*/
25-
public function __construct($entityLogClassname)
20+
public function __construct(string $entityLogClassname)
2621
{
2722
if(!class_exists($entityLogClassname)) {
2823
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)
3631
*/
3732
public function postLoad(LifecycleEventArgs $args)
3833
{
39-
$entity = $args->getEntity();
34+
$entity = $args->getObject();
4035

4136
if ($entity instanceof LogAccessor) {
4237

4338
/** @var EntityLogRepository $logRepo */
44-
$logRepo = $args->getEntityManager()->getRepository($this->entityLogClassname);
39+
$logRepo = $args->getObjectManager()->getRepository($this->entityLogClassname);
4540
$entity->setLogs($logRepo->getLogsFromEntity($entity));
4641
}
4742

src/Watcher/UpdateHandler/LogHandler.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ class LogHandler implements UpdateHandler
2121
private $logLevel;
2222

2323

24-
/**
25-
* LogHandler constructor.
26-
*
27-
* @param LoggerInterface $logger
28-
*/
2924
public function __construct(LoggerInterface $logger)
3025
{
3126
$this->logger = $logger;

src/Watcher/Watcher.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
class Watcher
1717
{
1818

19-
/**
20-
* @param UpdateHandler $handler
21-
*
22-
* @return EventManager
23-
*/
24-
public static function createEventManager(UpdateHandler $handler)
19+
public static function createEventManager(UpdateHandler $handler): EventManager
2520
{
2621
$listener = FlushListener::createWithHandler($handler);
2722
$eventManager = new EventManager();
@@ -32,7 +27,7 @@ public static function createEventManager(UpdateHandler $handler)
3227
}
3328

3429
/**
35-
* @return bool
30+
* @deprecated This method is deprecated and will be removed in doctrine/annotations 2.0. Annotations will be autoloaded in 2.0.
3631
*/
3732
public static function registerAnnotations()
3833
{

0 commit comments

Comments
 (0)