[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Event/Result/ -> ResultTypeBooleanAware.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2022 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\Result;
  11  
  12  use InvalidArgumentException;
  13  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * This Trait partially implements the ResultAwareInterface for type checking.
  20   *
  21   * Events using this Trait (and the ResultAware trait) will expect event handlers to set results
  22   * of a Boolean type.
  23   *
  24   * @since  4.2.0
  25   */
  26  trait ResultTypeBooleanAware
  27  {
  28      /**
  29       * Can the result attribute values also be NULL?
  30       *
  31       * @var    boolean
  32       * @since  4.2.0
  33       */
  34      protected $resultIsNullable = false;
  35  
  36      /**
  37       * Checks the type of the data being appended to the result argument.
  38       *
  39       * @param   mixed  $data  The data to type check
  40       *
  41       * @return  void
  42       * @throws  InvalidArgumentException
  43       *
  44       * @internal
  45       * @since   4.2.0
  46       */
  47      public function typeCheckResult($data): void
  48      {
  49          if ($this->resultIsNullable && $data === null) {
  50              return;
  51          }
  52  
  53          if (!is_bool($data)) {
  54              throw new InvalidArgumentException(sprintf('Event %s only accepts Boolean results.', $this->getName()));
  55          }
  56      }
  57  }


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