Download the PHP package dualmedia/symfony-doctrine-event-converter-bundle without Composer
On this page you can find all versions of the php package dualmedia/symfony-doctrine-event-converter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dualmedia/symfony-doctrine-event-converter-bundle
More information about dualmedia/symfony-doctrine-event-converter-bundle
Files in dualmedia/symfony-doctrine-event-converter-bundle
Package symfony-doctrine-event-converter-bundle
Short Description A symfony bundle for creating symfony events out of doctrine changes
License MIT
Informations about the package symfony-doctrine-event-converter-bundle
Doctrine Event Dispatcher Bundle
This bundle is meant to convert between doctrine and symfony events seamlessly, as well as allow for creation of sub-events with their own requirements and checks
It allows you to streamline doctrine actions using symfony directly, without need of implementing doctrine's listeners and event logic.
All of the hard work is already done, just declare your entities, implement EntityInterface
on them, and create an abstract event class.
Installation
Simply composer require dualmedia/symfony-doctrine-event-converter-bundle
Then add the bundle to your config/bundles.php
file like so
Usage
Entity
Make a Doctrine-managed entity, that also implements the DualMedia\DoctrineEventDistributorBundle\Interfaces\EntityInterface
Event
Create an event class (not final), and then at some point extend DualMedia\DoctrineEventDistributorBundle\Event\AbstractEntityEvent
,
mark this class with your appropriate event annotation, either one of the base ones or SubEvent
The bundle will then automatically generate proxy classes for appropriate events.
Each proxy class starts with the proxy namespace visible here under the PROXY_NS
constant value.
The following class name will always contain the full namespace of the parent event. This namespace is loaded via the autoloader in the bundle and should not be interacted with in ways other than subscribers and general use.
SubEvent
Let's assume the following scenario: You wish to have an event fired when the status of the Item
changes from pending
to complete
,
in this case you'd add the following attribute on your ItemEvent
(above).
SubEvents can take form of checks which apply to the previous and current state of variable, or only one (from OR to).
Important
Because of how Doctrine passes changes unfortunately changes to collections are not known at this time.
From and To
The following will generate an ItemPendingToCompleteEvent
class (under the default proxy namespace).
Assuming of course the existence of an enum or other value which can be passed to the Change
model.
More than one change can be required at a time, or any change, depending on SubEvent::$allMode
.
From
The following will generate an ItemFromPendingEvent
.
To
The following will generate an ItemCompleteEvent
.
PHPStan and Psalm issue ignoring
Ready-to-use templates are available below to make your lives a bit easier.
Plugins may be provided at a later time, but it's not certain.
PHPStan
Note: in future a phpstan.neon file will be provided to ignore these issues, for the time being simply add the following lines into your file.
I also suggest disabling reportUnmatchedIgnoredErrors
in your config, but it's not strictly necessary.
Psalm
This configuration needs to be copied over as psalm does not allow including files.
All versions of symfony-doctrine-event-converter-bundle with dependencies
doctrine/doctrine-bundle Version ^1.12|^2.0
doctrine/orm Version ^2.14|^3
symfony/framework-bundle Version ^5.4|^6.2|^7
symfony/event-dispatcher Version ^5.4|^6.2|^7
symfony/property-access Version ^5.4|^6.2|^7
symfony/http-kernel Version ^5.4|^6.2|^7
doctrine/common Version ^2|^3