PHP code example of nuvolapl / cqrs

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

    

nuvolapl / cqrs example snippets


class AccountController
{
    /**
     * @var SystemInterface
     */
    private $system;

    public function __construct(SystemInterface $system)
    {
        $this->system = $system;
    }

    public function post(array $payload): void
    {
        $command = new CreateAccountCommand(
            $payload['name'],
            $payload['confirmed'],
            new \DateTimeImmutable()
        );

        $this->system->command($command);
    }

    public function get(int $id): Account
    {
        return $this->system->query(
            new GetAccountByIdQuery($id)
        );
    }

    /**
     * {@inheritdoc}
     *
     * @return Account[]
     */
    public function getCollection(array $query): array
    {
        $collection = $this->system->query(
            new GetAccountCollectionQuery(
                $query['limit'],
                $query['offset']
            )
        );

        return \iterator_to_array($collection);
    }
}