Download the PHP package urichy/clean-architecture-core without Composer
On this page you can find all versions of the php package urichy/clean-architecture-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download urichy/clean-architecture-core
More information about urichy/clean-architecture-core
Files in urichy/clean-architecture-core
Package clean-architecture-core
Short Description PHP cleancoders clean architecture core library
License MIT
Homepage https://github.com/richy-cleancoders/php-clean-architecture-core
Informations about the package clean-architecture-core
Core library for clean architecture in PHP
Introduction
This documentation guides you through the utilization of the core library for implementing clean architecture in PHP. We'll explore the creation of custom application request and use cases, paying special attention to handling missing and unauthorized fields.
Practical examples are provided using code snippets from a test suite to showcase the library's usage in building a modular and clean PHP application.
Prerequisites
Ensure that you have the following:
PHP
installed on your machine (version8.2.0 or higher
).Composer
installed for dependency management.
Installation
Core Overview
Application Request
Requests serve as input object, encapsulating data from your http controller. In the core library, use the \Cleancoders\Core\Request\Request
class
as the foundation for creating custom application request object. Define the expected fields using the requestPossibleFields
property.
Presenter
Presenters handle the output logic of your usecase. You have to extends \Cleancoders\Core\Presenter\Presenter
and
implements \Cleancoders\Core\Presenter\PresenterInterface
Usecase
Use cases encapsulate business logic and orchestrate the flow of data between requests, entities, and presenters.
Extends the \Cleancoders\Core\Usecase\Usecase
class and implements \Cleancoders\Core\Usecase\UsecaseInterface
with the execute method.
Response
- Use
\Cleancoders\Core\Response\Response
to create usecaseresponse
. - Supports success/failure status, custom message, HTTP status codes, and response data.
- I recommend you to extends
\Cleancoders\Core\Response\Response
class to create your own response
Example of how to use the core library
- Creating a custom request and handling missing/unauthorized fields
- Extends
\Cleancoders\Core\Request\Request
and implements\Cleancoders\Core\Request\RequestInterface
to create custom application request objects. - Define the possible fields in the
requestPossibleFields
property.
- Creating a custom usecase
- Extends
\Cleancoders\Core\Usecase\Usecase
and implements\Cleancoders\Core\Usecase\UsecaseInterface
to create your use cases. - Implement the
execute
method for the use case logic.
- Create the custom presenter
- Extends
\Cleancoders\Core\Presenter\Presenter
to createpresenters
.
- Executing the Usecase
Instantiate your custom usecase, set your custom request and custom presenter, and execute the usecase.
Example with symfony controller
Example with laravel controller
Units Tests
You also can execute unit tests.
License
- Written and copyrighted ©2023-present by Ulrich Geraud AHOGLA. [email protected]
- Clean architecture core is open-sourced software licensed under the MIT license