Skip to content

Commit 5210eb5

Browse files
authored
Merge pull request #11 from Jeckel-Lab/feature/#10-flush-entity-on-event-dispatch
Flush entity on event dispatch
2 parents 37db221 + d77490e commit 5210eb5

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

grumphp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ parameters:
1616
triggered_by: ['php']
1717
show_info: true
1818

19-
phpunit: null
19+
# phpunit: null
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* @author: Julien Mercier-Rojas <julien@jeckel-lab.fr>
5+
* Created at: 30/03/2020
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace JeckelLab\CommandDispatcherBundle\EventDispatcher\Decorator;
11+
12+
use Doctrine\ORM\EntityManagerInterface;
13+
use Psr\EventDispatcher\EventDispatcherInterface;
14+
15+
/**
16+
* Class EntityFlushDecorator
17+
* @package JeckelLab\CommandDispatcherBundle\EventDispatcher\Decorator
18+
*/
19+
class EntityFlushDecorator implements EventDispatcherInterface
20+
{
21+
/** @var EventDispatcherInterface */
22+
protected $next;
23+
24+
/** @var EntityManagerInterface */
25+
protected $entityManager;
26+
27+
/**
28+
* EntityFlushDecorator constructor.
29+
* @param EventDispatcherInterface $next
30+
* @param EntityManagerInterface $entityManager
31+
*/
32+
public function __construct(EventDispatcherInterface $next, EntityManagerInterface $entityManager)
33+
{
34+
$this->next = $next;
35+
$this->entityManager = $entityManager;
36+
}
37+
38+
/**
39+
* @param object $event
40+
* @return object
41+
*/
42+
public function dispatch(object $event): object
43+
{
44+
$response = $this->next->dispatch($event);
45+
46+
$this->entityManager->flush();
47+
48+
return $response;
49+
}
50+
}

0 commit comments

Comments
 (0)