Регистр файлов

This commit is contained in:
origami11 2017-02-16 10:14:36 +03:00
parent 4fd0187ea6
commit c8958cbee0
83 changed files with 25 additions and 53 deletions

83
src/Layout/Manager.php Normal file
View file

@ -0,0 +1,83 @@
<?php
require_once __DIR__ . '/../functions.php';
// Переместить в фильтры!!
/**
* Выбор макета страницы.
* Выбор оформления страницы осуществляется если было совпадение с каким либо условием
*/
class Layout_Manager extends Filter_Filter
{
// Массив условий с их макетами
protected $condition = array();
/**
* Функция которая добавляет условие для проверки параметров $_GET
* @param $get array() | true Ассоциативный массив ключей и значений для $_GET
*
* @example
* addConditionGet(array('module' => 'personal'), 'personal')
* addConditionGet(array('module' => 'login'), 'login')
*/
public function addConditionGet($get, Filter_Filter $layout)
{
$this->addCondition(rcurry(array($this, 'checkGet'), $get), $layout);
}
/**
* Условие для аякс запросов. Тоже самое что и addConditionGet но еще проверяется является ли запрос ajax
*/
public function addConditionXHR($get, Filter_Filter $layout)
{
$this->addCondition(rcurry(array($this, 'checkXHR'), $get), $layout);
}
public function checkGet($request, $get)
{
if (is_array($get)) {
foreach ($get as $key => $value) {
if ($request->get($key) != $value) {
return false;
}
}
}
return true;
}
public function checkXHR($request, $get)
{
return $request->isAjax() && $this->checkGet($request, $get);
}
/**
* Добавляет условие в общем виде
* @parma $get function(HttpRequest) Функция
* @parma $layout Layout Макет
*/
public function addCondition($get, Filter_Filter $layout)
{
$this->condition [] = array($get, $layout);
}
/**
* Выбирает и применяет макет для страницы
*/
public function execute(HttpRequest $request)
{
foreach ($this->condition as $condition) {
if (call_user_func($condition[0], $request)) {
$layout = $condition[1];
$view = $layout->execute($request);
if ($view instanceof View_Composite) {
echo $view->render();
} else {
echo $view;
}
return null;
}
}
}
}

11
src/Layout/None.php Normal file
View file

@ -0,0 +1,11 @@
<?php
/**
* Самый простой макет
*/
class Layout_None extends Filter_Filter
{
function execute(HttpRequest $request)
{
return $this->processor->execute($request);
}
}