|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Pim\Bundle\CustomEntityBundle\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Pim\Bundle\CustomEntityBundle\Action\ActionInterface; |
|
6
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
8
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Event manager for actions |
|
12
|
|
|
* |
|
13
|
|
|
* @author Antoine Guigan <[email protected]> |
|
14
|
|
|
* @copyright 2013 Akeneo SAS (http://www.akeneo.com) |
|
15
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
16
|
|
|
*/ |
|
17
|
|
|
class ActionEventManager |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var EventDispatcherInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $eventDispatcher; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Constructor |
|
26
|
|
|
* |
|
27
|
|
|
* @param EventDispatcherInterface $eventDispatcher |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(EventDispatcherInterface $eventDispatcher) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Dispatches the ActionEvents::CONFIGURE event |
|
36
|
|
|
* |
|
37
|
|
|
* @param ActionInterface $action |
|
38
|
|
|
* @param OptionsResolver $optionsResolver |
|
39
|
|
|
*/ |
|
40
|
|
|
public function dipatchConfigureEvent(ActionInterface $action, OptionsResolver $optionsResolver) |
|
41
|
|
|
{ |
|
42
|
|
|
$event = new ConfigureActionEvent($action, $optionsResolver); |
|
43
|
|
|
$this->eventDispatcher->dispatch(ActionEvents::CONFIGURE, $event); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Dispatches the ActionEvents::PRE_EXECUTE event |
|
48
|
|
|
* |
|
49
|
|
|
* @param ActionInterface $action |
|
50
|
|
|
*/ |
|
51
|
|
|
public function dispatchPreExecuteEvent(ActionInterface $action) |
|
52
|
|
|
{ |
|
53
|
|
|
$event = new ActionEvent($action); |
|
54
|
|
|
$this->eventDispatcher->dispatch(ActionEvents::PRE_EXECUTE, $event); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Dispatches the ActionEvents::POST_EXECUTE event, and returns the modified response |
|
59
|
|
|
* |
|
60
|
|
|
* @param ActionInterface $action |
|
61
|
|
|
* @param Response $response |
|
62
|
|
|
* |
|
63
|
|
|
* @return Response |
|
64
|
|
|
*/ |
|
65
|
|
|
public function dispatchPostExecuteEvent(ActionInterface $action, Response $response) |
|
66
|
|
|
{ |
|
67
|
|
|
$event = new PostExecuteActionEvent($action, $response); |
|
68
|
|
|
$this->eventDispatcher->dispatch(ActionEvents::POST_EXECUTE, $event); |
|
69
|
|
|
|
|
70
|
|
|
return $event->getResponse(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Dispatches the ActionEvents::PRE_RENDER event, and returns an array containing the template ant its parameters |
|
75
|
|
|
* |
|
76
|
|
|
* @param ActionInterface $action |
|
77
|
|
|
* @param string $template |
|
78
|
|
|
* @param array $templateVars |
|
79
|
|
|
* |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
public function dispatchPreRenderEvent(ActionInterface $action, $template, array $templateVars) |
|
83
|
|
|
{ |
|
84
|
|
|
$event = new PreRenderActionEvent($action, $template, $templateVars); |
|
85
|
|
|
$this->eventDispatcher->dispatch(ActionEvents::PRE_RENDER, $event); |
|
86
|
|
|
|
|
87
|
|
|
return [$event->getTemplate(), $event->getTemplateVars()]; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|