{"id":22092118,"url":"https://github.com/krakphp/event-emitter","last_synced_at":"2025-03-23T23:44:58.220Z","repository":{"id":57009015,"uuid":"85448710","full_name":"krakphp/event-emitter","owner":"krakphp","description":"Event Emitter","archived":false,"fork":false,"pushed_at":"2017-03-19T04:33:21.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T23:52:37.630Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krakphp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-03-19T03:39:24.000Z","updated_at":"2017-03-19T04:31:46.000Z","dependencies_parsed_at":"2022-08-21T13:10:50.952Z","dependency_job_id":null,"html_url":"https://github.com/krakphp/event-emitter","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/krakphp%2Fevent-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fevent-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fevent-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krakphp%2Fevent-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krakphp","download_url":"https://codeload.github.com/krakphp/event-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245186925,"owners_count":20574554,"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":"2024-12-01T03:08:22.394Z","updated_at":"2025-03-23T23:44:58.182Z","avatar_url":"https://github.com/krakphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Event Emitter\n\nSimple event emitter package with a lot of flexibility. Inspired by the Evenement library, EventEmitter provides a simple interface for adding and emitting events.\n\n## Installation\n\nInstall with composer at `krak/event-emitter`\n\n## Usage\n\n```php\n\u003c?php\n\n$emitter = Krak\\EventEmitter\\emitter(); // creates the default emitter instance\n$emitter-\u003eon('event', function($arg) {\n    echo \"Hello $arg\\n\";\n});\n$emitter-\u003eemit('event', \"World\");\n```\n\nThis is the event emitter interface:\n\n```php\n\u003c?php\n\ninterface EventEmitter {\n    public function on($event, $listener);\n    public function once($event, $listener);\n    public function removeListener($event, $listener);\n    public function removeAllListeners($event = null);\n    public function listeners($event);\n    public function emit($event, ...$arguments);\n}\n```\n\n### Event Listeners\n\nYou can add event listener classes by implementing the `EventListener` interface.\n\n```php\n\u003c?php\n\nuse Krak\\EventEmitter\\EventListener;\n\nclass AcmeListener implements EventListener\n{\n    public function handle($param) {\n\n    }\n}\n```\n\nYou can then add this into the emitter via:\n\n```php\n\u003c?php\n\n$emitter-\u003eon('event', new AcmeListener());\n```\n\n### Custom Invocation\n\nThe default emitter supports custom invocations via the [Krak\\\\Invoke](https://github.com/krakphp/invoke) library. You can easily pass in a custom invoker which provides flexibility with how your listeners will be invoked.\n\n```php\n\u003c?php\n\nuse Krak\\EventEmitter;\n\n// this creates an emitter that will support container services as listeners\n$invoke = new Krak\\Invoke\\ContainerInvoke(EventEmitter\\emitterInvoke(), $container);\n$emitter = Krak\\EventEmitter\\emitter($invoke);\n$emitter-\u003eon('event', 'service_id');\n$emitter-\u003eemit('event', 1);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fevent-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrakphp%2Fevent-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrakphp%2Fevent-emitter/lists"}