1. Go to this page and download the library: Download vshf/php-bus 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/ */
vshf / php-bus example snippets
$bus = new \VSHF\Bus\Bus();
$command = new MyCommand($someParamsIfAny);
$bus->dispatch($command);
$result = $bus->ask(new GetUserQuery($id));
public function getResultType(): string
{
return User::class;
}
$bus->addMiddleware(MyMiddleware::class);
class MyMiddleware implements \VSHF\Bus\MiddlewareInterface {
public function before() : void
{
// You can access:
// $this->$command or $this->query
// $this->agent_type
// $this->agent_id
$this->next(); // Omit this to stop command/query execution.
}
public function after() : void
{
// Runs after the handler.
//
// You can access:
// $this->$command or $this->query
// $this->agent_type
// $this->agent_id
}
}