Пример #1
0
 * THEN send a ConvertJsonToCSV  command
 *   WITH payload.input_file set to "{received_message.payload.context.to_file_path}"
 *   AND payload.output_file set to "{replace('.json', '.csv', received_message.payload.context.to_file_path)}"
 * IF a Info event is received again
 *   WITH payload.context.success being true
 * THEN mark the chapter as done
 *
 * THE END
 */
//Init autoloading
require_once __DIR__ . '/../vendor/autoload.php';
//Set up prooph event store which will log the story events
$eventStore = new \Prooph\EventStore\EventStore(new \Prooph\EventStore\Adapter\InMemoryAdapter(), new \Prooph\Common\Event\ProophActionEventEmitter());
$eventStore->beginTransaction();
//As we use the InMemoryAdapter for prooph/event-store we have to create the story stream each time we run the sample
$eventStore->create(new \Prooph\EventStore\Stream\Stream(new \Prooph\EventStore\Stream\StreamName('prooph_story_stream'), new ArrayIterator([])));
$eventStore->commit();
//Add a simple console output logger to see logged story events
$eventStore->getActionEventEmitter()->attachListener('commit.post', function (\Prooph\Common\Event\ActionEvent $event) {
    $recordedEvents = $event->getParam('recordedEvents', []);
    foreach ($recordedEvents as $recordedEvent) {
        if ($recordedEvent instanceof \Prooph\Done\Story\Event\StoryWasStarted) {
            echo sprintf("%s started. StoryId: %s\n", $recordedEvent->storyName()->toString(), $recordedEvent->storyId()->toString());
            continue;
        }
        if ($recordedEvent instanceof \Prooph\Done\Story\Event\StoryWasDone) {
            echo sprintf("%s DONE!. StoryId: %s\n", $recordedEvent->storyName()->toString(), $recordedEvent->storyId()->toString());
            continue;
        }
        if ($recordedEvent instanceof \Prooph\Done\Story\Event\ChapterWasStarted) {
            echo sprintf("%s started. Chapter Number: %s\n", $recordedEvent->chapterStatus()->chapterName()->toString(), $recordedEvent->chapterStatus()->chapterNumber()->number());
$eventStore->beginTransaction();
/**
 * Events are organized in so called event streams.
 * An event stream is a logical unit for a group of events.
 */
$streamName = new \Prooph\EventStore\Stream\StreamName('event_stream');
$singleStream = new \Prooph\EventStore\Stream\Stream($streamName, []);
/**
 * As we are using the InMemoryAdapter we have to create the event stream
 * each time running the quick start. With a real persistence adapter this
 * is not required. In this case you should create the stream once. For example
 * with the help of a migration script.
 *
 * Note: For more details see the docs of the adapter you want to use.
 */
$eventStore->create($singleStream);
/**
 * Now we can easily add events to the stream ...
 */
$eventStore->appendTo($streamName, [$quickStartSucceeded]);
/**
 * Next step would be to commit the transaction.
 * But let's attach a plugin first that prints some information about currently added events.
 * Plugins are simple event listeners. See the docs of prooph/common for more details about event listeners.
 */
$eventStore->getActionEventEmitter()->attachListener('commit.post', function (\Prooph\Common\Event\ActionEvent $actionEvent) {
    /**
     * In the *commit.post* action event a plugin has access to
     * all recorded events which were added in the current committed transaction.
     * It is the ideal place to attach a domain event dispatcher.
     * We only use a closure here to print the recorded events in the terminal