Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Event.php

Zuletzt modifiziert: 09.10.2024, 12:55 - Dateigröße: 4.52 KiB


 001  <?php
 002  /**
 003   * Zend Framework (http://framework.zend.com/)
 004   *
 005   * @link      http://github.com/zendframework/zf2 for the canonical source repository
 006   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 007   * @license   http://framework.zend.com/license/new-bsd New BSD License
 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 = array();
 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       * @return Event
 095       * @throws Exception\InvalidArgumentException
 096       */
 097      public function setParams($params)
 098      {
 099          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  }
 210