[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Event/Result/ -> ResultTypeStringAware.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 String type.
  23   *
  24   * @since  4.2.0
  25   */
  26  trait ResultTypeStringAware
  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       * Can the result attribute values also be boolean FALSE?
  38       *
  39       * @var    boolean
  40       * @since  4.2.0
  41       *
  42       * @deprecated 5.0 You should use nullable values or exceptions instead of returning boolean false results.
  43       */
  44      protected $resultIsFalseable = false;
  45  
  46      /**
  47       * Checks the type of the data being appended to the result argument.
  48       *
  49       * @param   mixed  $data  The data to type check
  50       *
  51       * @return  void
  52       * @throws  InvalidArgumentException
  53       *
  54       * @internal
  55       * @since   4.2.0
  56       */
  57      public function typeCheckResult($data): void
  58      {
  59          if ($this->resultIsNullable && $data === null) {
  60              return;
  61          }
  62  
  63          if ($this->resultIsFalseable && $data === false) {
  64              return;
  65          }
  66  
  67          if (!is_string($data)) {
  68              throw new InvalidArgumentException(sprintf('Event %s only accepts String results.', $this->getName()));
  69          }
  70      }
  71  }


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