PHP code example of rtens / domin

1. Go to this page and download the library: Download rtens/domin 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/ */

    

rtens / domin example snippets


use rtens\domin\delivery\web\adapters\curir\root\IndexResource;
use rtens\domin\delivery\web\WebApplication;
use watoki\curir\WebDelivery;

WebDelivery::quickResponse(IndexResource::class,
    WebDelivery::init(null,
        WebApplication::init(function (WebApplication $app) {
            // Set-up $app here (e.g. $app->actions->add('foo', ...))
        })));

use rtens\domin\delivery\web\adapters\silex\SilexControllerProvider;
use rtens\domin\delivery\web\WebApplication;
use Silex\Application;

  // Set-up $app here (e.g. $app->actions->add('foo', ...))
    })));
$app->run();

use rtens\domin\delivery\cli\CliApplication;

CliApplication::run(CliApplication::init(function (CliApplication $app) {
    // Set-up $app here (e.g. $app->actions->add('foo', ...))
}));

class MyAction implements Action {

    public function caption() {
        return 'Some Action';
    }

    public function description() {
        return 'Some Description';
    }

    public function parameters() {
        return [
            new Parameter('foo', new StringType()),
            new Parameter('bar', new ClassType(\DateTime::class))
        ];
    }

    public function fill(array $parameters) {
        $parameters['foo'] = 'default value of foo';
        return $parameters;
    }

    public function execute(array $parameters) {
        return "Make it so! " . json_encode($parameters);
    }
}

$actionRegistry->add('my', new MyAction());

class MyAction extends ObjectAction {
    
    public function __construct($class, TypeFactory $types, CommandBus $bus) {
        parent::__construct($class, $types);
        $this->bus = $bus;
    }

    protected function executeWith($object) {
        $this->bus->handle($object);
    }
}

$actionRegistry->add('my', new MyAction(MyCommand::class, $types, $bus));
$actionRegistry->add('your', new MyAction(YourCommand::class, $types, $bus));
$actionRegistry->add('their', new MyAction(TheirCommand::class, $types, $bus));

(new ObjectActionGenerator($actionRegistry, $typeFactory))->fromFolder('model/commands', function ($object) {
    $bus->handle($object);
});

$actionRegistry->add('my', new MethodAction($handler, 'handleMyCommand', $typeFactory));
$actionRegistry->add('your', new MethodAction($handler, 'handleYourCommand', $typeFactory));
$actionRegistry->add('their', new MethodAction($handler, 'handleTheirCommand', $typeFactory));

(new MethodActionGenerator($actionRegistry, $typeFactory))->fromObject($handler);