Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Event.php
001 <?php
002 /**
003 * Zend Framework (http://framework.zend.com/)
004 *
005 * @link http://github.com/zendframework/zend-eventmanager for the canonical source repository
006 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
007 * @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
008 */
009
010 namespace Zend\EventManager;
011
012 use ArrayAccess;
013
014 /**
015 * Representation of an event
016 *
017 * Encapsulates the target context and parameters passed, and provides some
018 * behavior for interacting with the event manager.
019 */
020 class Event implements EventInterface
021 {
022 /**
023 * @var string Event name
024 */
025 protected $name;
026
027 /**
028 * @var string|object The event target
029 */
030 protected $target;
031
032 /**
033 * @var array|ArrayAccess|object The event parameters
034 */
035 protected $params = [];
036
037 /**
038 * @var bool Whether or not to stop propagation
039 */
040 protected $stopPropagation = false;
041
042 /**
043 * Constructor
044 *
045 * Accept a target and its parameters.
046 *
047 * @param string $name Event name
048 * @param string|object $target
049 * @param array|ArrayAccess $params
050 */
051 public function __construct($name = null, $target = null, $params = null)
052 {
053 if (null !== $name) {
054 $this->setName($name);
055 }
056
057 if (null !== $target) {
058 $this->setTarget($target);
059 }
060
061 if (null !== $params) {
062 $this->setParams($params);
063 }
064 }
065
066 /**
067 * Get event name
068 *
069 * @return string
070 */
071 public function getName()
072 {
073 return $this->name;
074 }
075
076 /**
077 * Get the event target
078 *
079 * This may be either an object, or the name of a static method.
080 *
081 * @return string|object
082 */
083 public function getTarget()
084 {
085 return $this->target;
086 }
087
088 /**
089 * Set parameters
090 *
091 * Overwrites parameters
092 *
093 * @param array|ArrayAccess|object $params
094 * @throws Exception\InvalidArgumentException
095 */
096 public function setParams($params)
097 {
098 if (! is_array($params) && ! is_object($params)) {
099 throw new Exception\InvalidArgumentException(
100 sprintf('Event parameters must be an array or object; received "%s"', gettype($params))
101 );
102 }
103
104 $this->params = $params;
105 }
106
107 /**
108 * Get all parameters
109 *
110 * @return array|object|ArrayAccess
111 */
112 public function getParams()
113 {
114 return $this->params;
115 }
116
117 /**
118 * Get an individual parameter
119 *
120 * If the parameter does not exist, the $default value will be returned.
121 *
122 * @param string|int $name
123 * @param mixed $default
124 * @return mixed
125 */
126 public function getParam($name, $default = null)
127 {
128 // Check in params that are arrays or implement array access
129 if (is_array($this->params) || $this->params instanceof ArrayAccess) {
130 if (! isset($this->params[$name])) {
131 return $default;
132 }
133
134 return $this->params[$name];
135 }
136
137 // Check in normal objects
138 if (! isset($this->params->{$name})) {
139 return $default;
140 }
141 return $this->params->{$name};
142 }
143
144 /**
145 * Set the event name
146 *
147 * @param string $name
148 */
149 public function setName($name)
150 {
151 $this->name = (string) $name;
152 }
153
154 /**
155 * Set the event target/context
156 *
157 * @param null|string|object $target
158 */
159 public function setTarget($target)
160 {
161 $this->target = $target;
162 }
163
164 /**
165 * Set an individual parameter to a value
166 *
167 * @param string|int $name
168 * @param mixed $value
169 */
170 public function setParam($name, $value)
171 {
172 if (is_array($this->params) || $this->params instanceof ArrayAccess) {
173 // Arrays or objects implementing array access
174 $this->params[$name] = $value;
175 return;
176 }
177
178 // Objects
179 $this->params->{$name} = $value;
180 }
181
182 /**
183 * Stop further event propagation
184 *
185 * @param bool $flag
186 */
187 public function stopPropagation($flag = true)
188 {
189 $this->stopPropagation = (bool) $flag;
190 }
191
192 /**
193 * Is propagation stopped?
194 *
195 * @return bool
196 */
197 public function propagationIsStopped()
198 {
199 return $this->stopPropagation;
200 }
201 }
202