Download the PHP package ug-php/clean-architecture-core without Composer
On this page you can find all versions of the php package ug-php/clean-architecture-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ug-php/clean-architecture-core
More information about ug-php/clean-architecture-core
Files in ug-php/clean-architecture-core
Package clean-architecture-core
Short Description PHP clean architecture core library
License MIT
Homepage https://github.com/ug-libraries/clean-architecture-core-php
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 requests and use cases, paying special attention to handling missing and unauthorized fields.
Practical examples are provided using code snippets 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
To install the core library, run the following command in your project directory:
Core Overview
Application Request
Request serve as input objects, encapsulating data from your HTTP controller. In the core library, use the \Urichy\Core\Request\Request
class as the foundation for creating custom application request objects.
Define the expected fields using the requestPossibleFields
property.
Handling unauthorized fields:
Handling missing fields:
When request successfully created.
Presenter
Presenter handle the output logic of your use case. Extend \Urichy\Core\Presenter\Presenter
and implement \Urichy\Core\Presenter\PresenterInterface
.
Response
Response encapsulate the data returned by use cases. They include status information, messages, and any relevant data. Use \Urichy\Core\Response\Response
to create use case responses.
Use Case
Use cases encapsulate business logic and orchestrate the flow of data between requests, entities, and presenters. Extend the \Urichy\Core\Usecase\Usecase
class and implement \Urichy\Core\Usecase\UsecaseInterface
with the execute
method.
@see example below
Exception
When an exception is thrown during processing, you can use some method to handle the exception data.
How to create an exception ?
-
Create an exception class that extends
\Urichy\Core\Exception\Exception
- Throw an exception when something has gone wrong and handling it.
Example Usage
From Scratch (PHP Without a Framework)
Project Structure
Code Examples
public/index.php
src/Controller/BookController.php
src/Request/BookRecordRequest.php
Using beberlei/assert
validation library
Using Symfony Validator
library
src/Presenter/JsonResponsePresenter.php
src/Presenter/HtmlResponsePresenter.php
src/UseCase/RegisterBookUsecase.php
src/Response/Response.php
Example with Symfony
Project Structure
Code Examples
src/Controller/BookController.php
Example with Laravel
Project Structure
Code Examples
app/Http/Controllers/BookController.php
With request and presenter
Without presenter, but with request.
Without request and presenter
Unit Tests
Command to Run Unit Tests
License
Information on Copyright and MIT License
- Written and copyrighted ©2023-present by Ulrich Geraud AHOGLA. [email protected]
- Clean architecture core is open-sourced software licensed under the MIT license