PHPackages                             neos/event-sourcing-symfony-bridge - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. neos/event-sourcing-symfony-bridge

ActiveSymfony-bundle[Framework](/categories/framework)

neos/event-sourcing-symfony-bridge
==================================

Symfony bridge to integrate Event Sourcing and CQRS pattern in your Symfony framework.

1.1.0(4y ago)45.0k[1 PRs](https://github.com/neos/Neos.EventSourcingSymfonyBridge/pulls)MITPHPPHP &gt;=7.2

Since Mar 31Pushed 2y ago2 watchersCompare

[ Source](https://github.com/neos/Neos.EventSourcingSymfonyBridge)[ Packagist](https://packagist.org/packages/neos/event-sourcing-symfony-bridge)[ Fund](https://shop.neos.io/neosfunding/)[ RSS](/packages/neos-event-sourcing-symfony-bridge/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (5)Used By (0)

Symfony bridge for Event Sourcing and CQRS
==========================================

[](#symfony-bridge-for-event-sourcing-and-cqrs)

Library providing interfaces and implementations for event-sourced applications for Symfony Applications.

This package is the symfony adapter of [Neos.EventSourcing](https://github.com/neos/Neos.EventSourcing) (which was created for the Neos/Flow framework).

### Demo

[](#demo)

Check out the Symfony Demo Repository:

Getting started
---------------

[](#getting-started)

In your symfony application, install this package and neos/event-sourcing via composer:

```
composer require neos/event-sourcing-symfony-bridge neos/event-sourcing
```

### Setting up a Doctrine Event Store

[](#setting-up-a-doctrine-event-store)

Since there could be multiple Event Stores simultaneously in one application, this package comes without a pre-configured "default" store. It is just a matter of a couple of lines of YAML to configure a custom store:

*config/packages/neos\_eventsourcing.yaml:*

```
neos_eventsourcing:
  stores:
    'blog.events':
      eventTableName: blog_events
    'user.events':
      eventTableName: user_events
```

Set the charset in the doctrine config to utf8mb4 by adding the following lines.

*config/packages/doctrine.yaml:*

```
doctrine:
    dbal:
        connections:
            default:
                url: '%env(resolve:DATABASE_URL)%'

                # IMPORTANT: You MUST configure your server version,
                # either here or in the DATABASE_URL env var (see .env file)
                server_version: '5.7'

                default_table_options:
                    charset: utf8mb4
                    collate: utf8mb4_unicode_ci
```

Add the following to bundles.php:

```
Neos\EventSourcing\SymfonyBridge\NeosEventSourcingBundle::class => ['all' => true],

```

To make use of the newly configured Event Store one more step is required in order to finish the setup (in this case to create the corresponding database table):

```
php bin/console eventsourcing:store-setup
```

### Writing events

[](#writing-events)

Example event: *BlogWasCreated.php*```
class BlogWasCreated implements DomainEventInterface
{
    /**
     * @var BlogIdentifier
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var UserIdentifier
     */
    private $author;

    public function __construct(
        BlogIdentifier $id,
        string $name,
        UserIdentifier $author
    )
    {
        $this->id = $id;
        $this->name = $name;
        $this->author = $author;
    }

    public function getId(): BlogIdentifier
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function getAuthor(): UserIdentifier
    {
        return $this->author;
    }
}
```

```
