PHPackages                             flyokai/generic - 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. flyokai/generic

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

flyokai/generic
===============

Generics definitions

v1.1.7(3w ago)0102MITPHP

Since Apr 25Pushed 3w agoCompare

[ Source](https://github.com/flyokai/generic)[ Packagist](https://packagist.org/packages/flyokai/generic)[ RSS](/packages/flyokai-generic/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (14)Used By (2)

flyokai/generic
===============

[](#flyokaigeneric)

> User docs → [`README.md`](README.md) · Agent quick-ref → [`CLAUDE.md`](CLAUDE.md) · Agent deep dive → [`AGENTS.md`](AGENTS.md)

> Builder, tuner, and execution-pipeline patterns expressed with PHPDoc generics — a tiny but pervasive primitive across Flyokai.

The package gives you four parametric interfaces — `State`, `Builder`, `Tuner`, `Execution` — plus DI-aware containers that compose them. Tuners are how Flyokai lets multiple modules contribute settings to one shared object (an `InputDefinition`, a `Router`, an ACL builder, …) without coupling them.

Features
--------

[](#features)

- `State` / `Builder` — generic state holder + builder pipeline
- `Tuner` / `TunerContainer` — composable, ordered state mutators
- `Execution` / `ExecutionContainer` — composable side-effect runners
- `InvalidStateException` — base for builder validation errors
- Fully PHPDoc-`@template` annotated for static analysers

Installation
------------

[](#installation)

```
composer require flyokai/generic
```

Quick start
-----------

[](#quick-start)

```
use Flyokai\Generic\State;
use Flyokai\Generic\BuilderImpl;
use Flyokai\Generic\Tuner;

/** @implements State */
final class ObjectState implements State
{
    public function __construct(public \stdClass $value) {}
    public function get(): \stdClass { return $this->value; }
}

/** @implements Tuner */
final class GreetingTuner implements Tuner
{
    public function tune(State $state): State
    {
        $state->value->greeting = 'hello';
        return $state;
    }
}

/** @extends BuilderImpl */
final class ObjectBuilder extends BuilderImpl {}

$builder = new ObjectBuilder(
    fn() => new ObjectState(new \stdClass()),
    new GreetingTuner(),
);

$obj = $builder->build();   // \stdClass { greeting: "hello" }
```

Composing tuners
----------------

[](#composing-tuners)

```
use Flyokai\Generic\TunerContainer;
use Amp\Injector\Composition;

$tuners = new TunerContainer($composition);  // Composition from amphp-injector
$state  = $tuners->tune($state);             // applies every tuner in order
```

`TunerContainer` accepts an `Amp\Injector\Composition` of `Tuner` instances — each module registers its own tuner via DI and ordering (`before`/`after`/`depends`) decides who runs when.

Executions
----------

[](#executions)

`Execution` is the side-effect cousin of `Tuner` — it runs against a context but does not return modified state:

```
use Flyokai\Generic\Execution;
use Flyokai\Generic\ExecutionContainer;

/** @implements Execution */
final class LogExecution implements Execution
{
    public function execute(mixed $context): void
    {
        $context->logger->info('done');
    }
}

$pipeline = new ExecutionContainer($composition);
$pipeline->execute($context);
```

Subclassing `ExecutionContainer` and overriding `executeChild()` lets you inject hooks (timing, error handling) around every child execution.

Where it shows up
-----------------

[](#where-it-shows-up)

- `flyokai/symfony-console` — `InputState` is `State`; `RequiredOptionHandler` and friends are tuners.
- `flyokai/application` — ACL Builder, RouterBuilder, ServerBuilder all expose tuner compositions so modules can extend them.
- `flyokai/data-service`, `flyokai/oauth-server` — `RouterBuilder` middleware and route registration.

Gotchas
-------

[](#gotchas)

- `BuilderImpl` is `abstract`; you must subclass to constrain the generic parameter.
- Tuner order in a `TunerContainer` is significant — wire ordering carefully via `compositionItem(...)` `before`/`after`/`depends`.
- `ExecutionContainer` does not aggregate return values — they are intentionally `void`.
- PHPDoc `@template` annotations are static-analysis only; nothing enforces the type at runtime.

See also
--------

[](#see-also)

- [`flyokai/amphp-injector`](../amphp-injector/README.md) — provides the `Composition` mechanism `TunerContainer` and `ExecutionContainer` rely on.

License
-------

[](#license)

MIT

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance91

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 87.5% 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 ~5 days

Total

10

Last Release

24d ago

Major Versions

0.0.1 → v1.1.22026-06-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/247743048?v=4)[flyokai](/maintainers/flyokai)[@flyokai](https://github.com/flyokai)

---

Top Contributors

[![flyokai](https://avatars.githubusercontent.com/u/247743048?v=4)](https://github.com/flyokai "flyokai (7 commits)")[![wtsergo](https://avatars.githubusercontent.com/u/305326?v=4)](https://github.com/wtsergo "wtsergo (1 commits)")

### Embed Badge

![Health badge](/badges/flyokai-generic/health.svg)

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

PHPackages © 2026

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