-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from bowphp/refactoring
Add readme file
- Loading branch information
Showing
6 changed files
with
56 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2023 Franck DAKIA <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Bow CQRS | ||
|
||
CQRS (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. | ||
CQRS (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. | ||
|
||
[For more information](https://www.martinfowler.com/bliki/CQRS.html) | ||
|
||
|
@@ -21,11 +21,14 @@ use Bow\CQRS\Command\CommandInterface; | |
|
||
class CreateUserCommand implements CommandInterface | ||
{ | ||
public function __construct(public string $username, public string $email) {} | ||
public function __construct( | ||
public string $username, | ||
public string $email | ||
) {} | ||
} | ||
``` | ||
|
||
Second, create the handler here: | ||
Create the handler here: | ||
|
||
```php | ||
use Bow\CQRS\Command\CommandHandlerInterface; | ||
|
@@ -37,7 +40,9 @@ class CreateUserCommandHandler implements CommandHandlerInterface | |
public function process(CommandInterface $command): mixed | ||
{ | ||
if ($this->userService->exists($command->email)) { | ||
throw new UserServiceException("The user already exists"); | ||
throw new UserServiceException( | ||
"The user already exists" | ||
); | ||
} | ||
|
||
return $this->userService->create([ | ||
|
@@ -75,11 +80,17 @@ class UserController extends Controller | |
|
||
public function __invoke(Request $request) | ||
{ | ||
$command = new CreateUserCommand($request->get('username'), $request->get('email')); | ||
$payload = $request->only(['username', 'email']); | ||
$command = new CreateUserCommand( | ||
$payload['username'], | ||
$payload['email'] | ||
); | ||
|
||
$result = $this->commandBus->execute($command); | ||
|
||
return redirect()->back()->withFlash("message", "User created"); | ||
return redirect() | ||
->back() | ||
->withFlash("message", "User created"); | ||
} | ||
} | ||
``` | ||
|
@@ -90,6 +101,12 @@ Put a new route: | |
$app->post("/users/create", UserController::class); | ||
``` | ||
|
||
Put a new route: | ||
|
||
```php | ||
$app->post("/users/create", UserController::class); | ||
``` | ||
|
||
## Contributing | ||
|
||
Thank you for considering contributing to Bow Framework! The contribution guide is in the framework documentation. | ||
|
@@ -101,4 +118,4 @@ Thank you for considering contributing to Bow Framework! The contribution guide | |
|
||
[[email protected]](mailto:[email protected]) - [@papacdev](https://twitter.com/papacdev) | ||
|
||
**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 slask](https://join.slack.com/t/bowphp/shared_invite/enQtNzMxOTQ0MTM2ODM5LTQ3MWQ3Mzc1NDFiNDYxMTAyNzBkNDJlMTgwNDJjM2QyMzA2YTk4NDYyN2NiMzM0YTZmNjU1YjBhNmJjZThiM2Q)** | ||
**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)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters