chgst / chgst-bundle
Symfony bundle for chgst
0.3.3
2023-10-21 16:26 UTC
Requires
- php: ^8.2
- chgst/chgst: ^0.3.3
- symfony/config: ~6
- symfony/security-bundle: ~6
Requires (Dev)
- friends-of-phpspec/phpspec-code-coverage: ^v6.3.0
- pdepend/pdepend: ^2.15
- php-coveralls/php-coveralls: ^v2.6.0
- phploc/phploc: ^7.0.2
- phpmd/phpmd: ^2.14.1
- phpspec/phpspec: ^7.4
- sebastian/phpcpd: ^6.0.3
- symfony/expression-language: ~v6.3.0
- symfony/templating: ~6
README
Before Install
Make sure you have Symfony Security installed:
composer require security
Installation
composer require chgst/chgst-bundle
Configuration
Set your event repository service for persisting events to data store
# config/packages/chgst.yaml chgst: enable_listeners: true # Make sure you disable listeners in test/dev environment when@dev: chgst: enable_listeners: false when@test: chgst: enable_listeners: false
Add repository service to your services configuration
# config/services.yaml services: Chgst\Event\RepositoryInterface: public: true class: Chgst\Event\ObjectRepository arguments: [ '@doctrine_mongodb.odm.document_manager', 'App\Document\DefaultEvent' ] # or '@doctrine.orm.entity_manager'
Create Doctrine model class for your events
<?php // src/Document/DefaultEvent.php namespace App\Document; use Chgst\Event\Event; class DefaultEvent extends Event { protected string $id; public function getId(): string { return $this->id; } public function setId(string $id): self { $this->id = $id; return $this; } }
And add XML mapping
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping https://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"> <document name="App\Document\DefaultEvent"> <id /> <field field-name="name" type="string" nullable="false" /> <field field-name="aggregateType" type="string" nullable="false" /> <field field-name="aggregateId" type="string" nullable="false" /> <field field-name="createdAt" type="date" nullable="false" /> <field field-name="createdBy" type="string" nullable="false" /> <field field-name="payload" type="hash" nullable="false" /> </document> </doctrine-mongo-mapping>