mirror of
https://github.com/BeitDina/AutoIndex.git
synced 2025-12-25 00:29:39 +01:00
142 lines
3.9 KiB
PHP
142 lines
3.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package AutoIndex
|
|
*
|
|
* @copyright (c) 2002-2021 Markus Petrux, John Olson, FlorinCB aka orynider at github.com
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License v2
|
|
* @link http://mxpcms.sourceforge.net/
|
|
* @link http://autoindex.sourceforge.net
|
|
*/
|
|
|
|
/*
|
|
AutoIndex PHP Script is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
AutoIndex PHP Script is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
if (!defined('IN_AUTOINDEX') || !IN_AUTOINDEX)
|
|
{
|
|
die();
|
|
}
|
|
|
|
|
|
/**#@+
|
|
* Class deactivated_super_global specific definitions
|
|
*
|
|
* Replacement for a superglobal (like $_GET or $_POST) which calls
|
|
* trigger_error on all operations but isset, overloads the [] operator with SPL.
|
|
*/
|
|
class deactivated_super_global implements \ArrayAccess, \Countable, \IteratorAggregate
|
|
{
|
|
/**
|
|
* @var string Holds the name of the superglobal this is replacing.
|
|
*/
|
|
private $name;
|
|
|
|
/**
|
|
* @var \mxp\request\mx_request_vars::POST|GET|REQUEST|COOKIE Super global constant.
|
|
*/
|
|
private $super_global;
|
|
|
|
/**
|
|
* @var mx_request_vars The request class instance holding the actual request data.
|
|
*/
|
|
private $request;
|
|
|
|
/**
|
|
* Constructor generates an error message fitting the super global to be used within the other functions.
|
|
*
|
|
* @param request $request A request class instance holding the real super global data.
|
|
* @param string $name Name of the super global this is a replacement for - e.g. '_GET'.
|
|
* @param mx_request_vars::POST|GET|REQUEST|COOKIE $super_global The variable's super global constant.
|
|
*/
|
|
public function __construct($request, string $name, int $super_global)
|
|
{
|
|
$this->request = $request;
|
|
$this->name = $name;
|
|
$this->super_global = $super_global;
|
|
}
|
|
|
|
/**
|
|
* Calls trigger_error with the file and line number the super global was used in.
|
|
*/
|
|
private function error()
|
|
{
|
|
$file = '';
|
|
$line = 0;
|
|
|
|
$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.';
|
|
|
|
$backtrace = debug_backtrace();
|
|
|
|
if (isset($backtrace[1]))
|
|
{
|
|
$file = isset($backtrace[1]['file']) ? $backtrace[1]['file'] : 'file? ';
|
|
$line = isset($backtrace[1]['line']) ? $backtrace[1]['line'] : 0;
|
|
}
|
|
|
|
trigger_error(sprintf($message, $file, $line), E_USER_ERROR);
|
|
}
|
|
|
|
/**
|
|
* Redirects isset to the correct request class call.
|
|
*
|
|
* @param string $offset The key of the super global being accessed.
|
|
*
|
|
* @return bool Whether the key on the super global exists.
|
|
*/
|
|
public function offsetExists($offset): bool
|
|
{
|
|
return $this->request->is_set($offset, $this->super_global);
|
|
}
|
|
|
|
/**#@+
|
|
* Part of the \ArrayAccess implementation, will always result in a FATAL error.
|
|
*/
|
|
public function offsetGet($offset): mixed
|
|
{
|
|
$this->error();
|
|
}
|
|
|
|
public function offsetSet($offset, $value): void
|
|
{
|
|
$this->error();
|
|
}
|
|
|
|
public function offsetUnset($offset): void
|
|
{
|
|
$this->error();
|
|
}
|
|
/**#@-*/
|
|
|
|
/**
|
|
* Part of the \Countable implementation, will always result in a FATAL error
|
|
*/
|
|
#[\ReturnTypeWillChange]
|
|
public function count(): void
|
|
{
|
|
$this->error();
|
|
}
|
|
|
|
/**
|
|
* Part of the Traversable/IteratorAggregate implementation, will always result in a FATAL error
|
|
*/
|
|
#[\ReturnTypeWillChange]
|
|
public function getIterator(): void
|
|
{
|
|
$this->error();
|
|
}
|
|
} // class deactivated_super_global
|
|
?>
|