From ee06f1febbe4d40b102d0a6e249fd99e3b26c32a Mon Sep 17 00:00:00 2001 From: "CORP\\phedor" Date: Tue, 3 Apr 2018 14:35:20 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20namespace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Action.php | 48 ++++++------------------ src/Model/Factory.php | 3 +- src/Tools/{String.php => StringUtil.php} | 2 +- src/Url.php | 13 +++++++ 4 files changed, 26 insertions(+), 40 deletions(-) rename src/Tools/{String.php => StringUtil.php} (99%) create mode 100644 src/Url.php diff --git a/src/Controller/Action.php b/src/Controller/Action.php index e549f9a..750b25e 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -4,6 +4,7 @@ namespace ctiso\Controller; use ctiso\Shortcut, Exception, ctiso\Path, + ctiso\Url, ctiso\View\View, ctiso\Model\Factory, ctiso\HttpRequest, @@ -11,14 +12,6 @@ use ctiso\Shortcut, ctiso\Settings, 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) { 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); } @@ -170,7 +163,7 @@ class Action * 2. Использовать наследование чтобы добавить к старому обработчику новое поведение * @param $request Обьект запроса */ - public function preprocess(HttpRequest $request) + public function preProcess(HttpRequest $request) { $action = self::ACTION_PREFIX . ucfirst($request->getAction()); if (!method_exists($this, $action)) { @@ -186,7 +179,7 @@ class Action public function execute(HttpRequest $request) { - $result = $this->preprocess($request); + $result = $this->preProcess($request); if (!empty($result)) { $this->view = $result; } @@ -206,15 +199,6 @@ class Action 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 учетом прав пользователя на ссылки * @param string $name Действие @@ -227,24 +211,14 @@ class Action /*.Filter_ActionAccess.*/$access = $this->access; if ($access == null || $access->checkAction($name)) { - return Functions::lcurry(array($this, 'postUrl'), $name, $param); - } - return null; - } + $param = array_merge(array( + 'module' => strtr($this->modulePrefix . strtolower(get_class($this)), array('module_' => '')), + "action" => $name + ), $param); - public function fUrl($name, array $param = array()) - { - return forceUrl($this->nUrl($name, $param)); - } - - /** - * Добавляет параметр для всех ссылок создаваемых функцией nUrl, aUrl - */ - public function addParameter($name, $value) - { - if ($value) { - $this->param [$name] = $value; + return new Url($param); } + return new Url(); } /** @@ -259,7 +233,7 @@ class Action */ 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)); } /** diff --git a/src/Model/Factory.php b/src/Model/Factory.php index 38ed7b7..868da5a 100644 --- a/src/Model/Factory.php +++ b/src/Model/Factory.php @@ -8,7 +8,6 @@ class Factory static $shortcut = "model"; public $db; public $_registry; - public $_shortcut; public function __construct (/*.Database.*/ $db, Settings $_registry = null) { @@ -23,7 +22,7 @@ class Factory */ public function getModel ($name) { - $modelName = "Mapper_" . $name; + $modelName = "App\\Mapper\\" . $name; $model = new $modelName(); $model->db = $this->db; $model->factory = $this; diff --git a/src/Tools/String.php b/src/Tools/StringUtil.php similarity index 99% rename from src/Tools/String.php rename to src/Tools/StringUtil.php index bda7385..8d07048 100644 --- a/src/Tools/String.php +++ b/src/Tools/StringUtil.php @@ -2,7 +2,7 @@ namespace ctiso\Tools; -class String { +class StringUtil { // from creole static function strToArray($str) { diff --git a/src/Url.php b/src/Url.php new file mode 100644 index 0000000..3137d16 --- /dev/null +++ b/src/Url.php @@ -0,0 +1,13 @@ +parts = $parts; + } + + function toString() { + return '?' . http_build_query($this->parts); + } +} \ No newline at end of file