SchulIT /
icc
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Doctrine; |
||
| 4 | |||
| 5 | use App\Entity\Message; |
||
| 6 | use App\Event\MessageCreatedEvent; |
||
| 7 | use Doctrine\Common\EventSubscriber; |
||
| 8 | use Doctrine\ORM\Event\LifecycleEventArgs; |
||
| 9 | use Doctrine\ORM\Events; |
||
| 10 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * This listener listens for new messages being created and |
||
| 14 | * dispatches an event into the EventDispatcher |
||
| 15 | */ |
||
| 16 | class MessagePersistSubscriber implements EventSubscriber { |
||
| 17 | |||
| 18 | public function __construct(private EventDispatcherInterface $dispatcher) |
||
| 19 | { |
||
| 20 | } |
||
| 21 | 25 | ||
| 22 | 25 | public function postPersist(LifecycleEventArgs $eventArgs) { |
|
| 23 | 25 | $entity = $eventArgs->getEntity(); |
|
|
0 ignored issues
–
show
|
|||
| 24 | |||
| 25 | 21 | if($entity instanceof Message) { |
|
| 26 | 21 | $this->dispatcher->dispatch(new MessageCreatedEvent($entity)); |
|
| 27 | } |
||
| 28 | 21 | } |
|
| 29 | 1 | ||
| 30 | /** |
||
| 31 | 21 | * @inheritDoc |
|
| 32 | */ |
||
| 33 | public function getSubscribedEvents(): array { |
||
| 34 | return [ |
||
| 35 | Events::postPersist |
||
| 36 | 25 | ]; |
|
| 37 | } |
||
| 38 | } |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.