PHPackages                             gcdtech/usecases - 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. gcdtech/usecases

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

gcdtech/usecases
================

Base classes and interfaces for implementing the Use Case pattern along with entities and entity emitting iterators.

2.0.0(3y ago)1948Apache-2.0PHPPHP ^8.0.0

Since Aug 1Pushed 3y ago4 watchersCompare

[ Source](https://github.com/GCDTech/php-usecase-pattern)[ Packagist](https://packagist.org/packages/gcdtech/usecases)[ RSS](/packages/gcdtech-usecases/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

PHP Use Case Pattern.
=====================

[](#php-use-case-pattern)

Base classes and interfaces for implementing the Use Case pattern along with entities and entity emitting iterators.

UseCases
========

[](#usecases)

A UseCase is a single class, implementing one 'use case' of the application business logic. It co-ordinates the manipulation of application state to acheive it's purpose.

Key objectives
--------------

[](#key-objectives)

#### 1. Be portable

[](#1-be-portable)

By using only simple objects and primitive types as parameters and return types the use cases of your application are a permanent representation of your business logic and moving to a new language or framework should **not** require any significant recoding.

##### 2. Integrate with framework as a plugin

[](#2-integrate-with-framework-as-a-plugin)

Where use cases need to interact with external layers (for example to persist changes in state) this should always be acheived by wrapping the framework functionality as a service and injecting it as a dependancy. This ensures that the UseCases can always be moved to a new framework and the interop with the framework is easily assessed, rewritten and replaced with no changes to the UseCase code or tests.

#### 3. Be testable

[](#3-be-testable)

As UseCases only deal with pure and simple PHP classes they should be 100% testable and so TDD should be the favoured approach to development.

#### 4. Do one thing

[](#4-do-one-thing)

A UseCase should be focused on completing one business goal - for example creation of an invoice. Where the action requires a concert of other changes this can be acheived by calling other UserCases.

Signature of a UseCase
----------------------

[](#signature-of-a-usecase)

Generally a UseCase has a single method 'execute' which takes arguments and returns a response value. It may also have a constructor through which service dependancies are injected.

```
class DispatchOrderUseCase extends UseCase
{
  private $emailProvider;

  public function __construct(EmailProvider $email)
  {
    $this->emailProvider = $email;
  }

  public function execute(Order $order)
  {
    // ... Do something to despatch the order
    $this->emailProvider->send(new DispatchEmail($order));
  }
}
```

Calling a UseCase
-----------------

[](#calling-a-usecase)

A UseCase should not be instantiated directly except in unit tests. In production code the static `create()` method ensure dependancies are injected using the DI container.

```
// Note no mention of the EmailProvider here...
DispatchOrderUseCase::create()->execute($order);
```

Entities
========

[](#entities)

An entity is a simple POPO (Plain Old PHP Object) with no frills that represents the data passed into and out of UseCases. Generally an entity can be regarded as a model for a business object.

This library defines a base `Entity` class only to allow for basic type recognition (e.g. $arg instanceof Entity)

EntityEmittingIterator
======================

[](#entityemittingiterator)

ORMs generally support representing collections as iterable objects creating objects lazily as required. This is good practice to keep memory usage to the minimum possible. To represent a list we've provided an EntityEmittingIterator that extends the base Iterator PHP interface and can be used to classify parameter and return types.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~1302 days

Total

2

Last Release

1180d ago

Major Versions

1.0.0 → 2.0.02023-02-23

PHP version history (2 changes)1.0.0PHP ^7.0.0

2.0.0PHP ^8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8905301607df4f73893d5b665c97b959572bc9394a5ff3c9f5907de6531aad6d?d=identicon)[acuthbert](/maintainers/acuthbert)

---

Top Contributors

[![acuthbert](https://avatars.githubusercontent.com/u/408400?v=4)](https://github.com/acuthbert "acuthbert (7 commits)")

### Embed Badge

![Health badge](/badges/gcdtech-usecases/health.svg)

```
[![Health](https://phpackages.com/badges/gcdtech-usecases/health.svg)](https://phpackages.com/packages/gcdtech-usecases)
```

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

705122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31178.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

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