PHP code example of vherus / depot

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

    

vherus / depot example snippets


$bus = new Depot\Bus\NativeCommandBus(new Depot\Resolution\NativeNamespaceResolver);
$bus->dispatch(new My\Command);

namespace My;
    
class Command implements Depot\Command { }

namespace My\Handler;
    
class CommandHandler
{
    public function handle(My\Command $command) { }
}

$bus = new NativeCommandBus(new NativeMapResolver([
    My\Command::class => My\Command\Handler\CommandHandler::class
]));
$bus->dispatch(new My\Command);

class QueuedCommand extends Depot\Command {}

class QueuedCommandBus implements Depot\CommandBus
{
    private $innerBus;
    private $queue;

    public function __construct(Depot\CommandBus $innerBus, SomeQueueLibrary $queue)
    {
        $this->innerBus = $innerBus;
        $this->queue = $queue;
    }

    public function dispatch(Command $command)
    {
        if ($command instanceof QueuedCommand) {
            $this->queue->queue($command);
            return;
        }

        $this->innerBus->dispatch($command);
    }
}

$this->app->bind(Depot\Container::class, Depot\Container\Laravel\IlluminateContainer::class);
$this->app->bind(Depot\HandlerResolver::class, Depot\Resolution\NativeNamespaceResolver::class);
$this->app->bind(Depot\CommandBus::class, Depot\Bus\NativeCommandBus::class);