{"id":23434925,"url":"https://github.com/gpslab/middleware","last_synced_at":"2025-04-13T03:20:01.534Z","repository":{"id":62512145,"uuid":"92312680","full_name":"gpslab/middleware","owner":"gpslab","description":"Infrastructure for use middleware in applications","archived":false,"fork":false,"pushed_at":"2017-07-17T12:06:51.000Z","size":72,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T20:21:18.642Z","etag":null,"topics":["cqrs","domain-event","infrastructure","middleware","php","psr-11","psr-3","symfony"],"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/gpslab.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":"2017-05-24T16:19:54.000Z","updated_at":"2021-11-19T10:18:47.000Z","dependencies_parsed_at":"2022-11-02T10:16:47.153Z","dependency_job_id":null,"html_url":"https://github.com/gpslab/middleware","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/gpslab%2Fmiddleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fmiddleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fmiddleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpslab%2Fmiddleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpslab","download_url":"https://codeload.github.com/gpslab/middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248658264,"owners_count":21140913,"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":["cqrs","domain-event","infrastructure","middleware","php","psr-11","psr-3","symfony"],"created_at":"2024-12-23T12:34:00.903Z","updated_at":"2025-04-13T03:20:01.513Z","avatar_url":"https://github.com/gpslab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://img.shields.io/packagist/v/gpslab/middleware.svg?maxAge=3600\u0026label=stable)](https://packagist.org/packages/gpslab/middleware)\n[![Total Downloads](https://img.shields.io/packagist/dt/gpslab/middleware.svg?maxAge=3600)](https://packagist.org/packages/gpslab/middleware)\n[![Build Status](https://img.shields.io/travis/gpslab/middleware.svg?maxAge=3600)](https://travis-ci.org/gpslab/middleware)\n[![Coverage Status](https://img.shields.io/coveralls/gpslab/middleware.svg?maxAge=3600)](https://coveralls.io/github/gpslab/middleware?branch=master)\n[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/gpslab/middleware.svg?maxAge=3600)](https://scrutinizer-ci.com/g/gpslab/middleware/?branch=master)\n[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/ed9115e0-283f-4799-993c-3777a044114d.svg?maxAge=3600\u0026label=SLInsight)](https://insight.sensiolabs.com/projects/ed9115e0-283f-4799-993c-3777a044114d)\n[![StyleCI](https://styleci.io/repos/92312680/shield?branch=master)](https://styleci.io/repos/92312680)\n[![License](https://img.shields.io/packagist/l/gpslab/middleware.svg?maxAge=3600)](https://github.com/gpslab/middleware)\n\n# Infrastructure for use middleware in applications\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"request-delegate-pipeline.png\" alt=\"Request delegate pipeline\"\u003e\u003c/p\u003e\n\n## Installation\n\nPretty simple with [Composer](http://packagist.org), run:\n\n```sh\ncomposer require gpslab/middleware\n```\n\n## Middleware chain\n\n`MiddlewareChain` contains a middlewares (`Middleware`) and sequentially apply them to the message by chain.\n\nThere are 3 implementations of the chain, but you can make your own.\n\n* `DirectBindingMiddlewareChain` - direct binding;\n* `ContainerMiddlewareChain` - [PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md) container;\n* `SymfonyContainerMiddlewareChain` - Symfony container *(Symfony 3.3\n[implements](http://symfony.com/blog/new-in-symfony-3-3-psr-11-containers) a\n[PSR-11](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-11-container.md))*.\n\n## Handle command (CQRS)\n\nExample usage middleware for handle Commands in [CQRS](https://github.com/gpslab/cqrs).\n\n```php\n// middleware chain\n$chain = new DirectBindingMiddlewareChain();\n\n// add logger middleware\n$chain-\u003eappend(new LoggerMiddleware($logger));\n// add validator middleware\n$chain-\u003eappend(new ValidatorMiddleware($validator));\n// add middleware for handle command from origin command bus\n$chain-\u003eappend(new CommandMiddleware($command_bus));\n\n// configure command bus\n$bus = new MiddlewareCommandBus($chain);\n\n\n// handle command\ntry {\n    $bus-\u003ehandle($my_command);\n} catch(InvalidMessageException $e) {\n    // show validation errors\n    var_dump($e-\u003egetMessages());\n}\n```\n\n## Handle query (CQRS)\n\nExample usage middleware for handle Queries in [CQRS](https://github.com/gpslab/cqrs).\n\n```php\n// middleware chain\n$chain = new DirectBindingMiddlewareChain();\n\n// add logger middleware\n$chain-\u003eappend(new LoggerMiddleware($logger));\n// add validator middleware\n$chain-\u003eappend(new ValidatorMiddleware($validator));\n// add middleware for handle query from origin query bus\n$chain-\u003eappend(new QueryMiddleware($query_bus));\n\n// configure query bus\n$bus = new MiddlewareQueryBus($chain);\n\n\n// handle query\ntry {\n    $bus-\u003ehandle($my_query);\n} catch (InvalidMessageException $e) {\n    // show validation errors\n    var_dump($e-\u003egetMessages());\n}\n```\n\n## Handle Domain event\n\nExample usage middleware for handle [domain events](https://github.com/gpslab/domain-event).\n\n```php\n// middleware chain\n$chain = new DirectBindingMiddlewareChain();\n\n// add logger middleware\n$chain-\u003eappend(new LoggerMiddleware($logger));\n// add middleware for handle event from origin domain event bus\n$chain-\u003eappend(new DomainEventMiddleware($domain_event_bus));\n\n// configure domain event bus\n$bus = new MiddlewareDomainEventBus($chain);\n\n\n// publish domain event\n$bus-\u003epublish($my_event);\n```\n\n## License\n\nThis bundle is under the [MIT license](http://opensource.org/licenses/MIT). See the complete license in the file: LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fmiddleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpslab%2Fmiddleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpslab%2Fmiddleware/lists"}