{"id":19764357,"url":"https://github.com/brick/event","last_synced_at":"2025-04-30T14:32:55.877Z","repository":{"id":20381685,"uuid":"23657297","full_name":"brick/event","owner":"brick","description":"An event dispatching library for PHP","archived":false,"fork":false,"pushed_at":"2024-05-02T23:16:53.000Z","size":38,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-09-21T09:52:46.494Z","etag":null,"topics":["event-dispatcher","events","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/brick.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-04T09:59:23.000Z","updated_at":"2024-07-16T14:04:31.000Z","dependencies_parsed_at":"2024-06-19T05:40:50.044Z","dependency_job_id":null,"html_url":"https://github.com/brick/event","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brick","download_url":"https://codeload.github.com/brick/event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224214016,"owners_count":17274524,"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":["event-dispatcher","events","php"],"created_at":"2024-11-12T04:13:37.066Z","updated_at":"2024-11-12T04:13:37.652Z","avatar_url":"https://github.com/brick.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Brick\\Event\n===========\n\n\u003cimg src=\"https://raw.githubusercontent.com/brick/brick/master/logo.png\" alt=\"\" align=\"left\" height=\"64\"\u003e\n\nA simple event dispatching mechanism.\n\n[![Build Status](https://github.com/brick/event/workflows/CI/badge.svg)](https://github.com/brick/event/actions)\n[![Coverage Status](https://coveralls.io/repos/github/brick/event/badge.svg?branch=master)](https://coveralls.io/github/brick/event?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/brick/event/v/stable)](https://packagist.org/packages/brick/event)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)\n\nIntroduction\n------------\n\nThis library helps to write extensible software by plugging in external listeners to events dispatched by an application.\n\nInstallation\n------------\n\nThis library is installable via [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require brick/event\n```\n\nRequirements\n------------\n\nThis library requires PHP 7.1 or later.\n\nOverview\n--------\n\nThis package provides the `EventDispatcher`.\nThe dispatcher dispatches *events*: an event is a unique `string` along with optional parameters.\nThe events are intercepted by *listeners*: any `callable` can be an event listener.\n\n### Basic usage\n\nLet's instantiate a dispatcher:\n\n    use Brick\\Event\\EventDispatcher;\n    \n    $dispatcher = new EventDispatcher();\n\nAnd add a few listeners:\n\n    $dispatcher-\u003eaddListener('startup', function() {\n        echo 'Caught startup event';\n    });\n    \n    $dispatcher-\u003eaddListener('shutdown', function() {\n        echo 'Caught shutdown event';\n    });\n\nNow, let's dispatch some events:\n\n    $dispatcher-\u003edispatch('startup'); // will display \"Caught startup event\"\n    $dispatcher-\u003edispatch('shutdown'); // will display \"Caught shutdown event\"\n\nAny additional parameters you pass to `dispatch()` are forwarded to the listeners:\n\n    $dispatcher-\u003eaddListener('test', function($a, $b) {\n        echo \"Caught $a and $b\";\n    });\n\n    $dispatcher-\u003edispatch('test', 'Hello', 'World'); // will display \"Caught Hello and World\"\n\n### Setting priorities\n\nBy default, the listeners are called in the order they have been registered. It is possible to bypass this\nnatural order by passing a priority to `addListener()`:\n\n    $dispatcher-\u003eaddListener('startup', function() { ... }, 10);\n\nThe default priority is `0`. The listeners with the highest priority will be called first in the chain.\nTwo listeners with the same priority will be called in the order they have been registered.\n\n### Stopping event propagation\n\nAny listener can decide that the event should not be propagated to further listeners in the chain, by returning `false`:\n\n    $dispatcher-\u003eaddListener('startup', function() {\n        // ...\n\n        return false;\n    });\n\nThe dispatcher will then break the chain and no further listeners will be called for this event.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrick%2Fevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrick%2Fevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrick%2Fevent/lists"}