1 | <?php |
||
13 | final class PlainMessage implements Message, \ArrayAccess |
||
14 | { |
||
15 | private $name; |
||
16 | private $arguments; |
||
17 | |||
18 | /** |
||
19 | * @param string $name |
||
20 | * @param array $arguments |
||
21 | 41 | */ |
|
22 | public function __construct($name, array $arguments = []) |
||
23 | 41 | { |
|
24 | 41 | $this->name = $name; |
|
25 | 41 | $this->arguments = $arguments; |
|
26 | } |
||
27 | |||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | public function getName() |
||
32 | { |
||
33 | return $this->name; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return array |
||
38 | */ |
||
39 | public function all() |
||
40 | { |
||
41 | return $this->arguments; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Returns the argument if found or null. |
||
46 | * |
||
47 | * @param string $name |
||
48 | * |
||
49 | * @return mixed |
||
50 | */ |
||
51 | public function get($name) |
||
52 | { |
||
53 | return $this->has($name) ? $this->arguments[$name] : null; |
||
54 | } |
||
55 | 1 | ||
56 | /** |
||
57 | 1 | * Checks whether the arguments contain the given key. |
|
58 | * |
||
59 | * @param string $name |
||
60 | 1 | * |
|
61 | * @return bool |
||
62 | 1 | */ |
|
63 | public function has($name) |
||
64 | { |
||
65 | return array_key_exists($name, $this->arguments); |
||
66 | } |
||
67 | |||
68 | public function offsetGet($offset) |
||
69 | { |
||
70 | return $this->get($offset); |
||
71 | } |
||
72 | |||
73 | public function offsetExists($offset) |
||
74 | { |
||
75 | return $this->has($offset); |
||
76 | } |
||
77 | |||
78 | 33 | public function offsetSet($offset, $value) |
|
82 | |||
83 | public function offsetUnset($offset) |
||
84 | { |
||
85 | throw new \LogicException('Message is immutable'); |
||
86 | } |
||
87 | |||
88 | public function __get($property) |
||
89 | { |
||
90 | return $this->get($property); |
||
92 | |||
93 | public function __isset($property) |
||
97 | |||
98 | public function __set($property, $value) |
||
102 | |||
103 | public function __unset($property) |
||
107 | } |
||
108 |