PHP code example of austinhyde / minibus

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

    

austinhyde / minibus example snippets


$bus = new Minibus\Bus;

$bus->addHandler(function(NewUserCommand $cmd) use ($db, $bus) {
  $row = $db->query("INSERT INTO users (username, email) VALUES (?, ?) RETURNING *",
    [$cmd->username, $cmd->email]);
  $user = User::fromRow($row);
  $bus->publish(new UserAddedEvent($user));
  return $user;
});

$bus->addListener(function(UserAddedEvent $event) use ($log) {
  $log->info("Added user: " . $event->getUser()->getUsername());
});

$router->get(function($req, $res) use ($bus) {
  $cmd = new NewUserCommand($req->body->username, $req->body->email);
  $user = $bus->dispatch($cmd);
  return $user->toJson();
});