{"id":27158897,"url":"https://github.com/activecollab/eventsdispatcher","last_synced_at":"2025-04-08T22:39:26.704Z","repository":{"id":56940278,"uuid":"87227384","full_name":"activecollab/eventsdispatcher","owner":"activecollab","description":"Simple events dispatcher","archived":false,"fork":false,"pushed_at":"2019-06-23T19:40:09.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T13:03:28.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/activecollab.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":"2017-04-04T19:36:01.000Z","updated_at":"2019-06-23T19:39:52.000Z","dependencies_parsed_at":"2022-08-21T06:20:54.460Z","dependency_job_id":null,"html_url":"https://github.com/activecollab/eventsdispatcher","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Feventsdispatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Feventsdispatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Feventsdispatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Feventsdispatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/activecollab","download_url":"https://codeload.github.com/activecollab/eventsdispatcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247941718,"owners_count":21022035,"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","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":[],"created_at":"2025-04-08T22:39:25.893Z","updated_at":"2025-04-08T22:39:26.688Z","avatar_url":"https://github.com/activecollab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EventsDispatcher\n\n[![Build Status](https://travis-ci.org/activecollab/eventsdispatcher.svg?branch=master)](https://travis-ci.org/activecollab/eventsdispatcher)\n\nThis package offers simple events dispatcher, with listeners. Key concepts:\n\n1. Events are not arbitrary strings, but instances that encapsulate all relevant event data,\n1. When you specify a listener, you specify an event class (or interface) that you want to listen to,\n1. You can listen to entire classes of events, by specifying general enough event class (or interface),\n1. Listeners are callables, and event is always passed to it as the first (and only) argument.\n\nGeneral listener example:\n\n```php\n\u003c?php\n\nnamespace MyApp;\n\nuse ActiveCollab\\EventsDispatcher\\EventsDispatcher;\nuse ActiveCollab\\EventsDispatcher\\Test\\Fixtures\\LicenseRenewedEvent\\LicenseRenewedEventInterface;\n\n$dispatcher = new EventsDispatcher();\n$dispatcher-\u003elisten(LicenseRenewedEventInterface::class, function (LicenseRenewedEventInterface $event) {\n    print \"License {$event-\u003egetLicenseKey()} has been renewed\\n\";\n});\n```\n\nTo specify a global listener, that handles all events, just go highly general with the specification:\n\n```php\n\u003c?php\n\nnamespace MyApp;\n\nuse ActiveCollab\\EventsDispatcher\\EventsDispatcher;\nuse ActiveCollab\\EventsDispatcher\\Events\\EventInterface;\n\n$dispatcher = new EventsDispatcher();\n$dispatcher-\u003elisten(EventInterface::class, function (EventInterface $event) {\n    print \"Event \" . get_class($event) . \" handled\\n\";\n});\n```\n\nSimilar approach can be used to handle a class of events. Instead of using the base `EventInterface`, register listener to a class, or interface that all events of a targeted type extend, or implement.\n\nTo trigger an event, call `trigger()` method with event as the first (and only) argument:\n\n```php\n\u003c?php\n\nnamespace MyApp;\n\nuse ActiveCollab\\EventsDispatcher\\EventsDispatcher;\nuse ActiveCollab\\EventsDispatcher\\Test\\Fixtures\\LicenseRenewedEvent\\LicenseRenewedEvent;\n\n$dispatcher = new EventsDispatcher();\n$dispatcher-\u003etrigger(new LicenseRenewedEvent(\n    '123',\n    '2016-12-31',\n    '2017-12-31',\n    699.0\n));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivecollab%2Feventsdispatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factivecollab%2Feventsdispatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivecollab%2Feventsdispatcher/lists"}