From 82f6dd163089cdc87e511d7d14e7ce1214e3b9d3 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Mon, 16 Dec 2024 17:10:44 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=D0=97=D0=B0=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=20=D0=BD=D0=B0=20=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Action.php | 7 ++++++- src/Controller/Component.php | 3 ++- src/HttpRequest.php | 26 ++++++++++++++++---------- src/Model/Factory.php | 12 ++++++------ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/Controller/Action.php b/src/Controller/Action.php index d209a46..d10d2eb 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -98,7 +98,7 @@ class Action /** * Создает представление * @param string $name - * @param string $viewClass + * @param class-string $viewClass * @return Composite */ public function getView($name, $viewClass = Composite::class) @@ -146,6 +146,11 @@ class Action return $tpl; } + /** + * @template T + * @param class-string $name + * @return T + */ public function getModel($name) { if (!$this->factory) { diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 2dc5ffc..761f8fb 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -99,7 +99,8 @@ class Component return new FakeTemplate($name); } - $config/*: Registry*/ = $this->config; + /* @var Registry $config */ + $config = $this->config; $default = $config->get('site', 'template'); $template = ($this->template) ? $this->template : $this->getTemplateName($config); diff --git a/src/HttpRequest.php b/src/HttpRequest.php index 186ae12..c8c0f7c 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -1,16 +1,18 @@ $_REQUEST, - 'get' => $_GET, - 'post' => $_POST, + 'data' => $_REQUEST, + 'get' => $_GET, + 'post' => $_POST, 'cookie' => $_COOKIE ]; @@ -44,15 +46,19 @@ class HttpRequest extends Collection return parent::get($key); } + /** + * @param T $key + * @return mixed + */ function get($key, $default = null) { return parent::get('data')->get($key, $default); } - + function session(Session $value = null) { if ($value) { - $this->_session = $value; + $this->_session = $value; } return $this->_session; } @@ -97,7 +103,7 @@ class HttpRequest extends Collection } public function setAction($name) - { + { $this->setRawData('get', 'action', $name); } diff --git a/src/Model/Factory.php b/src/Model/Factory.php index cf7f46e..ab560e3 100644 --- a/src/Model/Factory.php +++ b/src/Model/Factory.php @@ -11,21 +11,21 @@ class Factory public $config; public $user; - public function __construct (Database $db, Registry $config = null, User $user = null) + public function __construct(Database $db, Registry $config = null, User $user = null) { $this->db = $db; $this->config = $config; $this->user = $user; } - + /** * Создает модель - * @param string $name - * @return BaseMapper + * @template T + * @param class-string $modelName + * @return T */ - public function getModel ($name) + public function getModel($modelName) { - $modelName = "App\\Mapper\\" . $name; $model = new $modelName(); $model->db = $this->db; $model->factory = $this;