- md5
- 3917f59654eb1391cdec816a5c61fb85
- sha1
- 6950b16f2c427138065164e1e5802ea8a51166ed
- sha256
- f50fd1c7b055314e07a6e3b9713481ebb2e111acaad38d2640de8a607c4632d4
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
<?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.txt
*/
namespace Joomla\CMS\Event\Result;
// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* 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 an Integer type.
*
* @since 4.2.0
*/
trait ResultTypeIntegerAware
{
/**
* Can the result attribute values also be NULL?
*
* @var boolean
* @since 4.2.0
*/
protected $resultIsNullable = false;
/**
* Can the result attribute values also be boolean FALSE?
*
* @var boolean
* @since 4.2.0
*
* @deprecated 4.3 will be removed in 6.0
* You should use nullable values or exceptions instead of returning boolean false results.
*/
protected $resultIsFalseable = 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 ($this->resultIsFalseable && $data === false) {
return;
}
if (!is_int($data)) {
throw new \InvalidArgumentException(sprintf('Event %s only accepts Integer results.', $this->getName()));
}
}
}
The same content is in 35 releases, Joomla 4.4.0-alpha3 to 4.4.14. See them all, or every version of this file.