[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10 namespace Zend\EventManager; 11 12 use ArrayAccess; 13 14 /** 15 * Representation of an event 16 * 17 * Encapsulates the target context and parameters passed, and provides some 18 * behavior for interacting with the event manager. 19 */ 20 class Event implements EventInterface 21 { 22 /** 23 * @var string Event name 24 */ 25 protected $name; 26 27 /** 28 * @var string|object The event target 29 */ 30 protected $target; 31 32 /** 33 * @var array|ArrayAccess|object The event parameters 34 */ 35 protected $params = array(); 36 37 /** 38 * @var bool Whether or not to stop propagation 39 */ 40 protected $stopPropagation = false; 41 42 /** 43 * Constructor 44 * 45 * Accept a target and its parameters. 46 * 47 * @param string $name Event name 48 * @param string|object $target 49 * @param array|ArrayAccess $params 50 */ 51 public function __construct($name = null, $target = null, $params = null) 52 { 53 if (null !== $name) { 54 $this->setName($name); 55 } 56 57 if (null !== $target) { 58 $this->setTarget($target); 59 } 60 61 if (null !== $params) { 62 $this->setParams($params); 63 } 64 } 65 66 /** 67 * Get event name 68 * 69 * @return string 70 */ 71 public function getName() 72 { 73 return $this->name; 74 } 75 76 /** 77 * Get the event target 78 * 79 * This may be either an object, or the name of a static method. 80 * 81 * @return string|object 82 */ 83 public function getTarget() 84 { 85 return $this->target; 86 } 87 88 /** 89 * Set parameters 90 * 91 * Overwrites parameters 92 * 93 * @param array|ArrayAccess|object $params 94 * @return Event 95 * @throws Exception\InvalidArgumentException 96 */ 97 public function setParams($params) 98 { 99 if (!is_array($params) && !is_object($params)) { 100 throw new Exception\InvalidArgumentException( 101 sprintf('Event parameters must be an array or object; received "%s"', gettype($params)) 102 ); 103 } 104 105 $this->params = $params; 106 return $this; 107 } 108 109 /** 110 * Get all parameters 111 * 112 * @return array|object|ArrayAccess 113 */ 114 public function getParams() 115 { 116 return $this->params; 117 } 118 119 /** 120 * Get an individual parameter 121 * 122 * If the parameter does not exist, the $default value will be returned. 123 * 124 * @param string|int $name 125 * @param mixed $default 126 * @return mixed 127 */ 128 public function getParam($name, $default = null) 129 { 130 // Check in params that are arrays or implement array access 131 if (is_array($this->params) || $this->params instanceof ArrayAccess) { 132 if (!isset($this->params[$name])) { 133 return $default; 134 } 135 136 return $this->params[$name]; 137 } 138 139 // Check in normal objects 140 if (!isset($this->params->{$name})) { 141 return $default; 142 } 143 return $this->params->{$name}; 144 } 145 146 /** 147 * Set the event name 148 * 149 * @param string $name 150 * @return Event 151 */ 152 public function setName($name) 153 { 154 $this->name = (string) $name; 155 return $this; 156 } 157 158 /** 159 * Set the event target/context 160 * 161 * @param null|string|object $target 162 * @return Event 163 */ 164 public function setTarget($target) 165 { 166 $this->target = $target; 167 return $this; 168 } 169 170 /** 171 * Set an individual parameter to a value 172 * 173 * @param string|int $name 174 * @param mixed $value 175 * @return Event 176 */ 177 public function setParam($name, $value) 178 { 179 if (is_array($this->params) || $this->params instanceof ArrayAccess) { 180 // Arrays or objects implementing array access 181 $this->params[$name] = $value; 182 } else { 183 // Objects 184 $this->params->{$name} = $value; 185 } 186 return $this; 187 } 188 189 /** 190 * Stop further event propagation 191 * 192 * @param bool $flag 193 * @return void 194 */ 195 public function stopPropagation($flag = true) 196 { 197 $this->stopPropagation = (bool) $flag; 198 } 199 200 /** 201 * Is propagation stopped? 202 * 203 * @return bool 204 */ 205 public function propagationIsStopped() 206 { 207 return $this->stopPropagation; 208 } 209 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |