refactor: Замена строк на имена классов

This commit is contained in:
origami11@yandex.ru 2024-12-16 17:10:44 +03:00
parent 1d22953f68
commit 82f6dd1630
4 changed files with 30 additions and 18 deletions

View file

@ -98,7 +98,7 @@ class Action
/** /**
* Создает представление * Создает представление
* @param string $name * @param string $name
* @param string $viewClass * @param class-string $viewClass
* @return Composite * @return Composite
*/ */
public function getView($name, $viewClass = Composite::class) public function getView($name, $viewClass = Composite::class)
@ -146,6 +146,11 @@ class Action
return $tpl; return $tpl;
} }
/**
* @template T
* @param class-string<T> $name
* @return T
*/
public function getModel($name) public function getModel($name)
{ {
if (!$this->factory) { if (!$this->factory) {

View file

@ -99,7 +99,8 @@ class Component
return new FakeTemplate($name); return new FakeTemplate($name);
} }
$config/*: Registry*/ = $this->config; /* @var Registry $config */
$config = $this->config;
$default = $config->get('site', 'template'); $default = $config->get('site', 'template');
$template = ($this->template) ? $this->template : $this->getTemplateName($config); $template = ($this->template) ? $this->template : $this->getTemplateName($config);

View file

@ -9,7 +9,9 @@ use Exception,
ctiso\Collection, ctiso\Collection,
ctiso\Session; ctiso\Session;
// HTTPRequest = ArrayAccess /**
* @template T
*/
class HttpRequest extends Collection class HttpRequest extends Collection
{ {
@ -44,6 +46,10 @@ class HttpRequest extends Collection
return parent::get($key); return parent::get($key);
} }
/**
* @param T $key
* @return mixed
*/
function get($key, $default = null) function get($key, $default = null)
{ {
return parent::get('data')->get($key, $default); return parent::get('data')->get($key, $default);

View file

@ -11,7 +11,7 @@ class Factory
public $config; public $config;
public $user; 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->db = $db;
$this->config = $config; $this->config = $config;
@ -20,12 +20,12 @@ class Factory
/** /**
* Создает модель * Создает модель
* @param string $name * @template T
* @return BaseMapper * @param class-string<T> $modelName
* @return T
*/ */
public function getModel ($name) public function getModel($modelName)
{ {
$modelName = "App\\Mapper\\" . $name;
$model = new $modelName(); $model = new $modelName();
$model->db = $this->db; $model->db = $this->db;
$model->factory = $this; $model->factory = $this;