{"id":13669375,"url":"https://github.com/lastguest/ev","last_synced_at":"2025-04-27T02:31:12.310Z","repository":{"id":22052416,"uuid":"25381162","full_name":"lastguest/ev","owner":"lastguest","description":"A tweet-sized PHP Event emitter","archived":false,"fork":false,"pushed_at":"2015-02-11T21:41:37.000Z","size":145,"stargazers_count":42,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-18T09:47:20.138Z","etag":null,"topics":["event-emitter","lightweight","microframework","php"],"latest_commit_sha":null,"homepage":null,"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/lastguest.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}},"created_at":"2014-10-17T23:28:25.000Z","updated_at":"2023-06-01T15:35:35.000Z","dependencies_parsed_at":"2022-08-18T23:40:05.630Z","dependency_job_id":null,"html_url":"https://github.com/lastguest/ev","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/lastguest%2Fev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lastguest%2Fev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lastguest%2Fev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lastguest%2Fev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lastguest","download_url":"https://codeload.github.com/lastguest/ev/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251080020,"owners_count":21533039,"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-emitter","lightweight","microframework","php"],"created_at":"2024-08-02T08:01:11.372Z","updated_at":"2025-04-27T02:31:12.068Z","avatar_url":"https://github.com/lastguest.png","language":"PHP","readme":"# ∑\n\nA tweet-sized PHP Event emitter in only 103 bytes.\n\n[![Build Status](https://scrutinizer-ci.com/g/lastguest/ev/badges/build.png?b=master)](https://scrutinizer-ci.com/g/lastguest/ev/build-status/master) [![Latest Stable Version](https://poser.pugx.org/lastguest/ev/v/stable.svg)](https://packagist.org/packages/lastguest/ev) [![Total Downloads](https://poser.pugx.org/lastguest/ev/downloads.svg)](https://packagist.org/packages/lastguest/ev) [![Latest Unstable Version](https://poser.pugx.org/lastguest/ev/v/unstable.svg)](https://packagist.org/packages/lastguest/ev) [![License](https://poser.pugx.org/lastguest/ev/license.svg)](https://packagist.org/packages/lastguest/ev)\n\n```php\nfunction ∑($n,$c=0){static$r;is_callable($c)?$r[$n][]=$c:@array_walk($r[$n],'call_user_func',$c?:[]);}\n```\n\n**Warning: This is a pure proof of concept of a tweet sized event emitter**\n\n**DO NOT USE IT IN PRODUCTION!**\n\n\n### How to use\n\n**Bind handlers to event:** \n\n```php\n// Bind callback to event \"init\"\n∑('init', function(){\n    echo \"Init event triggered!\\n\";\n});\n\n// Bind another callback to event \"init\"\n∑('init', function(){\n    echo \"Second handler for init triggered!\\n\";\n});\n\n// Bind callback to event \"debug.event\" and listen to passed parameters\n∑('debug.event', function($idx,$params){\n    echo \"Called debug.event[$idx] with parameters : \",print_r($params,true),\"\\n\";\n});\n```\n\n**Trigger Events:**\n\t\nCalling an event with no parameters triggers all binded event handlers.\n\t\n```php\n// Trigger `init`\n∑(\"init\");\n```\n\nOutput:\n\n```html\nInit event triggered!\nSecond handler for init triggered!\n```\n\nYou can pass parameters to all handlers as an array :\n\n```php\n// Trigger `debug.event` passing parameters\n∑('debug.event',[1,2,'Hello, Friend.']);\n```\n\nOutput:\n\n```html\nCalled debug.event[0] with parameters : Array\n(\n    [0] =\u003e 1\n    [1] =\u003e 2\n    [2] =\u003e Hello, Friend.\n)\n```\n\n## Commented source\n\n```php\nfunction ∑ ($event_name, $callback=null){\n    // The event handlers repository.\n    static $event_handlers;\n \n    if (is_callable($callback)) {\n\n        // We are binding a callback to an event, add $callback to the\n        // events handler repository.\n        $event_handlers[$event_name][] = $callback;\n\n    } else {\n\n        // When $callback is not a callable, then we are triggering the event.\n        // In this case, $callback will be our array of parameters to pass to event handlers \n        $params = $callback ? $callback : [];\n\n        // Walk all handlers binded to event $event_name and invoke them with the\n        // ($event_index, $params) parameters.\n        array_walk($event_handlers[$event_name],'call_user_func',$params);\n    }\n} \n```\n\n\n## License (MIT)\n\nCopyright (c) 2014 Stefano Azzolini\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/lastguest/ev/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flastguest%2Fev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flastguest%2Fev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flastguest%2Fev/lists"}