PHPackages                             bamiz/use-case-executor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bamiz/use-case-executor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bamiz/use-case-executor
=======================

A library that allows to execute use cases of your application in isolation from the delivery mechanism.

0.5.0(9y ago)11.5k1[1 issues](https://github.com/bartosz-zasada/use-case-executor/issues)1MITPHPPHP &gt;=5.5.0

Since Mar 26Pushed 9y ago1 watchersCompare

[ Source](https://github.com/bartosz-zasada/use-case-executor)[ Packagist](https://packagist.org/packages/bamiz/use-case-executor)[ Docs](https://github.com/bartosz-zasada/use-case-executor)[ RSS](/packages/bamiz-use-case-executor/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (1)

Use Case Executor
=================

[](#use-case-executor)

Use Case Executor is a library that facilitates a certain way of implementation of [Screaming Architecture](https://8thlight.com/blog/uncle-bob/2011/09/30/Screaming-Architecture.html). 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:

[![Application Layer and Use Case Layer](doc/layers-diagram.png)](doc/layers-diagram.png)

Installation
============

[](#installation)

Just run

```
$ composer require bamiz/use-case-executor

```

Basic usage
===========

[](#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`.

```
namespace YourOrganization\YourApplication;

class MyUseCase
{
    public function execute(MyUseCaseRequest $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.

```
$inputProcessorContainer = new \Bamiz\UseCaseExecutor\Container\Container();
$inputProcessorContainer->set(
    \Bamiz\UseCaseExecutor\Execution\UseCaseContextResolver::DEFAULT_INPUT_PROCESSOR,
    new \Bamiz\UseCaseExecutor\Processor\Input\ArrayInputProcessor()
);

$responseProcessorContainer = new \Bamiz\UseCaseExecutor\Container\Container();
$responseProcessorContainer->set(
    \Bamiz\UseCaseExecutor\Execution\UseCaseContextResolver::DEFAULT_RESPONSE_PROCESSOR,
    new \Bamiz\UseCaseExecutor\Processor\Response\IdentityResponseProcessor()
);
```

Create a Container for your Use Cases and add your Use Case to it. Set up the Context Resolver with all the containers.

```
$useCaseContainer = new \Bamiz\UseCaseExecutor\Container\Container();
$useCaseContainer->set('my_use_case', new MyUseCase());

$contextResolver = new \Bamiz\UseCaseExecutor\Execution\UseCaseContextResolver(
    $useCaseContainer,
    $inputProcessorContainer,
    $responseProcessorContainer
);
```

Add the configuration of the Use Case to the Context Resolver. The minimum configuration contains the Use Case name and its Request class name.

```
$contextResolver->addUseCaseConfiguration(['use_case' => 'my_use_case', 'request_class' => MyUseCaseRequest::class]);
```

Create a Use Case Executor:

```
$actorRecognizer = new \Bamiz\UseCaseExecutor\Actor\CompositeActorRecognizer();
$useCaseExecutor = new \Bamiz\UseCaseExecutor\UseCaseExecutor($contextResolver, $actorRecognizer);
```

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:

```
$output = $useCaseExecutor->execute('my_use_case', $input);
```

See also
========

[](#see-also)

- [Screaming Architecture blog post on Robert C. Martin's blog](https://8thlight.com/blog/uncle-bob/2011/09/30/Screaming-Architecture.html)

- a blog post published on September 30, 2011, explaining the concept of Screaming Architecture in detail

- [Use Case Executor Bundle](https://github.com/bartosz-zasada/use-case-executor-bundle) - a Symfony bundle providing configuration and several Processors that make the Executor much easier to use with Symfony
- [Screaming Webshop](https://github.com/bartosz-zasada/screaming-webshop) - an example of Screaming Architecture implementation, with and without using Use Case Executor Bundle
- [Slides from my presentation about Screaming Architecture](https://speakerdeck.com/bamizpl/screaming-architecture)

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3385d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4774555?v=4)[Bartosz Zasada](/maintainers/bartosz-zasada)[@bartosz-zasada](https://github.com/bartosz-zasada)

### Embed Badge

![Health badge](/badges/bamiz-use-case-executor/health.svg)

```
[![Health](https://phpackages.com/badges/bamiz-use-case-executor/health.svg)](https://phpackages.com/packages/bamiz-use-case-executor)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M24.9k](/packages/friendsofphp-php-cs-fixer)[symfony/rate-limiter

Provides a Token Bucket implementation to rate limit input and output in your application

27054.3M281](/packages/symfony-rate-limiter)[symfony/ldap

Provides a LDAP client for PHP on top of PHP's ldap extension

1408.1M59](/packages/symfony-ldap)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19346.6k3](/packages/symfony-ux-cropperjs)[php-soap/ext-soap-engine

An ext-soap engine implementation

443.5M12](/packages/php-soap-ext-soap-engine)[symfony/ux-toggle-password

Toggle visibility of password inputs for Symfony Forms

27600.4k5](/packages/symfony-ux-toggle-password)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
