[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/event/src/ -> EventImmutable.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 BadMethodCallException;
  12  
  13  /**
  14   * Implementation of an immutable Event.
  15   * An immutable event cannot be modified after instanciation :
  16   *
  17   * - its propagation cannot be stopped
  18   * - its arguments cannot be modified
  19   *
  20   * You may want to use this event when you want to ensure that
  21   * the listeners won't manipulate it.
  22   *
  23   * @since  1.0
  24   */
  25  final class EventImmutable extends AbstractEvent
  26  {
  27      /**
  28       * A flag to see if the constructor has been
  29       * already called.
  30       *
  31       * @var  boolean
  32       */
  33      private $constructed = false;
  34  
  35      /**
  36       * Constructor.
  37       *
  38       * @param   string  $name       The event name.
  39       * @param   array   $arguments  The event arguments.
  40       *
  41       * @throws  BadMethodCallException
  42       *
  43       * @since   1.0
  44       */
  45  	public function __construct($name, array $arguments = [])
  46      {
  47          if ($this->constructed)
  48          {
  49              throw new BadMethodCallException(
  50                  sprintf('Cannot reconstruct the EventImmutable %s.', $this->name)
  51              );
  52          }
  53  
  54          $this->constructed = true;
  55  
  56          parent::__construct($name, $arguments);
  57      }
  58  
  59      /**
  60       * Set the value of an event argument.
  61       *
  62       * @param   string  $name   The argument name.
  63       * @param   mixed   $value  The argument value.
  64       *
  65       * @return  void
  66       *
  67       * @since   1.0
  68       * @throws  BadMethodCallException
  69       */
  70  	public function offsetSet($name, $value)
  71      {
  72          throw new BadMethodCallException(
  73              sprintf(
  74                  'Cannot set the argument %s of the immutable event %s.',
  75                  $name,
  76                  $this->name
  77              )
  78          );
  79      }
  80  
  81      /**
  82       * Remove an event argument.
  83       *
  84       * @param   string  $name  The argument name.
  85       *
  86       * @return  void
  87       *
  88       * @throws  BadMethodCallException
  89       *
  90       * @since   1.0
  91       */
  92  	public function offsetUnset($name)
  93      {
  94          throw new BadMethodCallException(
  95              sprintf(
  96                  'Cannot remove the argument %s of the immutable event %s.',
  97                  $name,
  98                  $this->name
  99              )
 100          );
 101      }
 102  }


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