{"id":20719712,"url":"https://github.com/slince/event-dispatcher","last_synced_at":"2025-10-07T15:40:16.326Z","repository":{"id":20660452,"uuid":"23942747","full_name":"slince/event-dispatcher","owner":"slince","description":":fire: A flexible event dispatching library for PHP","archived":false,"fork":false,"pushed_at":"2018-06-24T13:33:56.000Z","size":54,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-17T04:55:09.700Z","etag":null,"topics":["event","event-dispatcher","event-listener","events","listener","observer-pattern","subscriber"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slince.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-12T01:47:37.000Z","updated_at":"2021-01-05T18:31:23.000Z","dependencies_parsed_at":"2022-08-24T04:11:40.229Z","dependency_job_id":null,"html_url":"https://github.com/slince/event-dispatcher","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/slince/event-dispatcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fevent-dispatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fevent-dispatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fevent-dispatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fevent-dispatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slince","download_url":"https://codeload.github.com/slince/event-dispatcher/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slince%2Fevent-dispatcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278801731,"owners_count":26048557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["event","event-dispatcher","event-listener","events","listener","observer-pattern","subscriber"],"created_at":"2024-11-17T03:18:06.209Z","updated_at":"2025-10-07T15:40:16.296Z","avatar_url":"https://github.com/slince.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Event Dispatcher\n\n[![Build Status](https://img.shields.io/travis/slince/event-dispatcher/master.svg?style=flat-square)](https://travis-ci.org/slince/event-dispatcher)\n[![Coverage Status](https://img.shields.io/codecov/c/github/slince/event-dispatcher.svg?style=flat-square)](https://codecov.io/github/slince/event-dispatcher)\n[![Latest Stable Version](https://img.shields.io/packagist/v/slince/event-dispatcher.svg?style=flat-square\u0026label=stable)](https://packagist.org/packages/slince/event-dispatcher)\n[![Scrutinizer](https://img.shields.io/scrutinizer/g/slince/event-dispatcher.svg?style=flat-square)](https://scrutinizer-ci.com/g/slince/event-dispatcher/?branch=master)\n\n### Installation\n\nInstall via composer.\n\n```bash\n$ composer require slince/event-dispatcher\n```\n\n### Usage\n\n#### Creates a event dispatcher\n\n```php\n$dispatcher = new Slince\\EventDispatcher\\Dispatcher();\n```\n\n#### Adds a listener for the specified event\n\nThere are two types of listeners: `callable` and `Slince\\EventDispatcher\\Listener` \n \n- `Slince\\EventDispatcher\\Listener` \n\n```php\nuse Slince\\EventDispatcher\\ListenerInterface;\n\nclass FooListener implements ListenerInterface\n{\n     public function handle(Event $event)\n     {\n         //do something\n     }\n}\n\n$dispatcher-\u003eaddListener('foo-event-name', new FooListener());\n```\n\n- `callable`\n\n```php\n$dispatcher-\u003eaddListener('foo-event-name', function(Event $event){\n    //do something\n});\n```\n\n#### Add a subscriber\n\n```php\nuse Slince\\EventDispatcher\\SubscriberInterface;\n\nclass FooSubscriber implements SubscriberInterface\n{\n     public static function getSubscribedEvents(Event $event)\n     {\n        return [\n            'foo' =\u003e 'onFoo',\n            'bar' =\u003e 'onBar'\n        ];\n     }\n     \n    public function onFoo(Event $event)\n    {\n      //do something\n    }\n    \n    public function onBar(Event $event)\n    {\n       //do something\n    }\n}\n\n$dispatcher-\u003eaddSubscriber(new FooSubscriber());\n```\n\n#### Dispatches the event to the registered listeners\n\nJust provides the event name.\n\n```php\n$dispatcher-\u003edispatch('foo-event-name');\n```\n\nYou can also dispatch with an event instance.\n\n```php\n$dispatcher-\u003edispatch(new Event('foo-event-name'));\n```\n\n#### Propagation\n\nYou can call `stopPropagation` to stop event propagation on the event instance.\n\n```php\n$dispatcher-\u003eaddListener('foo-event-name', function(Event $event){\n    $event-\u003estopPropagation();\n});\n\n$emitter-\u003eaddListener('foo-event-name', function ($event) {\n    // This will not be triggered\n});\n\n$dispatcher-\u003edispatch('foo-event-name');\n```\n\nChecks whether propagation is stopped\n \n ```php\n $event = new Event('foo-event-name');\n $dispatcher-\u003edispatch($event);\n \n $event-\u003eisPropagationStopped();\n ```\n \n ### License\n \nThe MIT license. See [MIT](https://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslince%2Fevent-dispatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslince%2Fevent-dispatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslince%2Fevent-dispatcher/lists"}