Skip to content

Commit

Permalink
Merge pull request #11 from Jeckel-Lab/feature/#10-flush-entity-on-ev…
Browse files Browse the repository at this point in the history
…ent-dispatch

Flush entity on event dispatch
  • Loading branch information
jeckel authored Mar 30, 2020
2 parents 37db221 + d77490e commit 5210eb5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ parameters:
triggered_by: ['php']
show_info: true

phpunit: null
# phpunit: null
50 changes: 50 additions & 0 deletions src/EventDispatcher/Decorator/EntityFlushDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @author: Julien Mercier-Rojas <[email protected]>
* Created at: 30/03/2020
*/

declare(strict_types=1);

namespace JeckelLab\CommandDispatcherBundle\EventDispatcher\Decorator;

use Doctrine\ORM\EntityManagerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;

/**
* Class EntityFlushDecorator
* @package JeckelLab\CommandDispatcherBundle\EventDispatcher\Decorator
*/
class EntityFlushDecorator implements EventDispatcherInterface
{
/** @var EventDispatcherInterface */
protected $next;

/** @var EntityManagerInterface */
protected $entityManager;

/**
* EntityFlushDecorator constructor.
* @param EventDispatcherInterface $next
* @param EntityManagerInterface $entityManager
*/
public function __construct(EventDispatcherInterface $next, EntityManagerInterface $entityManager)
{
$this->next = $next;
$this->entityManager = $entityManager;
}

/**
* @param object $event
* @return object
*/
public function dispatch(object $event): object
{
$response = $this->next->dispatch($event);

$this->entityManager->flush();

return $response;
}
}

0 comments on commit 5210eb5

Please sign in to comment.