PHP code example of itmedia / command-bus-bundle

1. Go to this page and download the library: Download itmedia/command-bus-bundle 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/ */

    

itmedia / command-bus-bundle example snippets


use Itmedia\CommandBusBundle\Command\Command;

class TestCommand implements Command
{
    //...

    public function commandName(): string
    {
        return 'test_command';
    }

}

    $command = new CommandTest();
    $this->get('app.command_bus')->handle($command);

use Itmedia\CommandBusBundle\Command\Command;
use Symfony\Component\Validator\Constraints as Assert;

class TestCommand implements Command
{

    /**
     * @NotBlank()
     */
    private string $username;

    /**
     * @NotBlank()
     * @Assert\Email()
     */
    private string $email;

    public function __construct(string $username, string $email)
    {
        $this->username = $username;
        $this->email = $email;
    }

    public function commandName(): string
    {
        return 'test_command';
    }

    public function getUsername(): string
    {
        return $this->username;
    }

    public function getEmail(): string
    {
        return $this->email;
    }

}

use Itmedia\CommandBusBundle\Command\Command;
use Itmedia\CommandBusBundle\Command\HandlePropertiesFormArrayTrait;

class TestCommand implements Command
{

    use HandlePropertiesFormArrayTrait;
    
    // ....
  
    public function __construct($id, array $data)
    {
        $this->handleProperties($data);
        $this->id = $id;
    }

}