Feature #48409
Introduce new Annotation "Slot" for wiring signal and slots
Status: | New | Start date: | 2013-05-21 | |
---|---|---|---|---|
Priority: | Could have | Due date: | ||
Assigned To: | - | % Done: | 0% |
|
Category: | SignalSlot | |||
Target version: | - | |||
PHP Version: | Complexity: | |||
Has patch: | No |
Description
With this, the manual wiring in the Package.php could be left out so instead of doing this:
$dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher->connect( 'Some\Package\Controller\CommentController', 'commentCreated', //signal 'Some\Package\Service\Notification', 'sendNewCommentNotification' // slot );
one could easily add the Slot configuration to the respective function in the Class:
/** * @Flow\Slot('Some\Package\Controller\CommentController', 'commentCreated') * @param Comment $comment * @return void */ public function sendNewCommentNotification(Comment $comment) { ...
Future implementations could even allow Pointcut Expressions for e. g. Domain Events @Flow\Slot("class(Some\Package\Domain\Event\SomeEvent)")
Christian Müller however pointed out that this idea has been dropped in the past for a reason he couldn't remember.
So if anyone knows why this is a bad idea, let me know. If nothing speaks against implementing this: This is more of a "Flow-like" API imho.
History
#1 Updated by Henrik Møller Rasmussen about 2 years ago
Just a small note regarding the domain event part. To have proper support for domain events, it needs to be ensured that the signal is only triggered after the database transaction is committed successful.
Fx. a signal that sends an OrderCompleted email should not be triggered if the transaction saving the order does not complete.
#2 Updated by Philipp Maier about 2 years ago
Good point, which means that before sending out an Event a persistenceManager->persistAll should be called. Only works if the identity is generated early though, as there is no way to 'refresh' a loaded Entity yet.
Not related to the Annotation though, if I get this right. Might need to open a new issue concerning implementation of Domain Events.