{"id":15187738,"url":"https://github.com/superbalist/laravel4-event-pubsub","last_synced_at":"2025-10-02T02:31:37.431Z","repository":{"id":16676183,"uuid":"80420429","full_name":"Superbalist/laravel4-event-pubsub","owner":"Superbalist","description":"An event protocol and implementation over pub/sub for Laravel 4","archived":true,"fork":false,"pushed_at":"2022-07-25T07:50:58.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-01-16T10:02:51.446Z","etag":null,"topics":["event-protocol","laravel","laravel-package","laravel4","laravel4-event-pubsub","laravel4-package","php","php-event-pubsub","php-pubsub","pubsub","superbalist"],"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/Superbalist.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2017-01-30T12:41:27.000Z","updated_at":"2024-07-19T07:48:27.000Z","dependencies_parsed_at":"2022-07-24T23:46:41.762Z","dependency_job_id":null,"html_url":"https://github.com/Superbalist/laravel4-event-pubsub","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/Superbalist%2Flaravel4-event-pubsub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Flaravel4-event-pubsub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Flaravel4-event-pubsub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Superbalist%2Flaravel4-event-pubsub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Superbalist","download_url":"https://codeload.github.com/Superbalist/laravel4-event-pubsub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234929190,"owners_count":18908891,"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-protocol","laravel","laravel-package","laravel4","laravel4-event-pubsub","laravel4-package","php","php-event-pubsub","php-pubsub","pubsub","superbalist"],"created_at":"2024-09-27T18:43:24.038Z","updated_at":"2025-10-02T02:31:37.103Z","avatar_url":"https://github.com/Superbalist.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# laravel4-event-pubsub\n\nAn event protocol and implementation over pub/sub for Laravel 4.\n\n[![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist)\n[![Build Status](https://img.shields.io/travis/Superbalist/laravel4-event-pubsub/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/laravel4-event-pubsub)\n[![StyleCI](https://styleci.io/repos/80420429/shield?branch=master)](https://styleci.io/repos/80420429)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Packagist Version](https://img.shields.io/packagist/v/superbalist/laravel4-event-pubsub.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel4-event-pubsub)\n[![Total Downloads](https://img.shields.io/packagist/dt/superbalist/laravel4-event-pubsub.svg?style=flat-square)](https://packagist.org/packages/superbalist/laravel4-event-pubsub)\n\nThis package is a wrapper bridging [php-event-pubsub](https://github.com/Superbalist/php-event-pubsub) into Laravel.\nIt builds on top of the existing [laravel4-pubsub](https://github.com/Superbalist/laravel4-pubsub) package adding support\nfor publishing and subscribing to events over pub/sub.\n\nIf you aren't familiar with the `laravel4-pubsub` package, it's worth first taking a look at their [documentation](https://github.com/Superbalist/laravel4-pubsub).\n\nFor **Laravel 5** support, use the package https://github.com/Superbalist/laravel-event-pubsub\n\n## Installation\n\n```bash\ncomposer require superbalist/laravel4-event-pubsub\n```\n\nThe package has a default configuration built-in.\n\nTo customize the configuration file, publish the package configuration using Artisan.\n```bash\nphp artisan config:publish superbalist/laravel4-event-pubsub\n```\n\nYou can then edit the generated config at `app/config/packages/superbalist/laravel4-event-pubsub/config.php`.\n\nRegister the service provider in app.php\n```php\n'providers' =\u003e [\n    // ...\n    'Superbalist\\Laravel4EventPubSub\\PubSubEventsServiceProvider',\n]\n```\n\nRegister the facade in app.php\n```php\n'aliases' =\u003e [\n    // ...\n    'PubSubEvents' =\u003e 'Superbalist\\Laravel4EventPubSub\\PubSubEventsFacade',\n]\n```\n\n## Usage\n\n### Simple Events\n\nA `SimpleEvent` is an event which takes a name and optional attributes.\n\n```php\n// the pubsub_events.translator config setting should be set to 'pubsub.events.translators.simple'\n\n// get the event manager\n$manager = app('pubsub.events');\n\n// dispatch an event\n$event = new \\Superbalist\\EventPubSub\\Events\\SimpleEvent(\n    'user.created',\n    [\n        'user' =\u003e [\n            'id' =\u003e 1456,\n            'first_name' =\u003e 'Joe',\n            'last_name' =\u003e 'Soap',\n            'email' =\u003e 'joe.soap@example.org',\n        ],\n    ]\n);\n$manager-\u003edispatch('events', $event);\n\n// dispatch multiple events\n$events = [\n    new \\Superbalist\\EventPubSub\\Events\\SimpleEvent(\n        'user.created',\n        [\n            'user' =\u003e [\n                // ...\n            ],\n        ]\n    ),\n    new \\Superbalist\\EventPubSub\\Events\\SimpleEvent(\n        'user.created',\n        [\n            'user' =\u003e [\n                // ...\n            ],\n        ]\n    ),\n];\n$manager-\u003edispatchBatch('events', $events);\n\n// listen for an event\n$manager-\u003elisten('events', 'user.created', function (\\Superbalist\\EventPubSub\\EventInterface $event) {\n    var_dump($event-\u003egetName());\n    var_dump($event-\u003egetAttribute('user'));\n});\n\n// listen for all events on the channel\n$manager-\u003elisten('events', '*', function (\\Superbalist\\EventPubSub\\EventInterface $event) {\n    var_dump($event-\u003egetName());\n});\n\n// all the aboce commands can also be done using the facade\nPubSubEvents::dispatch('events', $event);\n```\n\n### Topic Events\n\nA `TopicEvent` is an event which takes a topic, name, version and optional attributes.\n\n```php\n// the pubsub_events.translator config setting should be set to 'pubsub.events.translators.topic'\n\n// get the event manager\n$manager = app('pubsub.events');\n\n// dispatch an event\n$event = new \\Superbalist\\EventPubSub\\Events\\TopicEvent(\n    'user',\n    'created',\n    '1.0',\n    [\n        'user' =\u003e [\n            'id' =\u003e 1456,\n            'first_name' =\u003e 'Joe',\n            'last_name' =\u003e 'Soap',\n            'email' =\u003e 'joe.soap@example.org',\n        ],\n    ]\n);\n$manager-\u003edispatch('events', $event);\n\n// listen for an event on a topic\n$manager-\u003elisten('events', 'user/created', function (\\Superbalist\\EventPubSub\\EventInterface $event) {\n    // ...\n});\n\n// listen for an event on a topic matching the given version\n$manager-\u003elisten('events', 'user/created/1.0', function (\\Superbalist\\EventPubSub\\EventInterface $event) {\n    // ...\n});\n\n// listen for all events on a topic\n$manager-\u003elisten('events', 'user/*', function (\\Superbalist\\EventPubSub\\EventInterface $event) {\n    // ...\n});\n\n// listen for all events on the channel\n$manager-\u003elisten('events', '*', function (\\Superbalist\\EventPubSub\\EventInterface $event) {\n    // ...\n});\n```\n\n### Schema Events\n\nA `SchemaEvent` is an extension of the `TopicEvent` and takes a schema and optional attributes.  The topic, name and\nversion are derived from the schema.\n\nThe schema must be in the format `(protocol)://(......)?/events/(topic)/(channel)/(version).json`\n\n```php\n// the pubsub_events.translator config setting should be set to 'pubsub.events.translators.schema'\n// the pubsub_events.validator config setting can be set to 'pubsub.events.validators.json_schema' to take advantage of\n// JSON Schema validation on incoming events\n\n// get the event manager\n$manager = app('pubsub.events');\n\n// dispatch an event\n$event = new \\Superbalist\\EventPubSub\\Events\\SchemaEvent(\n    'http://schemas.my-website.org/events/user/created/1.0.json',\n    [\n        'user' =\u003e [\n            'id' =\u003e 1456,\n            'first_name' =\u003e 'Joe',\n            'last_name' =\u003e 'Soap',\n            'email' =\u003e 'joe.soap@example.org',\n        ],\n    ]\n);\n$manager-\u003edispatch('events', $event);\n\n// the listen expressions are the same as those used for TopicEvents.\n```\n\n## Error Handling\n\nThe library supports error handlers for when event translation fails, listen expression fails and validation fails.\n\nThese are configurable as callables in the translate_fail_handler, listen_expr_fail_handler and validation_fail_handler\nconfig options.\n\nThe config contains default callables which will turn the callbacks into Laravel events.\n\nYou can listen for the following to hook into these:\n```php\n$events = app('events'); // or just use the facade Events\n\n$events-\u003elisten('pubsub.events.translation_failure', function ($message) {\n    // the message failed to translate into an event\n});\n\n$events-\u003elisten('pubsub.events.listen_expr_failure', function (\\Superbalist\\EventPubSub\\EventInterface $event, $expr) {\n    // the event didn't match the listen expression\n    // this isn't really an error, but can be useful for debug\n});\n\n$events-\u003elisten('pubsub.events.validation_failure', function (\\Superbalist\\EventPubSub\\ValidationResult $result) {\n    // the event failed validation\n    var_dump($result-\u003eerrors());\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperbalist%2Flaravel4-event-pubsub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperbalist%2Flaravel4-event-pubsub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperbalist%2Flaravel4-event-pubsub/lists"}