{"id":25663686,"url":"https://github.com/bowphp/cqrs","last_synced_at":"2025-04-22T11:35:40.674Z","repository":{"id":167920225,"uuid":"612565238","full_name":"bowphp/cqrs","owner":"bowphp","description":"Command Query Responsibility Segregation approach for Bow framework","archived":false,"fork":false,"pushed_at":"2025-02-02T17:45:17.000Z","size":65,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-13T08:26:52.607Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://bowphp.com","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/bowphp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-11T10:29:28.000Z","updated_at":"2025-01-20T16:36:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"67164e98-8ff7-4eb9-9a9e-8681ab1466fb","html_url":"https://github.com/bowphp/cqrs","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"1bd385265167270f345101ea2735e748317ed3d9"},"previous_names":["bowphp/cqrs"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowphp%2Fcqrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowphp%2Fcqrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowphp%2Fcqrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowphp%2Fcqrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bowphp","download_url":"https://codeload.github.com/bowphp/cqrs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249365038,"owners_count":21258082,"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":[],"created_at":"2025-02-24T05:18:08.867Z","updated_at":"2025-04-22T11:35:40.619Z","avatar_url":"https://github.com/bowphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bow CQRS\r\n\r\nCQRS (Command Query Responsibility Segregation). It's a pattern that I first heard described by Greg Young. At its heart is the notion that you can use a different model to update information than the model you use to read information. For some situations, this separation can be valuable but beware that for most systems CQRS adds risky complexity.\r\n\r\n[For more information](https://www.martinfowler.com/bliki/CQRS.html)\r\n\r\n## Install\r\n\r\nThe package uses php \u003e= 8.1\r\n\r\n```bash\r\ncomposer require bowphp/cqrs\r\n```\r\n\r\n## Help\r\n\r\nFirst, create the example command:\r\n\r\n```php\r\nuse Bow\\CQRS\\Command\\CommandInterface;\r\n\r\nclass CreateUserCommand implements CommandInterface\r\n{\r\n    public function __construct(\r\n        public string $username,\r\n        public string $email\r\n    ) {}\r\n}\r\n```\r\n\r\nCreate the handler here:\r\n\r\n```php\r\nuse Bow\\CQRS\\Command\\CommandHandlerInterface;\r\n\r\nclass CreateUserCommandHandler implements CommandHandlerInterface\r\n{\r\n    public function __construct(public UserService $userService) {}\r\n\r\n    public function process(CommandInterface $command): mixed\r\n    {\r\n        if ($this-\u003euserService-\u003eexists($command-\u003eemail)) {\r\n            throw new UserServiceException(\r\n                \"The user already exists\"\r\n            );\r\n        }\r\n\r\n        return $this-\u003euserService-\u003ecreate([\r\n            \"username\" =\u003e $command-\u003eusername,\r\n            \"email\" =\u003e $command-\u003eemail\r\n        ]);\r\n    }\r\n}\r\n```\r\n\r\nAdd command to the register in `App\\Configurations\\ApplicationConfiguration::class`:\r\n\r\n```php\r\nuse Bow\\CQRS\\Registration as CQRSRegistration;\r\n\r\npublic function run()\r\n{\r\n    CQRSRegistration::commands([\r\n        CreateUserCommand::class =\u003e CreateUserCommandHandler::class\r\n    ]);\r\n}\r\n```\r\n\r\nExecute the command in the controller:\r\n\r\n```php\r\nnamespace App\\Controllers;\r\n\r\nuse App\\Controllers\\Controller;\r\nuse App\\Commands\\CreateUserCommand;\r\n\r\nclass UserController extends Controller\r\n{\r\n    public function __construct(private CommandBus $commandBus) {}\r\n\r\n    public function __invoke(Request $request)\r\n    {\r\n        $payload = $request-\u003eonly(['username', 'email']);\r\n        $command = new CreateUserCommand(\r\n            $payload['username'],\r\n            $payload['email']\r\n        );\r\n\r\n        $result = $this-\u003ecommandBus-\u003eexecute($command);\r\n\r\n        return redirect()\r\n            -\u003eback()\r\n            -\u003ewithFlash(\"message\", \"User created\");\r\n    }\r\n}\r\n```\r\n\r\nPut a new route:\r\n\r\n```php\r\n$app-\u003epost(\"/users/create\", UserController::class);\r\n```\r\n\r\n## Contributing\r\n\r\nThank you for considering contributing to Bow Framework! The contribution guide is in the framework documentation.\r\n\r\n- [Franck DAKIA](https://github.com/papac)\r\n- [Thank's collaborators](https://github.com/bowphp/framework/graphs/contributors)\r\n\r\n## Contact\r\n\r\n[papac@bowphp.com](mailto:papac@bowphp.com) - [@papacdev](https://twitter.com/papacdev)\r\n\r\n**Please, if there is a bug in the project. Contact me by email or leave me a message on [slack](https://bowphp.slack.com). or [join us on slack](https://join.slack.com/t/bowphp/shared_invite/enQtNzMxOTQ0MTM2ODM5LTQ3MWQ3Mzc1NDFiNDYxMTAyNzBkNDJlMTgwNDJjM2QyMzA2YTk4NDYyN2NiMzM0YTZmNjU1YjBhNmJjZThiM2Q)**\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowphp%2Fcqrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbowphp%2Fcqrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowphp%2Fcqrs/lists"}