Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Prooph Event Store Doctrine Adapter Bundle Laravel Package

david2m/prooph-event-store-doctrine-adapter-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle

    composer require david2m/prooph-event-store-doctrine-adapter-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        David2M\ProophEventStoreDoctrineAdapterBundle\ProophEventStoreDoctrineAdapterBundle::class => ['all' => true],
    ];
    
  2. Configure Doctrine & Event Store Update config/packages/prooph_event_store.yaml (if missing, create it):

    prooph_event_store:
        event_store:
            doctrine_event_store:
                connection: default
                event_class: 'Prooph\EventStore\Aggregate\AggregateChanged'
                metadata_class: 'Prooph\EventStore\Aggregate\AggregateMetadata'
                repository_class: 'Prooph\EventStore\Aggregate\AggregateRepository'
                stream_name_prefix: 'prooph_'
    
  3. First Use Case: Publishing an Event

    use Prooph\EventStore\EventStore;
    use Prooph\EventStore\Aggregate\AggregateChanged;
    
    // Inject EventStore via Symfony's DI container
    $eventStore = $this->container->get(EventStore::class);
    
    // Publish an event
    $event = new AggregateChanged(
        'user-created',
        ['user_id' => '123', 'name' => 'John Doe'],
        new \DateTimeImmutable()
    );
    
    $eventStore->dispatch($event);
    

Implementation Patterns

Workflows

  1. Aggregate Root Management Use AggregateRepository to load and persist aggregates:

    $repository = $this->container->get('prooph_event_store.aggregate_repository');
    $aggregate = $repository->getAggregateRoot('user-123');
    $aggregate->recordThat(new UserRegistered('John Doe'));
    $repository->saveAggregateRoot($aggregate);
    
  2. Event Sourcing with Doctrine Query events via Doctrine’s EntityManager:

    $events = $entityManager->getRepository(AggregateChanged::class)
        ->findBy(['stream_name' => 'user-123']);
    
  3. Symfony Command Integration Process events in background jobs:

    use Symfony\Component\Console\Command\Command;
    use Prooph\EventStore\EventStore;
    
    class ProcessEventsCommand extends Command {
        protected static $defaultName = 'app:process-events';
    
        public function __construct(private EventStore $eventStore) {}
    
        protected function execute(InputInterface $input, OutputInterface $output): int {
            $this->eventStore->dispatch(new EventToProcess());
            return Command::SUCCESS;
        }
    }
    

Integration Tips

  • Doctrine Migrations: Use make:migration to create tables for aggregate_changed and aggregate_metadata.
  • Event Subscribers: Register Prooph event listeners in config/services.yaml:
    services:
        App\EventListener\MyEventListener:
            tags:
                - { name: 'prooph_event_store.event_listener' }
    
  • CQRS Pattern: Combine with prooph/service-bus for command/query separation.

Gotchas and Tips

Pitfalls

  1. Stream Naming Collisions Ensure stream_name_prefix in config is unique to avoid conflicts with other bundles.

  2. Doctrine Connection Issues Verify connection: default in config matches your Doctrine setup. Use connection: custom if needed.

  3. Event Serialization Custom event classes must implement JsonSerializable or use Prooph’s SerializableAggregateRoot.

Debugging

  • Event Not Persisted? Check Doctrine’s event_store.aggregate_changed table for records. Enable Prooph’s debug mode:

    prooph_event_store:
        debug: true
    
  • Metadata Missing? Ensure metadata_class in config matches AggregateMetadata (default: Prooph\EventStore\Aggregate\AggregateMetadata).

Extension Points

  1. Custom Event Store Override the default DoctrineEventStore by binding a custom implementation in services.yaml:

    services:
        Prooph\EventStore\EventStore: '@my_custom_event_store'
    
  2. Event Store Middleware Add middleware to the event store pipeline:

    $eventStore->addMiddleware(new MyCustomMiddleware());
    
  3. Doctrine Event Listeners Extend Prooph’s event listeners for custom logic:

    class CustomEventListener implements EventListener {
        public function __invoke(Recorded $recorded): void {
            // Custom logic here
        }
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle