Download the PHP package bamiz/use-case-executor without Composer
On this page you can find all versions of the php package bamiz/use-case-executor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bamiz/use-case-executor
More information about bamiz/use-case-executor
Files in bamiz/use-case-executor
Package use-case-executor
Short Description A library that allows to execute use cases of your application in isolation from the delivery mechanism.
License MIT
Homepage https://github.com/bartosz-zasada/use-case-executor
Informations about the package use-case-executor
Use Case Executor
Use Case Executor is a library that facilitates a certain way of implementation of Screaming Architecture.
From the point of view of this library, every Use Case of your system is implemented in its own class, with a single
public method: execute()
. Any data that the Use Case requires to be executed is passed to the execute()
method
in a form of a Use Case Request object, which is a simple data structure, preferably a class with all its fields public.
Any data that needs to be presented to the Actor (the outside-world executor of the Use Case) is returned in a form
of a Use Case Response.
Use Case Requests and Responses belong to the business logic layer. They must know nothing about the way in which the application receives its data (the application's Input), and the way in which the application presents the data (the application's Output). This means that the Input must be processed, so that the data required by the Request are retrieved from it and put into the proper Request object. Similarly, the Response that the Use Case returns must be processed, so that a proper Output that contains information interesting to the Actor is created and returned. Use Case Executor uses Input Processors and Response Processors to perform these operations.
Once a separation like described above has been achieved, the dependencies between the application layer and the business logic layer present themselves like this:
Installation
Just run
$ composer require bamiz/use-case-executor
Basic usage
Create a class that represents a Use Case of your system. Implement its behavior in execute()
method.
Pass all the required input data as an object, preferably named like your Use Case plus the word Request
.
In the bootstrap section of your application you will need to set up the dependencies of Use Case Executor. Set up Input Processor Container and Response Processor container by adding the default Processors to them.
Create a Container for your Use Cases and add your Use Case to it. Set up the Context Resolver with all the containers.
Add the configuration of the Use Case to the Context Resolver. The minimum configuration contains the Use Case name and its Request class name.
Create a Use Case Executor:
Use the Executor to execute your Use Cases. Leave the details of processing the Input and creating the Output to the Input and Response processors:
See also
- Screaming Architecture blog post on Robert C. Martin's blog
- a blog post published on September 30, 2011, explaining the concept of Screaming Architecture in detail
- Use Case Executor Bundle - a Symfony bundle providing configuration and several Processors that make the Executor much easier to use with Symfony
- Screaming Webshop - an example of Screaming Architecture implementation, with and without using Use Case Executor Bundle
- Slides from my presentation about Screaming Architecture