PHP code example of prooph / laravel-package

1. Go to this page and download the library: Download prooph/laravel-package 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/ */

    

prooph / laravel-package example snippets


class CreateEventStreamTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        \Prooph\Package\Migration\Schema\EventStoreSchema::createSingleStream('event_stream', true);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        \Prooph\Package\Migration\Schema\EventStoreSchema::dropStream('event_stream');
    }
}

class CreateSnapshotTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        \Prooph\Package\Migration\Schema\SnapshotSchema::create('snapshot');
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        \Prooph\Package\Migration\Schema\SnapshotSchema::drop('snapshot');
    }
}

// add the following config in your config/prooph.php under the specific config key
return [
    'event_store' => [
        // list of aggregate repositories
        'user_collection' => [
            'repository_class' => \Prooph\ProophessorDo\Infrastructure\Repository\EventStoreUserCollection::class,
            'aggregate_type' => \Prooph\ProophessorDo\Model\User\User::class,
            'aggregate_translator' => \Prooph\EventSourcing\EventStoreIntegration\AggregateTranslator::class,
            'snapshot_store' => \Prooph\EventStore\Snapshot\SnapshotStore::class,
        ],
    ],
    'service_bus' => [
        'command_bus' => [
            'router' => [
                'routes' => [
                    // list of commands with corresponding command handler
                    \Prooph\ProophessorDo\Model\User\Command\RegisterUser::class => \Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler::class,
                ],
            ],
        ],
        'event_bus' => [
            'router' => [
                'routes' => [
                    // list of events with a list of projectors
                    \Prooph\ProophessorDo\Model\User\Event\UserWasRegistered::class => [
                        \Prooph\ProophessorDo\Projection\User\UserProjector::class
                    ],
                ],
            ],
        ],
    ],
];

// add the following config in your config/dependencies.php after the other factories
return [
    // your factories
    // Model
    \Prooph\ProophessorDo\Model\User\Handler\RegisterUserHandler::class => \Prooph\ProophessorDo\Container\Model\User\RegisterUserHandlerFactory::class,
    \Prooph\ProophessorDo\Model\User\UserCollection::class => \Prooph\ProophessorDo\Container\Infrastructure\Repository\EventStoreUserCollectionFactory::class,
    // Projections
    \Prooph\ProophessorDo\Projection\User\UserProjector::class => \Prooph\ProophessorDo\Container\Projection\User\UserProjectorFactory::class,
    \Prooph\ProophessorDo\Projection\User\UserFinder::class => \Prooph\ProophessorDo\Container\Projection\User\UserFinderFactory::class,
];

    /* @var $container \Illuminate\Container\Container */
    
    /* @var $commandBus \Prooph\ServiceBus\CommandBus */
    $commandBus = $container->make(Prooph\ServiceBus\CommandBus::class);

    $command = new \Prooph\ProophessorDo\Model\User\Command\RegisterUser(
        [
            'user_id' => \Rhumsaa\Uuid\Uuid::uuid4()->toString(),
            'name' => 'prooph',
            'email' => '[email protected]',
        ]
    );

    $commandBus->dispatch($command);

    /* @var $container \Illuminate\Container\Container */
    $userFinder = $container->make(Prooph\ProophessorDo\Projection\User\UserFinder::class);

    $users = $userFinder->findAll();
bash 
$ php artisan vendor:publish
bash
$ php artisan make:migration create_event_stream_table
bash
$ php artisan make:migration create_snapshot_table
bash
$ php artisan migrate