[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Input/ -> Input.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2017 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\Input;
  11  
  12  use Joomla\CMS\Filter\InputFilter;
  13  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * Joomla! Input Base Class
  20   *
  21   * This is an abstracted input class used to manage retrieving data from the application environment.
  22   *
  23   * @since       1.7.0
  24   * @deprecated  5.0  Use Joomla\Input\Input instead
  25   *
  26   * @property-read   Input   $get
  27   * @property-read   Input   $post
  28   * @property-read   Input   $request
  29   * @property-read   Input   $server
  30   * @property-read   Input   $env
  31   * @property-read   Files   $files
  32   * @property-read   Cookie  $cookie
  33   */
  34  class Input extends \Joomla\Input\Input
  35  {
  36      /**
  37       * Container with allowed superglobals
  38       *
  39       * @var    array
  40       * @since  3.8.9
  41       * @deprecated  5.0  Use Joomla\Input\Input instead
  42       */
  43      private static $allowedGlobals = array('REQUEST', 'GET', 'POST', 'FILES', 'SERVER', 'ENV');
  44  
  45      /**
  46       * Input objects
  47       *
  48       * @var    Input[]
  49       * @since  1.7.0
  50       * @deprecated  5.0  Use Joomla\Input\Input instead
  51       */
  52      protected $inputs = array();
  53  
  54      /**
  55       * Constructor.
  56       *
  57       * @param   array  $source   Source data (Optional, default is $_REQUEST)
  58       * @param   array  $options  Array of configuration parameters (Optional)
  59       *
  60       * @since   1.7.0
  61       * @deprecated  5.0  Use Joomla\Input\Input instead
  62       */
  63      public function __construct($source = null, array $options = array())
  64      {
  65          if (!isset($options['filter'])) {
  66              $this->filter = InputFilter::getInstance();
  67          }
  68  
  69          parent::__construct($source, $options);
  70      }
  71  
  72      /**
  73       * Magic method to get an input object
  74       *
  75       * @param   mixed  $name  Name of the input object to retrieve.
  76       *
  77       * @return  \Joomla\Input\Input  The request input object
  78       *
  79       * @since   1.7.0
  80       * @deprecated  5.0  Use Joomla\Input\Input instead
  81       */
  82      public function __get($name)
  83      {
  84          if (isset($this->inputs[$name])) {
  85              return $this->inputs[$name];
  86          }
  87  
  88          $className = '\\Joomla\\CMS\\Input\\' . ucfirst($name);
  89  
  90          if (class_exists($className)) {
  91              $this->inputs[$name] = new $className(null, $this->options);
  92  
  93              return $this->inputs[$name];
  94          }
  95  
  96          $superGlobal = '_' . strtoupper($name);
  97  
  98          if (\in_array(strtoupper($name), self::$allowedGlobals, true) && isset($GLOBALS[$superGlobal])) {
  99              $this->inputs[$name] = new Input($GLOBALS[$superGlobal], $this->options);
 100  
 101              return $this->inputs[$name];
 102          }
 103  
 104          // Try using the parent class
 105          return parent::__get($name);
 106      }
 107  
 108      /**
 109       * Gets an array of values from the request.
 110       *
 111       * @param   array   $vars           Associative array of keys and filter types to apply.
 112       *                                  If empty and datasource is null, all the input data will be returned
 113       *                                  but filtered using the filter given by the parameter defaultFilter in
 114       *                                  InputFilter::clean.
 115       * @param   mixed   $datasource     Array to retrieve data from, or null.
 116       * @param   string  $defaultFilter  Default filter used in InputFilter::clean if vars is empty and
 117       *                                  datasource is null. If 'unknown', the default case is used in
 118       *                                  InputFilter::clean.
 119       *
 120       * @return  mixed  The filtered input data.
 121       *
 122       * @since   1.7.0
 123       * @deprecated  5.0  Use Joomla\Input\Input instead
 124       */
 125      public function getArray(array $vars = array(), $datasource = null, $defaultFilter = 'unknown')
 126      {
 127          return $this->getArrayRecursive($vars, $datasource, $defaultFilter, false);
 128      }
 129  
 130      /**
 131       * Gets an array of values from the request.
 132       *
 133       * @param   array   $vars           Associative array of keys and filter types to apply.
 134       *                                  If empty and datasource is null, all the input data will be returned
 135       *                                  but filtered using the filter given by the parameter defaultFilter in
 136       *                                  InputFilter::clean.
 137       * @param   mixed   $datasource     Array to retrieve data from, or null.
 138       * @param   string  $defaultFilter  Default filter used in InputFilter::clean if vars is empty and
 139       *                                  datasource is null. If 'unknown', the default case is used in
 140       *                                  InputFilter::clean.
 141       * @param   bool    $recursion      Flag to indicate a recursive function call.
 142       *
 143       * @return  mixed  The filtered input data.
 144       *
 145       * @since   3.4.2
 146       * @deprecated  5.0  Use Joomla\Input\Input instead
 147       */
 148      protected function getArrayRecursive(array $vars = array(), $datasource = null, $defaultFilter = 'unknown', $recursion = false)
 149      {
 150          if (empty($vars) && \is_null($datasource)) {
 151              $vars = $this->data;
 152          } else {
 153              if (!$recursion) {
 154                  $defaultFilter = null;
 155              }
 156          }
 157  
 158          $results = array();
 159  
 160          foreach ($vars as $k => $v) {
 161              if (\is_array($v)) {
 162                  if (\is_null($datasource)) {
 163                      $results[$k] = $this->getArrayRecursive($v, $this->get($k, null, 'array'), $defaultFilter, true);
 164                  } else {
 165                      $results[$k] = $this->getArrayRecursive($v, $datasource[$k], $defaultFilter, true);
 166                  }
 167              } else {
 168                  $filter = $defaultFilter ?? $v;
 169  
 170                  if (\is_null($datasource)) {
 171                      $results[$k] = $this->get($k, null, $filter);
 172                  } elseif (isset($datasource[$k])) {
 173                      $results[$k] = $this->filter->clean($datasource[$k], $filter);
 174                  } else {
 175                      $results[$k] = $this->filter->clean(null, $filter);
 176                  }
 177              }
 178          }
 179  
 180          return $results;
 181      }
 182  
 183      /**
 184       * Method to unserialize the input.
 185       *
 186       * @param   string  $input  The serialized input.
 187       *
 188       * @return  Input  The input object.
 189       *
 190       * @since   3.0.0
 191       * @deprecated  5.0  Use Joomla\Input\Input instead
 192       */
 193      public function unserialize($input)
 194      {
 195          // Unserialize the options, data, and inputs.
 196          list($this->options, $this->data, $this->inputs) = unserialize($input);
 197  
 198          // Load the filter.
 199          if (isset($this->options['filter'])) {
 200              $this->filter = $this->options['filter'];
 201          } else {
 202              $this->filter = InputFilter::getInstance();
 203          }
 204      }
 205  }


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