clean-architecture
, (*1)
Package for isolate your domain code from framework dependency, (*2)
What are Domain,Application and Infrastructure layer? Click here for a resume., (*3)
Why?
Why did you code this package?
When I code, I usually isolate the Domain layer from Application layer and Infrastructure layer, and every time I do it I need to re-build a set of objects that helps me doing this., (*4)
Those objects often are a Request, a Response and some Errors., (*5)
This package is born for me, to avoid re-building such set of objects, also avoiding some copy/paste from different projects., (*6)
Why should you isolate your domain code from Application and Infrastructure dependencies?
Imagine that your PHP application is currently built on top of Laravel framework., (*7)
And use a modern frameworks (such Laravel, Symfony or Slim) is a very good thing. Helps you to write a better code without reinvent the wheel., (*8)
But what if you want/must switch your current framework for performance, architectural or other reasons to an another one?, (*9)
Usually this is very painful, and you are despondent to change it.
This choose bind you to a tool that might not be as good as before for your project., (*10)
And this is only an example. There can be a lot of more reasons why you want to change framework., (*11)
How can I isolate it?
Using some DDD concepts, you can totally (or almost) isolate your domain code from the Application layer (Laravel for example) and from the Infrastructure layer (Postgresql or Mysql for example)., (*12)
So the Domain of my application is not relegated to a particular framework/package/database, and can be "easily" switched., (*13)
What hepls me to realize this package?
There are some books that helped me to "think" in this way. Here some of them:, (*14)
Clean PHP, (*15)
DDD in PHP, (*16)
DDD by Evans, (*17)
A Minimal Documentation
-
Common, (*18)
-
Collections, (*19)
-
Collection, (*20)
An interface to use instead an array of objects., (*21)
-
ArrayCollection, (*22)
An implementation of Collection using php array., (*23)
-
Enum, (*24)
-
Enum, (*25)
Used for give Enum support on PHP., (*26)
-
ReflectionEnum, (*27)
An implementation of Enum using reflection., (*28)
-
Mapper, (*29)
An interface to use for transform object into array and viceversa., (*30)
An interface to use for transform User instances into array and viceversa., (*31)
-
Persistence, (*32)
An interface to use for transaction cross Bounded Contexts., (*33)
-
Use Cases, (*34)
An interface to use for isolate the use case from the request (CLI,HTTP...)., (*35)
-
Error, (*36)
-
Error, (*37)
A representation of a generic error in the domain. The error it will be specified using type & code., (*38)
-
AbstractError, (*39)
An abstract implementation of ErrorInterface., (*40)
-
ErrorType, (*41)
An interface that extends Enum, used for specify all the error type of your domain., (*42)
-
AbstractErrorType, (*43)
An implementation of ErrorType., (*44)
-
Request, (*45)
-
Request, (*46)
An interface used as DTO for pass data from the infrastructure/application to the domain., (*47)
-
CollectionRequest, (*48)
An implementation of the Request using Collection., (*49)
-
Response, (*50)
-
Response, (*51)
An interface used for pass data from the domain to the infrastructure/application, it uses two main properties
Errors: pass all "errors"
Data: pass all other "data/information", (*52)
-
CollectionResponse, (*53)
An implementation of Response using Collection., (*54)
-
Validation, (*55)
-
ValidableRequest, (*56)
An interface used for the validate request's data inside the self request, (*57)
-
ValidableUseCase, (*58)
An interface used for the validate request's data inside the UseCase, (*59)
A Practical Example
Changelog
[0.4] 2018-06-01
- [BC] added a type-hing to
Enum interface. You need to adapt equals method in your class implementing
such inteface (or extending ReflectionEnum class)