{"id":20903531,"url":"https://github.com/phly/phly-event-emitter","last_synced_at":"2025-05-13T04:33:20.084Z","repository":{"id":57039002,"uuid":"135306770","full_name":"phly/phly-event-emitter","owner":"phly","description":"EXPERIMENTAL package for PSR-14 (EventDispatcher)","archived":false,"fork":false,"pushed_at":"2018-11-15T21:52:28.000Z","size":74,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T18:12:00.664Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-29T14:16:36.000Z","updated_at":"2018-12-12T15:20:00.000Z","dependencies_parsed_at":"2022-08-23T23:30:51.921Z","dependency_job_id":null,"html_url":"https://github.com/phly/phly-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/phly%2Fphly-event-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-event-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-event-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phly%2Fphly-event-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phly","download_url":"https://codeload.github.com/phly/phly-event-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253877265,"owners_count":21977632,"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-11-18T13:14:01.113Z","updated_at":"2025-05-13T04:33:18.636Z","avatar_url":"https://github.com/phly.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phly-event-emitter\n\n[![Build Status](https://secure.travis-ci.org/phly/phly-event-emitter.svg?branch=master)](https://secure.travis-ci.org/phly/phly-event-emitter)\n[![Coverage Status](https://coveralls.io/repos/github/phly/phly-event-emitter/badge.svg?branch=master)](https://coveralls.io/github/phly/phly-event-emitter?branch=master)\n\n\u003e ## Experimental!\n\u003e\n\u003e This library is experimental, tracking different iterations and experiments\n\u003e being proposed for PSR-14. It is highly unstable in terms of API; use at your\n\u003e own risk.\n\nThis library provides an implementation of the following proposed PSR-14 interfaces:\n\n- `ListenerProvider` implements `ListenerProviderInterface`, and allows you to\n  attach listeners to any message type. It then acts as a generator, looping\n  through each listener and testing if it handles the message type.\n\n- `PrioritizedListenerProvider` also implements `ListenerProviderInterface`,\n  and allows you to attach listeners to any message type, with an integer\n  _priority_. When listeners are retrieved, it loops through all attached\n  listeners, and injects those capable of listening to the emitted message to a\n  priority queue, which it then returns.\n\n- `MessageNotifier` implements `MessageNotifierInterface`, and accepts a\n  `ListenerProviderInterface` to its constructor. It then loops through\n  and notifies listeners returned for the message. If any listeners throw\n  exceptions, it catches them, and, when all listeners have been notified,\n  throws a `Phly\\EventEmitter\\Exception\\ExceptionAggregate` that aggregates all\n  of them; call the `getListenerExceptions()` method of that class to iterate\n  through them.\n\n- `TaskProcessor` implements `TaskProcessorInterface`, and accepts a\n  `ListenerProviderInterface` to its constructor. It then loops through\n  and processes listeners returned for the task, halting early if the\n  task is stoppable and indicates propagation has been stopped. Exceptions\n  thrown by listeners are not caught.\n\nIt DOES NOT provide implementations for the following interfaces:\n\n- `EventInterface` (consumers will create these)\n- `MessageInterface` (consumers will create these)\n- `TaskInterface` (consumers will create these)\n- `StoppableTaskInterface` (consumers will create these)\n\n## Installation\n\nYou will first need to add a repository entry to your `composer.json`:\n\n```json\n\"repositories\": [\n    {\n        \"type\": \"vcs\",\n        \"url\": \"https://github.com/phly/phly-event-emitter.git\"\n    }\n],\n```\n\nThen, run the following to install this library:\n\n```bash\n$ composer require phly/phly-event-emitter\n```\n\n## Documentation\n\n### Basic usage\n\nThe following demonstrates using the `ListenerProvider` to attach a listener.\nThe provider is then used to seed either a `MessageNotifier` or `TaskProcessor`.\n\n```php\nuse Phly\\EventEmitter\\MessageNotifier;\nuse Phly\\EventEmitter\\ListenerProvider;\n\n$listeners = new ListenerProvider();\n$listeners-\u003eon(BootstrapEvent::class, function ($e) {\n    // do something with the bootstrap event\n});\n\n$notifier = new MessageNotifier($listeners);\n$notifier-\u003enotify(new BootstrapEvent($params));\n```\n\n### Prioritized listeners\n\nThe following example uses a `PrioritizedListenerProvider` to provide three\ndifferent listeners, each with a different priority. Priorities are integers;\nhigher priorities execute first, while lower priorities (including _negative_\npriorities) execute last.\n\n```php\nuse Phly\\EventEmitter\\TaskProcessor;\nuse Phly\\EventEmitter\\PrioritizedListenerProvider;\n\n$listeners = new PrioritizedListenerProvider();\n$listeners-\u003eon(BootstrapTask::class, function ($e) {\n    echo 1, PHP_EOL;\n}, -100);\n$listeners-\u003eon(BootstrapTask::class, function ($e) {\n    echo 2, PHP_EOL;\n}, 100);\n$listeners-\u003eon(BootstrapTask::class, function ($e) {\n    echo 3, PHP_EOL;\n}, 1);\n\n$processor = new TaskProcessor($listeners);\n$processor-\u003eprocess(new BootstrapTask($params));\n```\n\nIn the above, the output will become:\n\n```text\n2\n3\n1\n```\n\n## Support\n\n* [Issues](https://github.com/phly/phly-event-emitter/issues/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-event-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphly%2Fphly-event-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphly%2Fphly-event-emitter/lists"}