Поправил namespace
This commit is contained in:
parent
bef7165777
commit
ee06f1febb
4 changed files with 26 additions and 40 deletions
|
|
@ -4,6 +4,7 @@ namespace ctiso\Controller;
|
||||||
use ctiso\Shortcut,
|
use ctiso\Shortcut,
|
||||||
Exception,
|
Exception,
|
||||||
ctiso\Path,
|
ctiso\Path,
|
||||||
|
ctiso\Url,
|
||||||
ctiso\View\View,
|
ctiso\View\View,
|
||||||
ctiso\Model\Factory,
|
ctiso\Model\Factory,
|
||||||
ctiso\HttpRequest,
|
ctiso\HttpRequest,
|
||||||
|
|
@ -11,14 +12,6 @@ use ctiso\Shortcut,
|
||||||
ctiso\Settings,
|
ctiso\Settings,
|
||||||
ctiso\Controller\State;
|
ctiso\Controller\State;
|
||||||
|
|
||||||
function forceUrl($name)
|
|
||||||
{
|
|
||||||
if (is_callable($name)) {
|
|
||||||
return call_user_func($name);
|
|
||||||
}
|
|
||||||
return $name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Контроллер страниц
|
* Контроллер страниц
|
||||||
*/
|
*/
|
||||||
|
|
@ -158,7 +151,7 @@ class Action
|
||||||
public function getModel($name)
|
public function getModel($name)
|
||||||
{
|
{
|
||||||
if (!$this->factory) {
|
if (!$this->factory) {
|
||||||
$this->factory = new Factory($this->db, $this->_registry);
|
$this->factory = new Factory($this->db, $this->settings['registry']);
|
||||||
}
|
}
|
||||||
return $this->factory->getModel($name);
|
return $this->factory->getModel($name);
|
||||||
}
|
}
|
||||||
|
|
@ -170,7 +163,7 @@ class Action
|
||||||
* 2. Использовать наследование чтобы добавить к старому обработчику новое поведение
|
* 2. Использовать наследование чтобы добавить к старому обработчику новое поведение
|
||||||
* @param $request Обьект запроса
|
* @param $request Обьект запроса
|
||||||
*/
|
*/
|
||||||
public function preprocess(HttpRequest $request)
|
public function preProcess(HttpRequest $request)
|
||||||
{
|
{
|
||||||
$action = self::ACTION_PREFIX . ucfirst($request->getAction());
|
$action = self::ACTION_PREFIX . ucfirst($request->getAction());
|
||||||
if (!method_exists($this, $action)) {
|
if (!method_exists($this, $action)) {
|
||||||
|
|
@ -186,7 +179,7 @@ class Action
|
||||||
|
|
||||||
public function execute(HttpRequest $request)
|
public function execute(HttpRequest $request)
|
||||||
{
|
{
|
||||||
$result = $this->preprocess($request);
|
$result = $this->preProcess($request);
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
$this->view = $result;
|
$this->view = $result;
|
||||||
}
|
}
|
||||||
|
|
@ -206,15 +199,6 @@ class Action
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postUrl($name, $param)
|
|
||||||
{
|
|
||||||
$uri = array_merge(array('module' =>
|
|
||||||
strtr($this->modulePrefix . strtolower(get_class($this)), array('module_' => '')), "action" => $name),
|
|
||||||
$this->param, $param);
|
|
||||||
|
|
||||||
return "?" . http_build_query($uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Генерация ссылки c учетом прав пользователя на ссылки
|
* Генерация ссылки c учетом прав пользователя на ссылки
|
||||||
* @param string $name Действие
|
* @param string $name Действие
|
||||||
|
|
@ -227,24 +211,14 @@ class Action
|
||||||
/*.Filter_ActionAccess.*/$access = $this->access;
|
/*.Filter_ActionAccess.*/$access = $this->access;
|
||||||
|
|
||||||
if ($access == null || $access->checkAction($name)) {
|
if ($access == null || $access->checkAction($name)) {
|
||||||
return Functions::lcurry(array($this, 'postUrl'), $name, $param);
|
$param = array_merge(array(
|
||||||
}
|
'module' => strtr($this->modulePrefix . strtolower(get_class($this)), array('module_' => '')),
|
||||||
return null;
|
"action" => $name
|
||||||
}
|
), $param);
|
||||||
|
|
||||||
public function fUrl($name, array $param = array())
|
return new Url($param);
|
||||||
{
|
|
||||||
return forceUrl($this->nUrl($name, $param));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Добавляет параметр для всех ссылок создаваемых функцией nUrl, aUrl
|
|
||||||
*/
|
|
||||||
public function addParameter($name, $value)
|
|
||||||
{
|
|
||||||
if ($value) {
|
|
||||||
$this->param [$name] = $value;
|
|
||||||
}
|
}
|
||||||
|
return new Url();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -259,7 +233,7 @@ class Action
|
||||||
*/
|
*/
|
||||||
public function aUrl($name, array $param = array())
|
public function aUrl($name, array $param = array())
|
||||||
{
|
{
|
||||||
return $this->nUrl($name, array_merge(array('mode' => 'ajax'), $param)); // FIXME
|
return $this->nUrl($name, array_merge(array('mode' => 'ajax'), $param));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ class Factory
|
||||||
static $shortcut = "model";
|
static $shortcut = "model";
|
||||||
public $db;
|
public $db;
|
||||||
public $_registry;
|
public $_registry;
|
||||||
public $_shortcut;
|
|
||||||
|
|
||||||
public function __construct (/*.Database.*/ $db, Settings $_registry = null)
|
public function __construct (/*.Database.*/ $db, Settings $_registry = null)
|
||||||
{
|
{
|
||||||
|
|
@ -23,7 +22,7 @@ class Factory
|
||||||
*/
|
*/
|
||||||
public function getModel ($name)
|
public function getModel ($name)
|
||||||
{
|
{
|
||||||
$modelName = "Mapper_" . $name;
|
$modelName = "App\\Mapper\\" . $name;
|
||||||
$model = new $modelName();
|
$model = new $modelName();
|
||||||
$model->db = $this->db;
|
$model->db = $this->db;
|
||||||
$model->factory = $this;
|
$model->factory = $this;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace ctiso\Tools;
|
namespace ctiso\Tools;
|
||||||
|
|
||||||
class String {
|
class StringUtil {
|
||||||
|
|
||||||
// from creole
|
// from creole
|
||||||
static function strToArray($str) {
|
static function strToArray($str) {
|
||||||
13
src/Url.php
Normal file
13
src/Url.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ctiso;
|
||||||
|
|
||||||
|
class Url {
|
||||||
|
function __construct($parts = []) {
|
||||||
|
$this->parts = $parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toString() {
|
||||||
|
return '?' . http_build_query($this->parts);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue