[ Index ]

PHP Cross Reference of phpBB-3.3.12-deutsch

title

Body

[close]

/phpbb/request/ -> deactivated_super_global.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\request;
  15  
  16  /**
  17  * Replacement for a superglobal (like $_GET or $_POST) which calls
  18  * trigger_error on all operations but isset, overloads the [] operator with SPL.
  19  */
  20  class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAggregate
  21  {
  22      /**
  23      * @var    string    Holds the name of the superglobal this is replacing.
  24      */
  25      private $name;
  26  
  27      /**
  28      * @var string (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE)    Super global constant.
  29      */
  30      private $super_global;
  31  
  32      /**
  33      * @var    \phpbb\request\request_interface    The request class instance holding the actual request data.
  34      */
  35      private $request;
  36  
  37      /**
  38      * Constructor generates an error message fitting the super global to be used within the other functions.
  39      *
  40      * @param    \phpbb\request\request_interface    $request    A request class instance holding the real super global data.
  41      * @param    string                    $name        Name of the super global this is a replacement for - e.g. '_GET'.
  42      * @param    string    $super_global    The variable's super global constant (\phpbb\request\request_interface::POST|GET|REQUEST|COOKIE).
  43      */
  44  	public function __construct(\phpbb\request\request_interface $request, $name, $super_global)
  45      {
  46          $this->request = $request;
  47          $this->name = $name;
  48          $this->super_global = $super_global;
  49      }
  50  
  51      /**
  52      * Calls trigger_error with the file and line number the super global was used in.
  53      */
  54  	private function error()
  55      {
  56          $file = '';
  57          $line = 0;
  58  
  59          $message = 'Illegal use of $' . $this->name . '. You must use the request class to access input data. Found in %s on line %d. This error message was generated by deactivated_super_global.';
  60  
  61          $backtrace = debug_backtrace();
  62          if (isset($backtrace[1]))
  63          {
  64              $file = $backtrace[1]['file'];
  65              $line = $backtrace[1]['line'];
  66          }
  67          trigger_error(sprintf($message, $file, $line), E_USER_ERROR);
  68      }
  69  
  70      /**
  71      * Redirects isset to the correct request class call.
  72      *
  73      * @param    string    $offset    The key of the super global being accessed.
  74      *
  75      * @return    bool    Whether the key on the super global exists.
  76      */
  77  	public function offsetExists($offset)
  78      {
  79          return $this->request->is_set($offset, $this->super_global);
  80      }
  81  
  82      /**#@+
  83      * Part of the \ArrayAccess implementation, will always result in a FATAL error.
  84      */
  85  	public function offsetGet($offset)
  86      {
  87          $this->error();
  88      }
  89  
  90  	public function offsetSet($offset, $value)
  91      {
  92          $this->error();
  93      }
  94  
  95  	public function offsetUnset($offset)
  96      {
  97          $this->error();
  98      }
  99      /**#@-*/
 100  
 101      /**
 102      * Part of the \Countable implementation, will always result in a FATAL error
 103      */
 104  	public function count()
 105      {
 106          $this->error();
 107      }
 108  
 109      /**
 110      * Part of the Traversable/IteratorAggregate implementation, will always result in a FATAL error
 111      */
 112  	public function getIterator()
 113      {
 114          $this->error();
 115      }
 116  }


Generated: Sun Jun 23 12:25:44 2024 Cross-referenced by PHPXref 0.7.1