PHP code example of malocher / zf2-cqrs-module

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

    

malocher / zf2-cqrs-module example snippets


  'cqrs' => array(
        'adapters' => array(
            'Malocher\Cqrs\Adapter\ArrayMapAdapter' => array(
                'buses' => array(
                    'My\Bus\DomainBus' => array(
                        'My\Command\AddEntityCommand' => array(
                            'alias'  => 'my_add_entity_command_handler',
                            'method' => 'addEntity' 
                        ),
                    ),
                ),
            ),
        ),
    ),
    'service_manager' => array(
        'invokables' => array(
            'my_add_entity_command_handler' => 'My\Repository\EntityRepository',
        ),
    ),


namespace My\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use My\Command\AddEntityCommand;
use My\Bus\DomainBus;

class MyController extends AbstractActionController {

  public function addEntityAction() {
  
    $entityName = $this->getEvent()->getRouteMatch()->getParam('entityname');
    
    $addEntityCommand = new AddEntityCommand();
    
    $addEntityCommand->setName($entityName);
    
    $this->getServiceLocator()
      ->get('malocher.cqrs.gate')
      ->getBus(DomainBus::NAME)
      ->invokeCommand($addEntityCommand);
  }
}