|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ControleOnline\Listener; |
|
4
|
|
|
|
|
5
|
|
|
use ControleOnline\Service\ExtraDataService; |
|
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Event\PrePersistEventArgs; |
|
|
|
|
|
|
8
|
|
|
use Doctrine\ORM\Event\PreUpdateEventArgs; |
|
|
|
|
|
|
9
|
|
|
use Doctrine\ORM\Event\PostPersistEventArgs; |
|
|
|
|
|
|
10
|
|
|
use Doctrine\ORM\Event\PostUpdateEventArgs; |
|
|
|
|
|
|
11
|
|
|
use Doctrine\ORM\Event\PreRemoveEventArgs; |
|
|
|
|
|
|
12
|
|
|
use Psr\Container\ContainerInterface; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
class DefaultEventListener |
|
16
|
|
|
{ |
|
17
|
|
|
public function __construct( |
|
18
|
|
|
private EntityManagerInterface $manager, |
|
19
|
|
|
private ExtraDataService $extraDataService, |
|
20
|
|
|
private ContainerInterface $container, |
|
21
|
|
|
) {} |
|
22
|
|
|
|
|
23
|
|
|
public function preUpdate(PreUpdateEventArgs $args): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->execute($args->getObject(), 'preUpdate'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function prePersist(PrePersistEventArgs $args): void |
|
29
|
|
|
{ |
|
30
|
|
|
$entity = $args->getObject(); |
|
31
|
|
|
$this->extraDataService->discoveryDevice($entity); |
|
32
|
|
|
$this->extraDataService->discoveryUser($entity); |
|
33
|
|
|
$this->execute($entity, 'prePersist'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function postUpdate(PostUpdateEventArgs $args): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->execute($args->getObject(), 'postUpdate'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function postPersist(PostPersistEventArgs $args): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->execute($args->getObject(), 'postPersist'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function preRemove(PreRemoveEventArgs $args): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->execute($args->getObject(), 'preRemove'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
private function execute($entity, $method) |
|
52
|
|
|
{ |
|
53
|
|
|
$class = get_class($entity); |
|
54
|
|
|
$serviceName = str_replace('Entity', 'Service', $class) . 'Service'; |
|
55
|
|
|
$this->extraDataService->persist($entity); |
|
56
|
|
|
if ($this->container->has($serviceName)) { |
|
57
|
|
|
$service = $this->container->get($serviceName); |
|
58
|
|
|
if (method_exists($service, $method)) { |
|
59
|
|
|
$newEntity = $service->$method($entity); |
|
60
|
|
|
|
|
61
|
|
|
if ('postPersist' === $method && $newEntity) |
|
62
|
|
|
$this->manager->refresh($newEntity); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
return $entity; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths