[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Form/Filter/ -> IntarrayFilter.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Form\Filter;
  11  
  12  use Joomla\CMS\Form\Form;
  13  use Joomla\CMS\Form\FormFilterInterface;
  14  use Joomla\Registry\Registry;
  15  use Joomla\Utilities\ArrayHelper;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('JPATH_PLATFORM') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Form Filter class for integer arrays
  23   *
  24   * @since  4.0.0
  25   */
  26  class IntarrayFilter implements FormFilterInterface
  27  {
  28      /**
  29       * Method to filter a field value.
  30       *
  31       * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the `<field>` tag for the form field object.
  32       * @param   mixed              $value    The form field value to validate.
  33       * @param   string             $group    The field name group control value. This acts as an array container for the field.
  34       *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  35       *                                       full field name would end up being "bar[foo]".
  36       * @param   Registry           $input    An optional Registry object with the entire data set to validate against the entire form.
  37       * @param   Form               $form     The form object for which the field is being tested.
  38       *
  39       * @return  mixed   The filtered value.
  40       *
  41       * @since   4.0.0
  42       */
  43      public function filter(\SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
  44      {
  45          if (strtoupper((string) $element['filter']) === 'INT_ARRAY') {
  46              @trigger_error('`INT_ARRAY` form filter is deprecated and will be removed in 5.0. Use `Intarray` instead', E_USER_DEPRECATED);
  47          }
  48  
  49          if (\is_object($value)) {
  50              $value = get_object_vars($value);
  51          }
  52  
  53          $value = \is_array($value) ? $value : array($value);
  54  
  55          $value = ArrayHelper::toInteger($value);
  56  
  57          return $value;
  58      }
  59  }


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