Регистр файлов
This commit is contained in:
parent
4fd0187ea6
commit
c8958cbee0
83 changed files with 25 additions and 53 deletions
129
src/HttpRequest.php
Normal file
129
src/HttpRequest.php
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Неверный запрос
|
||||
*/
|
||||
class WrongRequestException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
// HTTPRequest = ArrayAccess
|
||||
class HttpRequest extends Collection implements ArrayAccess
|
||||
{
|
||||
|
||||
public $_session;
|
||||
/**
|
||||
* Constructor
|
||||
* Stores "request data" in GPC order.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$list = array (
|
||||
'data' => $_REQUEST,
|
||||
'get' => $_GET,
|
||||
'post' => $_POST,
|
||||
'cookie' => $_COOKIE);
|
||||
|
||||
$ajax = $this->isAjax();
|
||||
foreach ($list as $key => $value) {
|
||||
$data = new Collection();
|
||||
$data->import($value);
|
||||
parent::set($key, $data);
|
||||
}
|
||||
|
||||
$data = new Collection();
|
||||
$data->import($GLOBALS['_FILES']);
|
||||
parent::set('files', $data);
|
||||
}
|
||||
|
||||
function _get($key)
|
||||
{
|
||||
return parent::get($key);
|
||||
}
|
||||
|
||||
function get($key, $default = null)
|
||||
{
|
||||
return parent::get('data')->get($key, $default);
|
||||
}
|
||||
|
||||
function session(Session $value = null)
|
||||
{
|
||||
if ($value) {
|
||||
$this->_session = $value;
|
||||
}
|
||||
return $this->_session;
|
||||
}
|
||||
|
||||
function set($key, /*.any.*/$value)
|
||||
{
|
||||
return parent::get('data')->set($key, $value);
|
||||
}
|
||||
|
||||
function export($key = 'data')
|
||||
{
|
||||
return parent::get($key)->export();
|
||||
}
|
||||
|
||||
function clear()
|
||||
{
|
||||
return parent::get('data')->clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow access to data stored in GET, POST and COOKIE super globals.
|
||||
*
|
||||
* @param string $var
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRawData($var, $key)
|
||||
{
|
||||
$data = parent::get(strtolower($var));
|
||||
if ($data) {
|
||||
return $data->get($key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setRawData($var, $key, $val)
|
||||
{
|
||||
$data = parent::get(strtolower($var));
|
||||
if ($data) {
|
||||
return $data->set($key, $val);
|
||||
}
|
||||
}
|
||||
|
||||
public function setAction($name)
|
||||
{
|
||||
$this->setRawData('get', 'action', $name);
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
$result = $this->getRawData('get', 'action');
|
||||
return ($result) ? $result : 'index';
|
||||
}
|
||||
|
||||
public function isAjax()
|
||||
{
|
||||
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
|
||||
}
|
||||
|
||||
public function redirect($url) {
|
||||
header('location: ' . $url);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
public function offsetSet($key, $value) {
|
||||
}
|
||||
|
||||
public function offsetExists($key) {
|
||||
}
|
||||
|
||||
public function offsetUnset($key) {
|
||||
}
|
||||
|
||||
public function offsetGet($key) {
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue