[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/event/src/ -> Event.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 InvalidArgumentException;
  12  
  13  /**
  14   * Default Event class.
  15   *
  16   * @since  1.0
  17   */
  18  class Event extends AbstractEvent
  19  {
  20      /**
  21       * Add an event argument, only if it is not existing.
  22       *
  23       * @param   string  $name   The argument name.
  24       * @param   mixed   $value  The argument value.
  25       *
  26       * @return  $this
  27       *
  28       * @since   1.0
  29       */
  30  	public function addArgument($name, $value)
  31      {
  32          if (!isset($this->arguments[$name]))
  33          {
  34              $this->arguments[$name] = $value;
  35          }
  36  
  37          return $this;
  38      }
  39  
  40      /**
  41       * Add argument to event.
  42       *
  43       * @param   string  $name   Argument name.
  44       * @param   mixed   $value  Value.
  45       *
  46       * @return  $this
  47       *
  48       * @since   1.0
  49       */
  50  	public function setArgument($name, $value)
  51      {
  52          $this->arguments[$name] = $value;
  53  
  54          return $this;
  55      }
  56  
  57      /**
  58       * Remove an event argument.
  59       *
  60       * @param   string  $name  The argument name.
  61       *
  62       * @return  mixed  The old argument value or null if it is not existing.
  63       *
  64       * @since   1.0
  65       */
  66  	public function removeArgument($name)
  67      {
  68          $return = null;
  69  
  70          if (isset($this->arguments[$name]))
  71          {
  72              $return = $this->arguments[$name];
  73              unset($this->arguments[$name]);
  74          }
  75  
  76          return $return;
  77      }
  78  
  79      /**
  80       * Clear all event arguments.
  81       *
  82       * @return  array  The old arguments.
  83       *
  84       * @since   1.0
  85       */
  86  	public function clearArguments()
  87      {
  88          $arguments       = $this->arguments;
  89          $this->arguments = [];
  90  
  91          return $arguments;
  92      }
  93  
  94      /**
  95       * Stop the event propagation.
  96       *
  97       * @return  void
  98       *
  99       * @since   1.0
 100       * @deprecated  3.0  Use stopPropogation instead
 101       */
 102  	public function stop()
 103      {
 104          trigger_deprecation(
 105              'joomla/event',
 106              '2.0.0',
 107              '%s() is deprecated and will be removed in 3.0, use %s::stopPropagation() instead.',
 108              __METHOD__,
 109              EventInterface::class
 110          );
 111  
 112          $this->stopPropagation();
 113      }
 114  
 115      /**
 116       * Set the value of an event argument.
 117       *
 118       * @param   string  $name   The argument name.
 119       * @param   mixed   $value  The argument value.
 120       *
 121       * @return  void
 122       *
 123       * @since   1.0
 124       * @throws  InvalidArgumentException  If the argument name is null.
 125       */
 126      #[\ReturnTypeWillChange]
 127  	public function offsetSet($name, $value)
 128      {
 129          if ($name === null)
 130          {
 131              throw new InvalidArgumentException('The argument name cannot be null.');
 132          }
 133  
 134          $this->setArgument($name, $value);
 135      }
 136  
 137      /**
 138       * Remove an event argument.
 139       *
 140       * @param   string  $name  The argument name.
 141       *
 142       * @return  void
 143       *
 144       * @since   1.0
 145       */
 146      #[\ReturnTypeWillChange]
 147  	public function offsetUnset($name)
 148      {
 149          $this->removeArgument($name);
 150      }
 151  }


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