PHP code example of cocoders / event-store

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

    

cocoders / event-store example snippets


    $eventStore = new MyEventStore();
    $invoice = Invoice::issueInvoice(
        Invoice\Id::generate();
        $command->getSeller(),
        $command->getBuyer(),
        $command->maxItemNumber
    );
    $eventStore->apply(new EventStream\Name(Invoice::class), $invoice->getRecordedEvents());
    $eventStore->commit();

  $eventStore = new MyEventStore(); 
  $eventSubscribers = new EventSubscribers();
  $eventBus = new EventBus($eventSubscribers);
  $projectionManager = new ProjectionManager($eventSubscribers);
  $projectionManager->registerProjection(
      'InvoiceIssued',
      new MyProjection()
  );
  $newEventsStream = $eventStore->findUncommited(new EventStream\Name(Invoice::class));
  $eventStore->commit();
  $eventStore->notify($newEventsStream); //now event bus will notify projections as well
bash
composer install
php bin/phpspec run -fpretty
php bin/phpunit