Ejemplo n.º 1
0
 *
 * IF a Info event is received
 *   WITH payload.success being true
 * 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;
 * (c) Alexander Miertsch <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 * 
 * Date: 21.10.14 - 20:03
 */
/**
 * This example shows you the basic set up of the ProophEventStore Doctrine adapter and how you can use the adapter
 * to set up your database.
 */
chdir(__DIR__);
include '../vendor/autoload.php';
//Configure the connection
$connectionParams = ['dbname' => 'mydb', 'user' => 'user', 'password' => 'secret', 'host' => 'localhost', 'driver' => 'pdo_mysql'];
$esAdapter = new \Prooph\EventStore\Adapter\Doctrine\DoctrineEventStoreAdapter(['connection' => $connectionParams]);
//Pass adapter to event store via configuration
$esConfig = new Prooph\EventStore\Configuration\Configuration();
$esConfig->setAdapter($esAdapter);
$eventStore = new \Prooph\EventStore\EventStore($esConfig);
//When using the \Prooph\EventStore\Stream\SingleStreamStrategy
//you can use the following code snippet to create a database schema:
$eventStore->getAdapter()->createSchemaFor(new \Prooph\EventStore\Stream\StreamName('event_stream'), array('aggregate_id' => 'string', 'aggregate_type' => 'string'));
//When using the \Prooph\EventStore\Stream\AggregateTypeStreamStrategy
//you need to create a stream table for each aggregate root class
//The aggregate_type metadata is not required for this strategy
$eventStore->getAdapter()->createSchemaFor(new \Prooph\EventStore\Stream\StreamName('My\\Model\\AggregateRoot'), array('aggregate_id' => 'string'));
//The \Prooph\EventStore\Stream\AggregateStreamStrategy needs no existing tables. It creates a new table for
//each aggregate instance. This strategy is not the best choice when working with a RDBMS,
//cause it will end up in having a lot of tables.
//But it becomes really interesting when using NoSql databases.
Ejemplo n.º 3
0
/**
 * The event store provides access to a data store which is capable of persisting events in streams.
 * See ProophEventStore documentation for details.
 *
 * The workflow processor uses the event store to persist process events
 * so that logging is a first class citizen
 * in the workflow system.
 *
 * @return \Prooph\EventStore\EventStore
 */
function _set_up_event_store()
{
    $inMemoryAdapter = new \Prooph\EventStore\Adapter\InMemoryAdapter();
    $config = new \Prooph\EventStore\Configuration\Configuration();
    $config->setAdapter($inMemoryAdapter);
    $es = new \Prooph\EventStore\EventStore($config);
    //Attach an output logger which prints information about recorded events
    $es->getActionEventDispatcher()->attachListener("commit.post", function (\Prooph\EventStore\PersistenceEvent\PostCommitEvent $event) {
        foreach ($event->getRecordedEvents() as $recordedEvent) {
            echo sprintf("Event %s recorded with payload: \n\n%s\n\n", $recordedEvent->messageName(), json_encode($recordedEvent->payload()));
        }
    });
    return $es;
}
Ejemplo n.º 4
0
 * The event store has two dependencies:
 *
 * - Prooph\EventStore\Adapter\Adapter
 * - Prooph\Common\Event\ActionEventEmitter
 *
 * Here we use the InMemoryAdapter but in a real project
 * you need to set up one of the available
 * persistence adapters.
 *
 * Prooph\Common\Event\ActionEventEmitter is an interface
 * that encapsulates functionality of an event dispatcher.
 * You can use the one provided by prooph/common or
 * you write a wrapper for the event dispatcher used
 * by your web framework.
 */
$eventStore = new \Prooph\EventStore\EventStore(new \Prooph\EventStore\Adapter\InMemoryAdapter(), new \Prooph\Common\Event\ProophActionEventEmitter());
/**
 * We need a test event so let's create one.
 *
 * As a bare minimum events need to implement
 * Prooph\Common\Messaging\Message.
 *
 * Note: It is possible to use your own events
 * in your domain and use a translator to
 * convert them. We'll come to that later.
 */
$quickStartSucceeded = \Example\Event\QuickStartSucceeded::withSuccessMessage('It works');
/**
 * Use the event store to manage transactions.
 * It will delegate transaction handling to
 * the underlying adapter if the adapter supports