|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* @copyright 2013 - 2016 Cross Solution <http://cross-solution.de> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** */ |
|
11
|
|
|
namespace Core\EventManager; |
|
12
|
|
|
|
|
13
|
|
|
use Zend\EventManager\Event; |
|
14
|
|
|
use Zend\EventManager\EventInterface; |
|
15
|
|
|
use Zend\EventManager\EventManager as ZfEventManager; |
|
16
|
|
|
use Zend\EventManager\Exception; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* EventPrototype Aware EventManager implementation. |
|
20
|
|
|
* |
|
21
|
|
|
* @internal |
|
22
|
|
|
* Will be obsolete with ZF3 as ZF3s' EventManager implementation is |
|
23
|
|
|
* already event prototype aware. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
26
|
|
|
* @since 0.25 |
|
27
|
|
|
*/ |
|
28
|
|
|
class EventManager extends ZfEventManager implements EventProviderInterface |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The event prototype. |
|
33
|
|
|
* |
|
34
|
|
|
* @var EventInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $eventPrototype; |
|
37
|
|
|
|
|
38
|
|
|
public function setEventPrototype(EventInterface $event) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->eventPrototype = $event; |
|
41
|
|
|
$this->setEventClass(get_class($event)); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getEvent($name = null, $target = null, $params = null) |
|
47
|
|
|
{ |
|
48
|
|
|
if (!$this->eventPrototype) { |
|
49
|
|
|
$this->setEventPrototype(new Event()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$event = clone $this->eventPrototype; |
|
53
|
|
|
|
|
54
|
|
|
if (is_array($name)) { |
|
55
|
|
|
$params = $name; |
|
56
|
|
|
$name = null; |
|
57
|
|
|
|
|
58
|
|
|
} else if (is_array($target)) { |
|
59
|
|
|
$params = $target; |
|
60
|
|
|
$target = null; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
View Code Duplication |
if (!$name && isset($params['name'])) { |
|
|
|
|
|
|
64
|
|
|
$name = $params['name']; |
|
65
|
|
|
unset($params['name']); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
if (!$target && isset($params['target'])) { |
|
|
|
|
|
|
69
|
|
|
$target = $params['target']; |
|
70
|
|
|
unset($params['target']); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$event->setName($name); |
|
74
|
|
|
if (null !== $target) { $event->setTarget($target); } |
|
75
|
|
|
if (null !== $params) { $event->setParams($params); } |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
return $event; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function trigger($event, $target = null, $argv = [], $callback = null) |
|
81
|
|
|
{ |
|
82
|
|
|
if (!$event instanceOf EventInterface |
|
83
|
|
|
&& !$target instanceOf EventInterface |
|
84
|
|
|
&& !$argv instanceOf EventInterface |
|
85
|
|
|
) { |
|
86
|
|
|
/* |
|
87
|
|
|
* Create the event from the prototype, and not |
|
88
|
|
|
* from eventClass as the parent implementation does. |
|
89
|
|
|
*/ |
|
90
|
|
|
$e = $this->getEvent($event, $target, $argv); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
return parent::trigger($e, $callback); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return parent::trigger($event, $target, $argv, $callback); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
} |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.