[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/event/src/ -> AbstractEvent.php (source)

   1  <?php
   2  /**
   3   * Part of the Joomla Framework Event Package
   4   *
   5   * @copyright  Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved.
   6   * @license    GNU General Public License version 2 or later; see LICENSE
   7   */
   8  
   9  namespace Joomla\Event;
  10  
  11  use ArrayAccess;
  12  use Countable;
  13  use Serializable;
  14  
  15  /**
  16   * Implementation of EventInterface.
  17   *
  18   * @since  1.0
  19   */
  20  abstract class AbstractEvent implements EventInterface, ArrayAccess, Serializable, Countable
  21  {
  22      /**
  23       * The event name.
  24       *
  25       * @var    string
  26       * @since  1.0
  27       */
  28      protected $name;
  29  
  30      /**
  31       * The event arguments.
  32       *
  33       * @var    array
  34       * @since  1.0
  35       */
  36      protected $arguments;
  37  
  38      /**
  39       * A flag to see if the event propagation is stopped.
  40       *
  41       * @var    boolean
  42       * @since  1.0
  43       */
  44      protected $stopped = false;
  45  
  46      /**
  47       * Constructor.
  48       *
  49       * @param   string  $name       The event name.
  50       * @param   array   $arguments  The event arguments.
  51       *
  52       * @since   1.0
  53       */
  54  	public function __construct($name, array $arguments = [])
  55      {
  56          $this->name      = $name;
  57          $this->arguments = $arguments;
  58      }
  59  
  60      /**
  61       * Get the event name.
  62       *
  63       * @return  string  The event name.
  64       *
  65       * @since   1.0
  66       */
  67  	public function getName()
  68      {
  69          return $this->name;
  70      }
  71  
  72      /**
  73       * Get an event argument value.
  74       *
  75       * @param   string  $name     The argument name.
  76       * @param   mixed   $default  The default value if not found.
  77       *
  78       * @return  mixed  The argument value or the default value.
  79       *
  80       * @since   1.0
  81       */
  82  	public function getArgument($name, $default = null)
  83      {
  84          if (isset($this->arguments[$name]))
  85          {
  86              return $this->arguments[$name];
  87          }
  88  
  89          return $default;
  90      }
  91  
  92      /**
  93       * Tell if the given event argument exists.
  94       *
  95       * @param   string  $name  The argument name.
  96       *
  97       * @return  boolean  True if it exists, false otherwise.
  98       *
  99       * @since   1.0
 100       */
 101  	public function hasArgument($name)
 102      {
 103          return isset($this->arguments[$name]);
 104      }
 105  
 106      /**
 107       * Get all event arguments.
 108       *
 109       * @return  array  An associative array of argument names as keys and their values as values.
 110       *
 111       * @since   1.0
 112       */
 113  	public function getArguments()
 114      {
 115          return $this->arguments;
 116      }
 117  
 118      /**
 119       * Tell if the event propagation is stopped.
 120       *
 121       * @return  boolean  True if stopped, false otherwise.
 122       *
 123       * @since   1.0
 124       */
 125  	public function isStopped()
 126      {
 127          return $this->stopped === true;
 128      }
 129  
 130      /**
 131       * Stops the propagation of the event to further event listeners.
 132       *
 133       * @return  void
 134       *
 135       * @since   2.0.0
 136       */
 137  	public function stopPropagation(): void
 138      {
 139          $this->stopped = true;
 140      }
 141  
 142      /**
 143       * Count the number of arguments.
 144       *
 145       * @return  integer  The number of arguments.
 146       *
 147       * @since   1.0
 148       */
 149      #[\ReturnTypeWillChange]
 150  	public function count()
 151      {
 152          return \count($this->arguments);
 153      }
 154  
 155      /**
 156       * Serialize the event.
 157       *
 158       * @return  string  The serialized event.
 159       *
 160       * @since   1.0
 161       */
 162  	public function serialize()
 163      {
 164          return serialize($this->__serialize());
 165      }
 166  
 167      /**
 168       * Serialize the event.
 169       *
 170       * @return  array  The data to be serialized
 171       *
 172       * @since   2.0.0
 173       */
 174  	public function __serialize()
 175      {
 176          return [
 177              'name'      => $this->name,
 178              'arguments' => $this->arguments,
 179              'stopped'   => $this->stopped,
 180          ];
 181      }
 182  
 183      /**
 184       * Unserialize the event.
 185       *
 186       * @param   string  $serialized  The serialized event.
 187       *
 188       * @return  void
 189       *
 190       * @since   1.0
 191       */
 192  	public function unserialize($serialized)
 193      {
 194          $this->__unserialize(unserialize($serialized));
 195      }
 196  
 197      /**
 198       * Unserialize the event.
 199       *
 200       * @param   array  $data  The serialized event.
 201       *
 202       * @return  void
 203       *
 204       * @since   2.0.0
 205       */
 206  	public function __unserialize(array $data)
 207      {
 208          $this->name      = $data['name'];
 209          $this->arguments = $data['arguments'];
 210          $this->stopped   = $data['stopped'];
 211      }
 212  
 213      /**
 214       * Tell if the given event argument exists.
 215       *
 216       * @param   string  $name  The argument name.
 217       *
 218       * @return  boolean  True if it exists, false otherwise.
 219       *
 220       * @since   1.0
 221       */
 222      #[\ReturnTypeWillChange]
 223  	public function offsetExists($name)
 224      {
 225          return $this->hasArgument($name);
 226      }
 227  
 228      /**
 229       * Get an event argument value.
 230       *
 231       * @param   string  $name  The argument name.
 232       *
 233       * @return  mixed  The argument value or null if not existing.
 234       *
 235       * @since   1.0
 236       */
 237      #[\ReturnTypeWillChange]
 238  	public function offsetGet($name)
 239      {
 240          return $this->getArgument($name);
 241      }
 242  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer