2 Commits
2.0.x ... 2.2.1

7 changed files with 11 additions and 13 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
composer.json Normal file → Executable file
View File

0
composer.lock generated Normal file → Executable file
View File

4
mirzaev/minimal/system/controller.php Normal file → Executable file
View File

@@ -21,7 +21,7 @@ class controller
/** /**
* Постфикс * Постфикс
*/ */
private const POSTFIX = '_controller'; public const POSTFIX = '_controller';
/** /**
* Инстанция модели * Инстанция модели
@@ -51,7 +51,6 @@ class controller
public function __set(string $name, mixed $value = null): void public function __set(string $name, mixed $value = null): void
{ {
match ($name) { match ($name) {
'POSTFIX' => throw new exception('Запрещено реинициализировать постфикс ($this::POSTFIX)', 500),
'model' => (function () use ($value) { 'model' => (function () use ($value) {
if ($this->__isset('model')) throw new exception('Запрещено реинициализировать свойство с инстанцией модели ($this->model)', 500); if ($this->__isset('model')) throw new exception('Запрещено реинициализировать свойство с инстанцией модели ($this->model)', 500);
else { else {
@@ -84,7 +83,6 @@ class controller
public function __get(string $name): mixed public function __get(string $name): mixed
{ {
return match ($name) { return match ($name) {
'POSTFIX' => $this::POSTFIX ?? throw new exception("Свойство \"POSTFIX\" не инициализировано", 500),
'model' => $this->model ?? throw new exception("Свойство \"\$model\" не инициализировано", 500), 'model' => $this->model ?? throw new exception("Свойство \"\$model\" не инициализировано", 500),
'view' => $this->view ?? throw new exception("Свойство \"\$view\" не инициализировано", 500), 'view' => $this->view ?? throw new exception("Свойство \"\$view\" не инициализировано", 500),
default => throw new exception("Свойство \"\$$name\" не обнаружено", 404) default => throw new exception("Свойство \"\$$name\" не обнаружено", 404)

4
mirzaev/minimal/system/core.php Normal file → Executable file
View File

@@ -90,9 +90,9 @@ final class core
* *
* @param ?string $uri Маршрут * @param ?string $uri Маршрут
* *
* @return ?string Сгенерированный ответ (HTML, JSON...) * @return string|int|null Ответ
*/ */
public function start(string $uri = null): ?string public function start(string $uri = null): string|int|null
{ {
// Обработка запроса // Обработка запроса
return $this->__get('router')->handle($uri, core: $this); return $this->__get('router')->handle($uri, core: $this);

4
mirzaev/minimal/system/model.php Normal file → Executable file
View File

@@ -18,7 +18,7 @@ class model
/** /**
* Постфикс * Постфикс
*/ */
private const POSTFIX = '_model'; public const POSTFIX = '_model';
/** /**
* Конструктор * Конструктор
@@ -38,7 +38,6 @@ class model
public function __set(string $name, mixed $value = null): void public function __set(string $name, mixed $value = null): void
{ {
match ($name) { match ($name) {
'POSTFIX' => throw new exception('Запрещено реинициализировать постфикс ($this::POSTFIX)', 500),
default => throw new exception("Свойство \"\$$name\" не найдено", 404) default => throw new exception("Свойство \"\$$name\" не найдено", 404)
}; };
} }
@@ -53,7 +52,6 @@ class model
public function __get(string $name): mixed public function __get(string $name): mixed
{ {
return match ($name) { return match ($name) {
'POSTFIX' => $this::POSTFIX ?? throw new exception("Свойство \"POSTFIX\" не инициализировано", 500),
default => throw new exception("Свойство \"\$$name\" не обнаружено", 404) default => throw new exception("Свойство \"\$$name\" не обнаружено", 404)
}; };
} }

6
mirzaev/minimal/system/router.php Normal file → Executable file
View File

@@ -52,8 +52,10 @@ final class router
* @param ?string $uri URI запроса (https://domain.com/foo/bar) * @param ?string $uri URI запроса (https://domain.com/foo/bar)
* @param ?string $method Метод запроса (GET, POST, PUT...) * @param ?string $method Метод запроса (GET, POST, PUT...)
* @param ?core $core Инстанция системного ядра * @param ?core $core Инстанция системного ядра
*
* @return string|int|null Ответ
*/ */
public function handle(?string $uri = null, ?string $method = null, ?core $core = new core): ?string public function handle(?string $uri = null, ?string $method = null, ?core $core = new core): string|int|null
{ {
// Инициализация значений по умолчанию // Инициализация значений по умолчанию
$uri ??= $_SERVER['REQUEST_URI'] ?? '/'; $uri ??= $_SERVER['REQUEST_URI'] ?? '/';
@@ -124,7 +126,7 @@ final class router
$controller = new $controller; $controller = new $controller;
// Инициализация инстанции ядра модели // Инициализация инстанции ядра модели
if (class_exists($model = $core->namespace . '\\models\\' . $route['model'] . $core->model::POSTFIX)) $controller->model = new $model; if (class_exists($model = $core->namespace . '\\models\\' . $route['model'] . $core->model::POSTFIX));
// Вызов связанного с маршрутом методв и возврат (успех) // Вызов связанного с маршрутом методв и возврат (успех)
return $controller->{$route['method']}($data['vars'] + $_REQUEST, $_FILES); return $controller->{$route['method']}($data['vars'] + $_REQUEST, $_FILES);