From 94bc27b6ba8281b1fe07943788c0b73f17d08d7a Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Mon, 15 Feb 2021 15:44:27 +0100 Subject: [PATCH] add event-subscriber to throw flushed workflow events --- .../Workflow/FlushedEventSubscriber.php | 72 +++++++++++++++++++ Resources/config/services.xml | 8 +++ Tests/Application/config/config.yml | 10 --- 3 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php diff --git a/Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php b/Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php new file mode 100644 index 00000000..833acaa9 --- /dev/null +++ b/Content/Infrastructure/Symfony/Workflow/FlushedEventSubscriber.php @@ -0,0 +1,72 @@ + 'onCompleted', + ]; + } + + /** + * @var EventDispatcherInterface + */ + private $eventDispatcher; + + /** + * @var mixed[] + */ + private $eventsToDispatch = []; + + public function __construct(EventDispatcherInterface $eventDispatcher) + { + $this->eventDispatcher = $eventDispatcher; + } + + public function onCompleted(Event $event): void + { + $eventName = sprintf('workflow.%s.flushed', WorkflowInterface::WORKFLOW_DEFAULT_NAME); + + $this->eventsToDispatch[] = [$event, $eventName]; + $this->eventsToDispatch[] = [$event, sprintf('%s.%s', $eventName, $event->getTransition()->getName())]; + } + + public function postFlush(): void + { + foreach ($this->eventsToDispatch as $item) { + $this->eventDispatcher->dispatch($item[0], $item[1]); + } + + $this->eventsToDispatch = []; + } + + public function onClear(): void + { + $this->eventsToDispatch = []; + } +} diff --git a/Resources/config/services.xml b/Resources/config/services.xml index fd41fa84..586880e1 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -166,5 +166,13 @@ + + + + + + + + diff --git a/Tests/Application/config/config.yml b/Tests/Application/config/config.yml index cad22d0f..58deced6 100644 --- a/Tests/Application/config/config.yml +++ b/Tests/Application/config/config.yml @@ -1,16 +1,6 @@ swiftmailer: disable_delivery: true -doctrine: - orm: - mappings: - gedmo_tree: - type: xml - prefix: Gedmo\Tree\Entity - dir: "%kernel.project_dir%/../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity" - alias: GedmoTree - is_bundle: false - #sulu_core: # content: # structure: