1 | <?php |
||
20 | class EntitySubscriber implements EventSubscriber |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var TokenStorage |
||
25 | */ |
||
26 | protected $user; |
||
27 | |||
28 | /** |
||
29 | * @var EventDispatcher |
||
30 | */ |
||
31 | protected $eventDispatcher; |
||
32 | |||
33 | public function __construct($user, $eventDispatcher) |
||
38 | |||
39 | public function getSubscribedEvents() |
||
46 | |||
47 | public function prePersist(LifecycleEventArgs $args) |
||
48 | { |
||
49 | $entity = $args->getEntity(); |
||
50 | |||
51 | if (($entity instanceof TimestampInterface )&& empty($entity->getCreatedAt())) { |
||
52 | $entity->setCreatedAt(new DateTime()); |
||
53 | } |
||
54 | if ($entity instanceof AbstractEntity && empty($entity->getUuid())) { |
||
55 | $uuid = Uuid::uuid4(); |
||
56 | $entity->setUuid($uuid); |
||
|
|||
57 | } |
||
58 | if (!$entity instanceof AbstractUser) { |
||
59 | return false; |
||
60 | } |
||
61 | if (empty($entity->getUser()) && $user = $this->getUser()) { |
||
62 | $entity->setUser($user); |
||
63 | } |
||
64 | |||
65 | return true; |
||
66 | } |
||
67 | |||
68 | protected function getUser() |
||
76 | |||
77 | public function onFlush(OnFlushEventArgs $event) |
||
102 | } |
||
103 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: