{"id":28351477,"url":"https://github.com/phalcon/incubator-events","last_synced_at":"2025-08-04T06:16:47.064Z","repository":{"id":42198887,"uuid":"265550709","full_name":"phalcon/incubator-events","owner":"phalcon","description":"Extra Phalcon Events Adapters.","archived":false,"fork":false,"pushed_at":"2023-04-19T19:26:56.000Z","size":59,"stargazers_count":4,"open_issues_count":3,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-21T20:35:39.485Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/phalcon.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}},"created_at":"2020-05-20T11:57:28.000Z","updated_at":"2024-11-19T22:55:25.000Z","dependencies_parsed_at":"2024-01-23T21:30:56.020Z","dependency_job_id":"adb97208-5b2f-4fbd-94c8-64e8829d4095","html_url":"https://github.com/phalcon/incubator-events","commit_stats":{"total_commits":8,"total_committers":4,"mean_commits":2.0,"dds":0.625,"last_synced_commit":"e2d36ea42033cbd15d09ce9e9716cd02beb82bf0"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/phalcon/incubator-events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phalcon%2Fincubator-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phalcon%2Fincubator-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phalcon%2Fincubator-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phalcon%2Fincubator-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phalcon","download_url":"https://codeload.github.com/phalcon/incubator-events/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phalcon%2Fincubator-events/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267997141,"owners_count":24178245,"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-07-31T02:00:08.723Z","response_time":66,"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":[],"created_at":"2025-05-27T22:10:53.124Z","updated_at":"2025-08-04T06:16:47.035Z","avatar_url":"https://github.com/phalcon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Phalcon\\Incubator\\Events\nUsage examples of the features is here:\n\n## Manager\n\n### Classic event handling\n\nClassic event handling requires one class with a bunch of methods named equal to event name.\n\nAnd multiple `$eventsManager-\u003eattach()` calls if you use more than one handler for single event:\n```php\nclass DispatchEventsHandler\n{\n    public function beforeCallActionMethod(\n        Phalcon\\Events\\EventInterface $event, \n        Phalcon\\Dispatcher\\DispatcherInterface $dispatcher\n    ): void {\n        //do some stuff\n    }\n\n    public function beforeDoSomeMistakes(\n        Phalcon\\Events\\EventInterface $event, \n        Phalcon\\Dispatcher\\DispatcherInterface $dispatcher\n    ): void {\n        //do some right stuff\n    }\n}\n\nclass DispatchEventsHandlerTwo\n{\n    public function beforeCallActionMethod(\n        Phalcon\\Events\\EventInterface $event, \n        Phalcon\\Dispatcher\\DispatcherInterface $dispatcher\n    ): void {\n        //do another stuff in same event\n    }\n}\n\n$eventsManager = new Phalcon\\Events\\Manager();\n$eventsManager-\u003eattach('dispatch:beforeCallActionMethod',new DispatchEventsHandler(), 100);\n$eventsManager-\u003eattach('dispatch:beforeCallActionMethod',new DispatchEventsHandlerTwo(), 101);\n$eventsManager-\u003eattach('dispatch:beforeDoSomeMistakes',new DispatchEventsHandler());\n//or global way\n$eventsManager-\u003eattach('dispatch',new DispatchEventsHandler(), 100);\n$eventsManager-\u003eattach('dispatch',new DispatchEventsHandlerTwo(), 101);\n```\n\n### Featured event handling\nThis manager version provides a feature of single responsible event handlers via configs, using `__invoke`.\n\nCreate your handler class:\n```php\nclass BeforeCallActionMethod\n{\n    public function __invoke(\n        Phalcon\\Events\\EventInterface $event, \n        Phalcon\\Dispatcher\\DispatcherInterface $dispatcher\n    ): void {\n        //do some stuff\n    }\n}\n```\n\nDefine configuration in config file:\n```php\n$config = new Phalcon\\Config([\n  'handlers' =\u003e [\n      'dispatch:beforeCallActionMethod' =\u003e BeforeCallActionMethod::class,\n  ],\n]);\n```\n\nDefine `Phalcon\\Incubator\\Events\\Manager` in container as eventsManager service using config of handlers:\n```php\n$handlers = $config-\u003eget('handlers')-\u003etoArray();\n\n$eventsManager = new Phalcon\\Incubator\\Events\\Manager();\n$eventsManager-\u003eloadHandlers($handlers);\n```\n\nThere are multiple ways to define configs of handlers:\n\nFlat classname usage, if your handler is invokable:\n```php\n$flat = new Phalcon\\Config([\n    'handlers' =\u003e [\n        'dispatch:beforeCallActionMethod' =\u003e BeforeCallActionMethod::class,\n    ],\n]);\n```\n\nSame, but more informative and with optional priority:\n```php\n$verbose = new Phalcon\\Config([\n    'handlers' =\u003e [\n        'dispatch:beforeCallActionMethod' =\u003e [\n            'class' =\u003e BeforeCallActionMethod::class,\n            'priority' =\u003e 100, //optional\n        ],\n    ],\n]);\n```\n\nUsing callable constructions:\n```php\n$callable = new Phalcon\\Config([\n    'handlers' =\u003e [\n        //you can use any other public method name instead of method, for example run()\n        'dispatch:beforeCallActionMethod' =\u003e [new BeforeCallActionMethod(), 'run'],\n        //or\n        'dispatch:beforeCallActionMethod' =\u003e [BeforeCallActionMethod::class, 'staticRun'],\n    ],\n]);\n```\n\nGrouping more than one handler for one event:\n```php\n$grouped = new Phalcon\\Config([\n    'handlers' =\u003e [\n        'dispatch:beforeCallActionMethod' =\u003e [\n            BeforeCallActionMethod::class,\n            BeforeCallActionMethodAnother::class,\n            BeforeCallActionMethodThird::class,\n        ],\n    ],\n]);\n\n$groupedVerbose = new Phalcon\\Config([\n    'handlers' =\u003e [\n        'dispatch:beforeCallActionMethod' =\u003e [\n            [\n                'class' =\u003e BeforeCallActionMethod::class,\n                'priority' =\u003e 100, //optional\n            ],\n            [\n                'class' =\u003e BeforeCallActionMethodAnother::class,\n                'priority' =\u003e 101, //optional\n            ],\n            [\n                'class' =\u003e BeforeCallActionMethodThird::class,\n                'priority' =\u003e 101, //optional\n            ],\n        ],\n    ],\n]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphalcon%2Fincubator-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphalcon%2Fincubator-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphalcon%2Fincubator-events/lists"}