[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Event/Workflow/ -> AbstractEvent.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  namespace Joomla\CMS\Event\Workflow;
  11  
  12  use BadMethodCallException;
  13  use Joomla\CMS\Event\AbstractImmutableEvent;
  14  
  15  use function explode;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('JPATH_PLATFORM') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Event class for WebAsset events
  23   *
  24   * @since  4.0.0
  25   */
  26  abstract class AbstractEvent extends AbstractImmutableEvent
  27  {
  28      /**
  29       * Constructor.
  30       *
  31       * @param   string  $name       The event name.
  32       * @param   array   $arguments  The event arguments.
  33       *
  34       * @throws  BadMethodCallException
  35       *
  36       * @since   4.0.0
  37       */
  38      public function __construct($name, array $arguments = array())
  39      {
  40          if (!\array_key_exists('subject', $arguments)) {
  41              throw new BadMethodCallException("Argument 'subject' of event {$this->name} is required but has not been provided");
  42          }
  43  
  44          if (!\array_key_exists('extension', $arguments)) {
  45              throw new BadMethodCallException("Argument 'extension' of event {$this->name} is required but has not been provided");
  46          }
  47  
  48          if (strpos($arguments['extension'], '.') === false) {
  49              throw new BadMethodCallException("Argument 'extension' of event {$this->name} has wrong format. Valid format: 'component.section'");
  50          }
  51  
  52          if (!\array_key_exists('extensionName', $arguments) || !\array_key_exists('section', $arguments)) {
  53              $parts = explode('.', $arguments['extension']);
  54  
  55              $arguments['extensionName'] = $arguments['extensionName'] ?? $parts[0];
  56              $arguments['section']       = $arguments['section'] ?? $parts[1];
  57          }
  58  
  59          parent::__construct($name, $arguments);
  60      }
  61  }


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