{"id":22307465,"url":"https://github.com/imroychen/php-event","last_synced_at":"2025-03-26T01:22:22.441Z","repository":{"id":56993560,"uuid":"389829223","full_name":"imroychen/php-event","owner":"imroychen","description":"A simple php event engine to reduce the coupling between project modules.(一个简单php事件引擎，以便解耦项目中的各模块)","archived":false,"fork":false,"pushed_at":"2022-05-30T03:28:23.000Z","size":110,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T22:47:32.838Z","etag":null,"topics":["event","fire-event","php-event"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imroychen.png","metadata":{"files":{"readme":"README-EN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-27T02:50:26.000Z","updated_at":"2023-11-11T05:33:47.000Z","dependencies_parsed_at":"2022-08-21T13:20:41.502Z","dependency_job_id":null,"html_url":"https://github.com/imroychen/php-event","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imroychen","download_url":"https://codeload.github.com/imroychen/php-event/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245569065,"owners_count":20636880,"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","fire-event","php-event"],"created_at":"2024-12-03T20:09:54.763Z","updated_at":"2025-03-26T01:22:22.419Z","avatar_url":"https://github.com/imroychen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Docs: [中文简体](./README.md), [English](./README-EN.md)\r\n# Description\r\nA simple php event engine to reduce the coupling between project modules.\r\n## How to install and use\r\n\u003ca id=\"lang-en\"\u003e\u003c/a\u003e\r\n## 1.installation\r\n1). Install using composer. \r\n\r\n```shell script\r\ncomposer require iry/php-event\r\ncompoer update\r\n```\r\n\r\n2).Traditional loading: add require_once('php-event PATH/start.php'); to your public file [example](./example/client.php)\r\n\r\n# Add configuration\r\n\r\n```php\r\niry\\e\\App::setCfg('\\\\MyNamespace\\\\event\\\\Setting');\r\n```\r\n\r\n### 3. Create class \\\\MyNamespace\\event\\\\Setting\r\n```\r\nnamespace \\\\MyNamespace\\event;\r\nclass Config implements \\iry\\e\\interfaces\\Setting{\r\n   public function getPoolDriver()\r\n   public function getSubscribers(){}\r\n   public function getEventRules(){}\r\n   public function getTempPath(){}\r\n\r\n}\r\n```\r\nInterface : [./src/Setting.php](./src/interfaces/Setting.php)\u003cbr\u003e\u003cbr\u003e\r\nPlease refer to the interface docking example: [./example/event/Setting.php](./example/event/Setting.php)\u003cbr\u003e\u003cbr\u003e\r\n#### 方法\r\n**public function getPoolDriver()**\r\n\r\n //This package contains the following built-in drivers (DB (Sql DB), Sqlite, Redis, DbForLaravel, DbForTp).\u003cbr\u003e\r\n    Custom drive:  'Class Name(Contains namespace)'\r\n    Built-in drive: '@DbForLaravel?table=event_store'\r\n    \u003cbr\u003e For more built-in drivers, please refer to[./src/drivers/RADME.md](./src/drivers/RADME.md)\r\n\r\n**public function getSubscribers()**\r\n\r\nreturn array（recommended）|string\u003cbr\u003e\r\n  array: class list []: ['class1','class2'];\u003cbr\u003e\r\n  string: Example: \u003cu\u003e_files:Subscriber Path/*.php_\u003c/u\u003e (Automatically analyze the full name of the class from the code of these files)\r\n\r\n**public function getEventRules()**\r\n\r\nreturn ：\"string\", Class Name，Example[./example/event/Event.php](./example/event/Event.php)\u003cbr\u003e\u003cbr\u003e\r\n\r\nreturn：\"string\"\r\n\r\n**public function getTempPath()**\r\n\r\nreturn：\"string\",Return a directory path, do not add \"/\" at the end。 Example：_/tmp_\u003cbr\u003e\u003cbr\u003e\r\n\r\n### 3.Srart Service (Service 在命令行下执行)\r\n参考 [example/service.php](example/service.php)\r\n```php\r\n//启动守护进程\r\n//$argv为所有的命令行参数 $_SERVER['argv']|| 如果是入口文件 也可使用$argv接收\r\niry\\e\\Service::start($argv);\r\n```\r\n\r\n### 4. Fire EVENT （Client）\r\n\r\n#### Quick way\r\n```php\r\nuse iry\\e\\Event;\r\n\r\nEvent::fire('Event Name',['argument 1','argument 2...'],'Delay broadcast for n seconds','Dependent event ID');\r\nEvent::fire('complete',[]);\r\nEvent::fire('complete',[],10);//Delay usage，Broadcast event message after 10 seconds\r\nEvent::fire('complete',[],0,5000);//5000 The current event will not be broadcast until the broadcast is confirmed\r\n```\r\n#### Use event objects\r\nAn event dependency chain will be automatically formed to ensure the sequence of events being broadcast successfully\r\n```php\r\nuse iry\\e\\Fire; \r\n\r\n$fire = new Fire();\r\n$fire -\u003estart('beforeRequest',['arguments1','...']);\r\n    //... Your code\r\n$fire -\u003ethen('afterRequest',['arguments1','...']);\r\n    //... Your code\r\n$fire -\u003ethen('complete',['arguments1','...']);\r\n//The broadcast sequence is:\r\n// beforeRequest \u003e afterRequest \u003e complete\r\n\r\n$fire-\u003egetLastEventId();//Get the ID of the last event\r\n```\r\nThis usage automatically forms an event dependency chain to ensure the sequence in which events are successfully broadcast.\r\n**_\"Complete\"_** depends on _**\"afterRequest\"**_ and _\"complete\"_ will automatically wait for _\"afterRequest\"_ to be confirmed by all listeners before it is actually broadcast.\r\n\r\n**_\"AfterRequest\"_** relies on **_\"beforeRequest\"_**, **_\"afterRequest\"_** will automatically wait for **_\"beforeRequest\"_** to be confirmed by all listeners before it is actually broadcast.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimroychen%2Fphp-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimroychen%2Fphp-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimroychen%2Fphp-event/lists"}