PHPackages                             mrhash/taskmachine - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mrhash/taskmachine

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

mrhash/taskmachine
==================

Modular micro-service task pipelining &amp; orchestration with validated state machine integrity.

12261[6 issues](https://github.com/MrHash/TaskMachine/issues)PHPCI failing

Since Nov 17Pushed 6y ago3 watchersCompare

[ Source](https://github.com/MrHash/TaskMachine)[ Packagist](https://packagist.org/packages/mrhash/taskmachine)[ RSS](/packages/mrhash-taskmachine/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

TaskMachine
===========

[](#taskmachine)

### Modular micro-service task pipelining &amp; orchestration with validated state machine integrity.

[](#modular-micro-service-task-pipelining--orchestration-with-validated-state-machine-integrity)

Define micro-service tasks and arrange them into state machine managed flows with a simple and expressive API. You can create build tool chains, processing pipelines, utility services, or even serve web pages...

#### State machines for the masses!

[](#state-machines-for-the-masses)

Examples
========

[](#examples)

Simple pipeline
---------------

[](#simple-pipeline)

We define two simple inline tasks which are independent. The machine executes the two tasks in order and then finishes.

```
$tmb = new TaskMachineBuilder;

// Define some tasks
$tmb->task('hello', function () {
  echo 'Hello World';
});

$tmb->task('goodbye', function () {
  echo 'Goodbye World';
});

// Define and build a machine
$tm = $tmb->machine('greetings')
  // specify an initial task and transition
  ->hello([
    'initial' => true,
    'transition' => 'goodbye'
  ])
   // specify a final task
  ->goodbye(['final' => true])
  ->build();

// Run the machine.
$tm->run('greetings');
```

Pipeline with DI
----------------

[](#pipeline-with-di)

Now we introduce some more tasks with DI. Tasks are isolated by definition and optionally have expected inputs and outputs.

```
// Bootstrap your own Auryn injector and throw it in
$tmb = new TaskMachineBuilder(new TaskFactory($myInjector));

// Define some tasks
$tmb->task(
  'translate',
  function (InputInterface $input, MyTranslationInterface $translator) {
    // Auryn injects fully constructed dependencies. Run your things.
    $translation = $translator->translate($input->get('text'));
    return ['text' => $translation];
  }
);

// Input from previous task is injectable and immutable
$tmb->task('echo', function (InputInterface $input) {
  echo $input->get('text');
});

$tmb->task('goodbye', function () {
  return ['closing' => 'Goodbye World'];
});

 // Define and build machine
$tm = $tmb->machine('translator')
  ->translate([
    'initial' => true,
    'transition' => 'echo'
  ])
  ->echo(['transition' => 'goodbye'])
  ->goodbye(['final' => true])
  ->build();

// Run with input and then echo the output from the last task
$output = $tm->run('translator', ['text' => 'Hello World']);
echo $output->get('closing');
```

Any faults in the configuration of your machine will result in a build error! Tasks must be linked together correctly and have valid unambiguous transitions.
-------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#any-faults-in-the-configuration-of-your-machine-will-result-in-a-build-error-tasks-must-be-linked-together-correctly-and-have-valid-unambiguous-transitions)

Conditional branching
---------------------

[](#conditional-branching)

Machines can branch to different tasks based on conditions written in Symfony Expression Language.

```
$tmb = new TaskMachineBuilder(new TaskFactory($myInjector));

// Define some tasks
$tmb->task('process', function () {
  // This outputs a random true or false result
  $result = (bool)random_int(0,1);
  return ['success' => $result];
});

// Task with your instantiated object which implements TaskHandlerInterface
$tmb->task('finish', new Finisher($myService));

// Task with your handler which implements TaskHandlerInterface
// Your dependencies are injected
$tmb->task('fail', MyCustomServiceInterface::class);

// Define and build a machine with different final outcomes
$tm = $tmb->machine('switcher')
  ->process([
    'initial' => true,
    // Specify switch conditions to subsequent tasks
    'transition' => [
      'output.success' => 'finish',
      '!output.success' => 'fail'
    ]
  ])
  ->finish(['final' => true])
  ->fail(['final' => true])
  ->build();

// Run it.
$tm->run('switcher');
```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfd8067a48429509afed9e9e36d51b8d5bfecd208fe9672ef7fc4a354ea7541b?d=identicon)[MrHash](/maintainers/MrHash)

---

Top Contributors

[![MrHash](https://avatars.githubusercontent.com/u/390925?v=4)](https://github.com/MrHash "MrHash (59 commits)")

---

Tags

dependency-injectionmicroserviceorchestrationpipelinestate-machinetaskvalidationworkflow

### Embed Badge

![Health badge](/badges/mrhash-taskmachine/health.svg)

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

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

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