CoreFiles by mySites.guru
ResultTypeBooleanAware.php57 lines, 1,383 bytes, from Joomla_5.0.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 5.0.0-alpha1
md5
3387f71f55fa9a71e298703ae3f786ad
sha1
b2e202bf55f42e6aea057160e5abf496f10ae676
sha256
1bc066a844e0de055c8b1b7f4cdf2557c81b27badecef3551a23f386e461459b
<?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;

use InvalidArgumentException;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') 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 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 2 releases, Joomla 5.0.0-alpha1 to 5.0.0-alpha2. See them all, or every version of this file.