[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zend-eventmanager for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md 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 = []; 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 * @throws Exception\InvalidArgumentException 95 */ 96 public function setParams($params) 97 { 98 if (! is_array($params) && ! is_object($params)) { 99 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |