{"id":36373745,"url":"https://github.com/maksimepikhin/php-event-dispatcher","last_synced_at":"2026-01-11T14:03:48.212Z","repository":{"id":62527140,"uuid":"461889535","full_name":"maksimepikhin/php-event-dispatcher","owner":"maksimepikhin","description":"Компонент для работы с событиями и слушателями","archived":false,"fork":false,"pushed_at":"2022-02-22T08:08:54.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"stable","last_synced_at":"2025-07-24T09:26:13.505Z","etag":null,"topics":["dispatcher","event","listener-pattern","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maksimepikhin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-21T14:09:53.000Z","updated_at":"2022-02-22T08:07:53.000Z","dependencies_parsed_at":"2022-11-02T14:02:57.936Z","dependency_job_id":null,"html_url":"https://github.com/maksimepikhin/php-event-dispatcher","commit_stats":null,"previous_names":["maksimepikhin/php-event-dispatcher"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/maksimepikhin/php-event-dispatcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksimepikhin%2Fphp-event-dispatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksimepikhin%2Fphp-event-dispatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksimepikhin%2Fphp-event-dispatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksimepikhin%2Fphp-event-dispatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maksimepikhin","download_url":"https://codeload.github.com/maksimepikhin/php-event-dispatcher/tar.gz/refs/heads/stable","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maksimepikhin%2Fphp-event-dispatcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28306985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T11:18:18.743Z","status":"ssl_error","status_checked_at":"2026-01-11T11:07:56.842Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dispatcher","event","listener-pattern","php"],"created_at":"2026-01-11T14:03:48.152Z","updated_at":"2026-01-11T14:03:48.205Z","avatar_url":"https://github.com/maksimepikhin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# php-event-dispatcher\n\n![release](https://img.shields.io/github/v/release/mepihindeveloper/php-event-dispatcher?label=version)\n[![Packagist Version](https://img.shields.io/packagist/v/mepihindeveloper/php-event-dispatcher)](https://packagist.org/packages/mepihindeveloper/php-event-dispatcher)\n[![PHP Version Require](http://poser.pugx.org/mepihindeveloper/php-event-dispatcher/require/php)](https://packagist.org/packages/mepihindeveloper/php-event-dispatcher)\n![license](https://img.shields.io/github/license/mepihindeveloper/php-event-dispatcher)\n\n![build](https://github.com/mepihindeveloper/php-event-dispatcher/actions/workflows/php.yml/badge.svg?branch=stable)\n[![codecov](https://codecov.io/gh/mepihindeveloper/php-event-dispatcher/branch/stable/graph/badge.svg?token=36PP7VKHKG)](https://codecov.io/gh/mepihindeveloper/php-event-dispatcher)\n\nКомпонент для работы с событиями и слушателями\n\n# Структура\n\n```\nsrc/\n--- exceptions/\n------ EventNotFoundException.php\n------ ListenerNotFoundException\n--- interfaces/\n------ ListenerInterface.php\n--- Event.php\n--- EventDispatcher.php\n--- ListenerProvider.php\n```\n\nВ директории `interfaces` хранятся необходимые интерфейсы, которые необходимо имплементировать в при реализации \nсобственного класса `Listener`. Класс `Listener` выступает в качестве слушателя события и должен реализовать метод\n`process`. В директории `exceptions` хранятся необходимые исключения. Исключение `EventNotFoundException` необходимо\nдля идентификации ошибки поиска события (когда событие не было найдено), аналогично и для `ListenerNotFoundException`.\n\nКласс `Event` реализует само событие. Собственные события должны наследоваться от класса `Event`.\n\nКласс `EventDispatcher` реализует диспетчер событий, который работает через `ListenerProvider`, выступая посредником.\n\nКласс `ListenerProvider` реализует поставщика слушателей, где происходят все операции со слушателями и событиями.\n\nПримерная реализация событий и слушателей:\n\n```php\n\u003c?php\n\ndeclare(strict_types = 1);\n\nuse mepihindeveloper\\components\\Event;\nuse mepihindeveloper\\components\\EventDispatcher;\nuse mepihindeveloper\\components\\interfaces\\ListenerInterface;\nuse mepihindeveloper\\components\\ListenerProvider;\nuse Psr\\EventDispatcher\\StoppableEventInterface;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\nclass Event1 extends Event { }\n\nclass Event2 extends Event { }\n\nclass Event1Listener1 implements ListenerInterface {\n\tpublic function process(StoppableEventInterface $event) {\n\t\techo \"Я \" . get_class($this) . \" слушаю событие \" . get_class($event) . PHP_EOL;\n\t}\n}\n\nclass Event2Listener1 implements ListenerInterface {\n\tpublic function process(StoppableEventInterface $event) {\n\t\techo \"Я \" . get_class($this) . \" слушаю событие \" . get_class($event) . PHP_EOL;\n\t}\n}\n\nclass Event2Listener2 implements ListenerInterface {\n\tpublic function process(StoppableEventInterface $event) {\n\t\techo \"Я \" . get_class($this) . \" слушаю событие \" . get_class($event) . PHP_EOL;\n\t}\n}\n\nclass AllEventsListener implements ListenerInterface {\n\tpublic function process(StoppableEventInterface $event) {\n\t\techo \"Я \" . get_class($this) . \" слушаю событие \" . get_class($event) . PHP_EOL;\n\t}\n}\n\n$event1 = new Event1;\n$event2 = new Event2;\n$event1Listener1 = new Event1Listener1;\n$event2Listener1 = new Event2Listener1;\n$event2Listener2 = new Event2Listener2;\n$allEventsListener = new AllEventsListener;\n\n$listenerProvider = new ListenerProvider;\n$listenerProvider\n\t-\u003eaddListenerForEventType($event1Listener1, Event1::class)\n\t-\u003eaddListenerForEventType($event2Listener1, Event2::class)\n\t-\u003eaddListenerForEventType($event2Listener2, Event2::class)\n\t-\u003eaddListenerForEventType($allEventsListener);\n\n$dispatcher = new EventDispatcher($listenerProvider);\n$dispatcher-\u003edispatch($event1);\n$dispatcher-\u003edispatch($event2);\n```\n\n\n# Доступные методы\n\n## Event\n\n| Метод                | Аргументы | Возвращаемые данные | Исключения | Описание                                        |\n|----------------------|-----------|---------------------|------------|-------------------------------------------------|\n| stopPropagation      |           | void                |            | Останавливает работу (распространение) события  |\n| isPropagationStopped |           | bool                |            | См. Psr\\EventDispatcher\\StoppableEventInterface |\n\n## EventDispatcher\n\n| Метод                                                    | Аргументы                    | Возвращаемые данные       | Исключения             | Описание                               |\n|----------------------------------------------------------|------------------------------|---------------------------|------------------------|----------------------------------------|\n| __construct(ListenerProviderInterface  $listenerProvider | Провайдер слушателей событий | void                      |                        |                                        |\n| dispatch(object $event)                                  | Объект события               | bool                      | EventNotFoundException | Отправляет событие слушателям          |\n| getListenerProvider                                      |                              | ListenerProviderInterface |                        | Получает провайдера слушателей событий |\n\n## ListenerProvider\n\n| Метод                                                                                                  | Аргументы                                         | Возвращаемые данные | Исключения                                        | Описание                                          |\n|--------------------------------------------------------------------------------------------------------|---------------------------------------------------|---------------------|---------------------------------------------------|---------------------------------------------------|\n| addListenerForEventType(ListenerInterface $listener, string $eventType = self::DEFAULT_EVENT_TYPE)     | $listener -   Слушатель; $eventType - Тип события | ListenerProvider    |                                                   | Добавляет слушателя                               |\n| removeListenerFromEventType(ListenerInterface $listener, string $eventType = self::DEFAULT_EVENT_TYPE) | $listener -   Слушатель; $eventType - Тип события | ListenerProvider    | EventNotFoundException; ListenerNotFoundException | Удаляет слушателя события                         |\n| hasListenerInEventType(ListenerInterface $listener, string $eventType = self::DEFAULT_EVENT_TYPE)      | $listener -   Слушатель; $eventType - Тип события | bool                | EventNotFoundException                            | Проверяет наличие слушателя в событии             |\n| hasEventType(string $eventType = self::DEFAULT_EVENT_TYPE)                                             | Тип события                                       | bool                |                                                   | Проверяет наличие типа события                    |\n| removeListenersForEventType(string $eventType = self::DEFAULT_EVENT_TYPE)                              | Тип события                                       | ListenerProvider    | EventNotFoundException                            | Удаляет слушателей события                        |\n| removeListeners                                                                                        |                                                   | ListenerProvider    |                                                   | Удаляет всех слушателей всех событий              |\n| getListenersForEvent(object $event)                                                                    | См. Psr\\EventDispatcher\\ListenerProviderInterface | iterable            | EventNotFoundException                            | См. Psr\\EventDispatcher\\ListenerProviderInterface |\n| getListenersForEventType(string $eventType)                                                            | Тип события                                       | array               | EventNotFoundException                            | Получает слушателей события                       |\n| getListeners                                                                                           |                                                   | array               |                                                   | Получает всех слушателей всех событий             |\n\n# Контакты\n\nВы можете связаться со мной в социальной сети ВКонтакте: [ВКонтакте: Максим Епихин](https://vk.com/maximepihin)\n\nЕсли удобно писать на почту, то можете воспользоваться этим адресом: mepihindeveloper@gmail.com\n\nМой канал на YouTube, который посвящен разработке веб и игровых\nпроектов: [YouTube: Максим Епихин](https://www.youtube.com/channel/UCKusRcoHUy6T4sei-rVzCqQ)\n\nПоддержать меня можно переводом на Яндекс.Деньги: [Денежный перевод](https://yoomoney.ru/to/410012382226565)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksimepikhin%2Fphp-event-dispatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaksimepikhin%2Fphp-event-dispatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaksimepikhin%2Fphp-event-dispatcher/lists"}