PHPackages                             jildertmiedema/commander - 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. [CLI &amp; Console](/categories/cli)
4. /
5. jildertmiedema/commander

ActiveLibrary[CLI &amp; Console](/categories/cli)

jildertmiedema/commander
========================

Command bus implementation: Commands and domain events

v0.1.0(11y ago)02.6k1MITPHPPHP &gt;=5.4.0

Since Aug 4Pushed 11y ago1 watchersCompare

[ Source](https://github.com/jildertmiedema/commander)[ Packagist](https://packagist.org/packages/jildertmiedema/commander)[ RSS](/packages/jildertmiedema-commander/feed)WikiDiscussions master Synced today

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

Domain commander
================

[](#domain-commander)

=========

This package is able run domain commands easily. Commands are used to separate domain logic from your php framework.

This package is based on [Laravel Commander](https://github.com/laracasts/Commander) build by [JeffreyWay](https://github.com/JeffreyWay).

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

[](#installation)

Install through Composer.

```
"require": {
    "jildertmiedema/commander": "~0.1"
}
```

What does it do
---------------

[](#what-does-it-do)

- It creates a command object. The command object is [data transfer object](http://en.wikipedia.org/wiki/Data_transfer_object) between the framework/controller and the domain logic.
- It will fill the command object with the request data (For example `$_GET`, `$_POST`, `$app['request']->query->all()`).
- It will try to find a validator class, when it's found it will validate the input.
- If decorators have been set it will execute the decorators. (For example a sanitizer).
- It will find and execute the handler for the command.

Integrate to the framework
--------------------------

[](#integrate-to-the-framework)

### Silex

[](#silex)

This package can easily be used in [Silex](http://silex.sensiolabs.org).

It will try to find a handler(required) and a validator (not required) from application container using the following convention.

```
//without namespace "ExampleCommand"
$app[$className . '.handler']; // exampleCommand.handler
$app[$className . '.validator']; // exampleCommand.validator

//with namespace "Acme\Domain\ExampleCommand"
$app[$className . '.handler']; // acme.domain.exampleCommand.handler
$app[$className . '.validator']; // acme.domain.exampleCommand.validator
```

Usage:

```
$app->register(new JildertMiedema\Commander\Silex\CommanderServiceProvider());
```

Example:

```
class TestCommand {
    public $test;
    public $extra;

    public function __construct($test, $extra)
    {
        $this->test = $test;
        $this->extra = $extra;
    }
}

class TestCommandHandler implements CommandHandler
{

    public function handle($command)
    {
        //handle the command
    }
}

$app['testCommand.handler'] = $app->share(function() use ($app) {
    return new TestCommandHandler();
});

$app->get('/', function() use ($app) {
    return $app['commander.executor']->execute('TestCommand');
});
```

For a full example see [silex.php](https://github.com/jildertmiedema/commander/blob/master/examples/silex.php)

For usage in controllers see [CommanderController.php](https://github.com/jildertmiedema/commander/blob/master/examples/silex/CommanderController.php)

### Vanilla php

[](#vanilla-php)

To use commander in another framework you can use this code:

```
use JildertMiedema\Commander\Manager;
use JildertMiedema\Commander\Vanilla\Executor;

$manager = new Manager();
$executor = new Executor($manager);

echo $executor->execute('TestCommand', null, ['TestSanitizer']);
```

> The vanilla php solution does not support out-of-the-box dependency injection, therefore you need to implement a translator and a resolver.

An example [vanilla.php](https://github.com/jildertmiedema/commander/blob/master/examples/vanilla.php)

### Creating your own translator and resolver

[](#creating-your-own-translator-and-resolver)

For integration with a another framework you can implement your own `translator` and `resolver`.

```
$translator = new YourOwnCommandTranslator; // Must implement `JildertMiedema\Commander\CommandTranslatorInterface`
$resolver =  new YourOwnResolver; // Must implement `JildertMiedema\Commander\ResolverInterface`
$defaultCommandBus = new DefaultCommandBus($translator, $resolver);
$commandBus = new ValidationCommandBus($defaultCommandBus, $translator, $resolver);
$manager = new Manager($commandBus);
```

### Examples

[](#examples)

Run the examples

```
cd YOUR_PACKAGE_DIR
cd examples
php -S localhost:8000
```

Visit:

```
http://localhost:8000/silex.php?test=test%20%20%20&extra=123
http://localhost:8000/silex.php/sanitizer?test=test%20%20%20&extra=123
http://localhost:8000/silex.php/controller?test=test%20%20%20&extra=123
http://localhost:8000/vanilla.php?test=test%20%20%20&extra=123

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

4296d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17d3aa5c306bcc4739b0953cdc617f1fd05c035f5aff96bef28971ae6603e128?d=identicon)[jildertmiedema](/maintainers/jildertmiedema)

---

Top Contributors

[![jildertmiedema](https://avatars.githubusercontent.com/u/3383186?v=4)](https://github.com/jildertmiedema "jildertmiedema (17 commits)")

---

Tags

command bussilexdomain-eventscommander

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jildertmiedema-commander/health.svg)

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

###  Alternatives

[league/tactician

A small, flexible command bus. Handy for building service layers.

86415.4M126](/packages/league-tactician)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M18](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26947.8M5](/packages/chi-teck-drupal-code-generator)[cilex/console-service-provider

Console Service Provider

273.1M3](/packages/cilex-console-service-provider)[grasmash/yaml-cli

A command line tool for reading and manipulating yaml files.

2523.6M10](/packages/grasmash-yaml-cli)

PHPackages © 2026

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