Библиотека для cis, online, cms1

This commit is contained in:
Фёдор Подлеснов 2016-06-29 18:51:32 +03:00
commit 3c2e614d87
269 changed files with 39854 additions and 0 deletions

136
core/httprequest.php Normal file
View file

@ -0,0 +1,136 @@
<?php
require_once 'core/safecollection.php';
require_once 'core/json.php';
require_once 'core/session.php';
/**
* Íåâåðíûé çàïðîñ
*/
class WrongRequestException extends Exception
{
}
// HTTPRequest = ArrayAccess
class HttpRequest extends Collection implements ArrayAccess
{
/**
* 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 SafeCollection();
if ($ajax) {
$data->import(json::prepare($value, array('self', 'unicode_decode')));
} else {
$data->import($value);
}
parent::set($key, $data);
}
$data = new Collection();
$data->import($GLOBALS['_FILES']);
parent::set('files', $data);
}
function get($key, $default = null)
{
return parent::get('data')->get($key, $default);
}
function session($value = false)
{
if ($value) {
$this->session = $value;
}
return $this->session;
}
function set($key, $value)
{
return parent::get('data')->set($key, $value);
}
function _get($key)
{
return parent::get($key);
}
function export()
{
return parent::get('data')->export();
}
/* Array Acces Interface */
function offsetExists($offset)
{
}
function offsetGet($offset)
{
}
function offsetSet($offset, $value)
{
}
function offsetUnset($offset)
{
}
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');
}
}