CoreFiles by mySites.guru
ResultTypeBooleanAware.php56 lines, 1,206 bytes, from Joomla_4.2.0-alpha3-dev-Development-Full_Package.zip
Raw History Compare with 4.2.0-alpha2
md5
fe727d5135d42b7b6bac924377082805
sha1
5475985745f7c5e2895f69a9e74c15cd83983910
sha256
ff56b81914d9b5e299ea43504ccc972b69a5644493b9fef7f6dc01c336d94a53
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
 * @license        GNU General Public License version 2 or later; see LICENSE
 */

namespace Joomla\CMS\Event\Result;

\defined('JPATH_PLATFORM') or die;

use InvalidArgumentException;

/**
 * This Trait partially implements the ResultAwareInterface for type checking.
 *
 * Events using this Trait (and the ResultAware trait) will expect event handlers to set results
 * of a Boolean type.
 *
 * @since  4.2.0
 */
trait ResultTypeBooleanAware
{
	/**
	 * Can the result attribute values also be NULL?
	 *
	 * @var    boolean
	 * @since  4.2.0
	 */
	protected $resultIsNullable = false;

	/**
	 * Checks the type of the data being appended to the result argument.
	 *
	 * @param   mixed  $data  The data to type check
	 *
	 * @return  void
	 * @throws  InvalidArgumentException
	 *
	 * @internal
	 * @since   4.2.0
	 */
	public function typeCheckResult($data): void
	{
		if ($this->resultIsNullable && $data === null)
		{
			return;
		}

		if (!is_bool($data))
		{
			throw new InvalidArgumentException(sprintf('Event %s only accepts Boolean results.', $this->getName()));
		}
	}
}

The same content is in 3 releases, Joomla 4.2.0-alpha3 to 4.2.0-beta2. See them all, or every version of this file.