1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Metabor\Event; |
4
|
|
|
|
5
|
|
|
use Metabor\KeyValue\Nullable; |
6
|
|
|
use Metabor\Observer\Subject; |
7
|
|
|
use Metabor\Statemachine\Util\ArrayAccessToArrayConverter; |
8
|
|
|
use MetaborStd\Event\EventInterface; |
9
|
|
|
use MetaborStd\MetadataInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Oliver Tischlinger |
13
|
|
|
*/ |
14
|
|
|
class Event extends Subject implements EventInterface, \ArrayAccess, MetadataInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $name; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $invokeArgs = array(); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \ArrayAccess |
28
|
|
|
*/ |
29
|
|
|
private $metadata; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $name |
33
|
|
|
*/ |
34
|
19 |
|
public function __construct($name) |
35
|
|
|
{ |
36
|
19 |
|
parent::__construct(); |
37
|
19 |
|
$this->name = $name; |
38
|
19 |
|
$this->metadata = new Nullable(); |
39
|
19 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @see MetaborStd\Event.EventInterface::getInvokeArgs() |
43
|
|
|
*/ |
44
|
2 |
|
public function getInvokeArgs() |
45
|
|
|
{ |
46
|
2 |
|
return $this->invokeArgs; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @see \MetaborStd\CallbackInterface::__invoke() |
51
|
|
|
*/ |
52
|
7 |
|
public function __invoke() |
53
|
|
|
{ |
54
|
7 |
|
$this->invokeArgs = func_get_args(); |
55
|
7 |
|
$this->notify(); |
56
|
5 |
|
$this->invokeArgs = array(); |
57
|
5 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @see \MetaborStd\NamedInterface::getName() |
61
|
|
|
*/ |
62
|
14 |
|
public function getName() |
63
|
|
|
{ |
64
|
14 |
|
return $this->name; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @see \ArrayAccess::offsetExists() |
69
|
|
|
*/ |
70
|
2 |
|
public function offsetExists($offset) |
71
|
|
|
{ |
72
|
2 |
|
return $this->metadata->offsetExists($offset); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @see \ArrayAccess::offsetGet() |
77
|
|
|
*/ |
78
|
2 |
|
public function offsetGet($offset) |
79
|
|
|
{ |
80
|
2 |
|
return $this->metadata->offsetGet($offset); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @see \ArrayAccess::offsetSet() |
85
|
|
|
*/ |
86
|
4 |
|
public function offsetSet($offset, $value) |
87
|
|
|
{ |
88
|
4 |
|
$this->metadata->offsetSet($offset, $value); |
89
|
4 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @see \ArrayAccess::offsetUnset() |
93
|
|
|
*/ |
94
|
1 |
|
public function offsetUnset($offset) |
95
|
|
|
{ |
96
|
1 |
|
$this->metadata->offsetUnset($offset); |
97
|
1 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @see \MetaborStd\MetadataInterface::getMetadata() |
101
|
|
|
*/ |
102
|
4 |
|
public function getMetadata() |
103
|
|
|
{ |
104
|
4 |
|
$converter = new ArrayAccessToArrayConverter($this->metadata); |
105
|
|
|
|
106
|
4 |
|
return $converter->toArray(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|