diff --git a/src/Skobkin/Bundle/PointToolsBundle/Event/UsersRenamedEvent.php b/src/Skobkin/Bundle/PointToolsBundle/Event/UsersRenamedEvent.php new file mode 100644 index 0000000..e42c336 --- /dev/null +++ b/src/Skobkin/Bundle/PointToolsBundle/Event/UsersRenamedEvent.php @@ -0,0 +1,37 @@ +renames = $renames; + } + + /** + * @return UserRenameEvent[] + */ + public function getRenames(): array + { + return $this->renames; + } +} \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersRenameNotifierListener.php b/src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersRenamedNotifierListener.php similarity index 63% rename from src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersRenameNotifierListener.php rename to src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersRenamedNotifierListener.php index 4f178c1..90875b4 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersRenameNotifierListener.php +++ b/src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersRenamedNotifierListener.php @@ -2,11 +2,10 @@ namespace Skobkin\Bundle\PointToolsBundle\EventListener; - +use Skobkin\Bundle\PointToolsBundle\Event\UsersRenamedEvent; use Skobkin\Bundle\PointToolsBundle\Service\Telegram\Notifier; -use Symfony\Component\EventDispatcher\GenericEvent; -class UsersRenameNotifierListener +class UsersRenamedNotifierListener { /** * @var Notifier @@ -24,8 +23,8 @@ class UsersRenameNotifierListener $this->notifier = $notifier; } - public function onAppUsersRenamed(GenericEvent $event) + public function onAppUsersRenamed(UsersRenamedEvent $event) { - $this->notifier->sendUsersRenamedNotification((array) $event->getIterator()); + $this->notifier->sendUsersRenamedNotification($event->getRenames()); } } \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/EventListener/UserRenameSubscriber.php b/src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersUpdatedSubscriber.php similarity index 76% rename from src/Skobkin/Bundle/PointToolsBundle/EventListener/UserRenameSubscriber.php rename to src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersUpdatedSubscriber.php index d3caeb3..85ac976 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/EventListener/UserRenameSubscriber.php +++ b/src/Skobkin/Bundle/PointToolsBundle/EventListener/UsersUpdatedSubscriber.php @@ -10,15 +10,15 @@ use Doctrine\ORM\Event\PostFlushEventArgs; use Doctrine\ORM\Event\PreUpdateEventArgs; use Skobkin\Bundle\PointToolsBundle\Entity\User; use Skobkin\Bundle\PointToolsBundle\Entity\UserRenameEvent; +use Skobkin\Bundle\PointToolsBundle\Event\UsersRenamedEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\GenericEvent; -class UserRenameSubscriber implements EventSubscriber +class UsersUpdatedSubscriber implements EventSubscriber { /** * @var UserRenameEvent[] */ - private $items = []; + private $renames = []; /** * @var EventDispatcherInterface @@ -54,27 +54,27 @@ class UserRenameSubscriber implements EventSubscriber } if ($event->hasChangedField('login')) { - $this->items[] = new UserRenameEvent($entity, $event->getOldValue('login')); + $this->renames[] = new UserRenameEvent($entity, $event->getOldValue('login')); } } public function postFlush(PostFlushEventArgs $event) { - if (0 !== count($this->items)) { + if (0 !== count($this->renames)) { // Creating event for dispatch - $usersRenamedEvent = new GenericEvent(null, $this->items); + $usersRenamedEvent = new UsersRenamedEvent($this->renames); $em = $event->getEntityManager(); - foreach ($this->items as $item) { + foreach ($this->renames as $item) { $em->persist($item); } - $this->items = []; + $this->renames = []; $em->flush(); - $this->eventDispatcher->dispatch('app.users.renamed', $usersRenamedEvent); + $this->eventDispatcher->dispatch(UsersRenamedEvent::NAME, $usersRenamedEvent); } } } \ No newline at end of file diff --git a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml index a7441ec..d72edef 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml +++ b/src/Skobkin/Bundle/PointToolsBundle/Resources/config/services.yml @@ -85,14 +85,14 @@ services: # Event listener - point_tools.event_listener.user_rename_subscriber: - class: Skobkin\Bundle\PointToolsBundle\EventListener\UserRenameSubscriber + point_tools.event_listener.users_updated: + class: Skobkin\Bundle\PointToolsBundle\EventListener\UsersUpdatedSubscriber arguments: [@event_dispatcher] tags: - { name: doctrine.event_subscriber, connection: default } - point_tools.event_listener.users_renamed_notifier_listener: - class: Skobkin\Bundle\PointToolsBundle\EventListener\UsersRenameNotifierListener + point_tools.event_listener.users_renamed_notifier: + class: Skobkin\Bundle\PointToolsBundle\EventListener\UsersRenamedNotifierListener arguments: [@point_tools.telegram.notifier] tags: - { name: kernel.event_listener, event: app.users.renamed }