CoreFiles by mySites.guru
AbstractEvent.php61 lines, 1,687 bytes, from Joomla_4.0.0-beta1-Beta-Full_Package.zip
Raw History Compare with 3.9.0-beta4
md5
78e110e978ea65c335ba78367a75ce31
sha1
d72328ad0683546afdd4402b40e6f49aa91be737
sha256
5c9db4af3cb742c32fd62f0a67584be853b9746e23ae4d0c07599c1c2d3e7db7
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE
 */

namespace Joomla\CMS\Event\Workflow;

\defined('JPATH_PLATFORM') or die;

use BadMethodCallException;
use Joomla\CMS\Event\AbstractImmutableEvent;
use function explode;

/**
 * Event class for WebAsset events
 *
 * @since  4.0.0
 */
abstract class AbstractEvent extends AbstractImmutableEvent
{
	/**
	 * Constructor.
	 *
	 * @param   string  $name       The event name.
	 * @param   array   $arguments  The event arguments.
	 *
	 * @throws  BadMethodCallException
	 *
	 * @since   4.0.0
	 */
	public function __construct($name, array $arguments = array())
	{
		if (!\array_key_exists('subject', $arguments))
		{
			throw new BadMethodCallException("Argument 'subject' of event {$this->name} is required but has not been provided");
		}

		if (!\array_key_exists('extension', $arguments))
		{
			throw new BadMethodCallException("Argument 'extension' of event {$this->name} is required but has not been provided");
		}

		if (strpos($arguments['extension'], '.') === false)
		{
			throw new BadMethodCallException("Argument 'extension' of event {$this->name} has wrong format. Valid format: 'component.section'");
		}

		if (!\array_key_exists('extensionName', $arguments) || !\array_key_exists('section', $arguments))
		{
			$parts = explode('.', $arguments['extension']);

			$arguments['extensionName'] = $arguments['extensionName'] ?? $parts[0];
			$arguments['section']       = $arguments['section'] ?? $parts[1];
		}

		parent::__construct($name, $arguments);
	}
}

The same content is in 5 releases, Joomla 4.0.0-beta to 4.0.0-beta5. See them all, or every version of this file.