PHP code example of jildertmiedema / commander

1. Go to this page and download the library: Download jildertmiedema/commander library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jildertmiedema / commander example snippets


//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

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

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');
});

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

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

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

$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);
sh
cd YOUR_PACKAGE_DIR
cd examples
php -S localhost:8000

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