PHP code example of event-engine / prooph-v7-event-store
1. Go to this page and download the library: Download event-engine/prooph-v7-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/ */
event-engine / prooph-v7-event-store example snippets
//Basic set up that's able to handle Prooph\Common\Messaging\DomainEvent
$filesystemEventStore = new \EventEngine\Prooph\V7\EventStore\FilesystemEventStore(
'data/prooph.event_store.json',
\JSON_PRETTY_PRINT
// optional MessageFactory -> defaults to FQCNMessageFactory
// optional MessageConverter -> defaults to NoOpMessageConverter
);
//Create an empty stream
$filesystemEventStore->create(
new \Prooph\EventStore\Stream(
new \Prooph\EventStore\StreamName('event_stream'),
new ArrayIterator()
)
);
//Can also be used together with an InMemoryProjectionManager
$projectionManager = new \EventEngine\Prooph\V7\EventStore\Projecting\InMemory\InMemoryProjectionManager(
$filesystemEventStore,
new \EventEngine\Persistence\InMemoryConnection()
);
$query = $projectionManager->createQuery();
$query->fromStream('event_stream')
->whenAny(function (array $state, \Prooph\Common\Messaging\DomainEvent $event) {
echo "{$event->messageName()} stored in event_stream\n";
});
$query->run();