Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
95ddffba30 | |||
41bf8ab56a |
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
composer.json
Normal file → Executable file
0
composer.json
Normal file → Executable file
0
composer.lock
generated
Normal file → Executable file
0
composer.lock
generated
Normal file → Executable file
4
mirzaev/minimal/system/controller.php
Normal file → Executable file
4
mirzaev/minimal/system/controller.php
Normal file → Executable 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
|
||||
{
|
||||
match ($name) {
|
||||
'POSTFIX' => throw new exception('Запрещено реинициализировать постфикс ($this::POSTFIX)', 500),
|
||||
'model' => (function () use ($value) {
|
||||
if ($this->__isset('model')) throw new exception('Запрещено реинициализировать свойство с инстанцией модели ($this->model)', 500);
|
||||
else {
|
||||
@@ -84,7 +83,6 @@ class controller
|
||||
public function __get(string $name): mixed
|
||||
{
|
||||
return match ($name) {
|
||||
'POSTFIX' => $this::POSTFIX ?? throw new exception("Свойство \"POSTFIX\" не инициализировано", 500),
|
||||
'model' => $this->model ?? throw new exception("Свойство \"\$model\" не инициализировано", 500),
|
||||
'view' => $this->view ?? throw new exception("Свойство \"\$view\" не инициализировано", 500),
|
||||
default => throw new exception("Свойство \"\$$name\" не обнаружено", 404)
|
||||
|
4
mirzaev/minimal/system/core.php
Normal file → Executable file
4
mirzaev/minimal/system/core.php
Normal file → Executable file
@@ -90,9 +90,9 @@ final class core
|
||||
*
|
||||
* @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);
|
||||
|
4
mirzaev/minimal/system/model.php
Normal file → Executable file
4
mirzaev/minimal/system/model.php
Normal file → Executable 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
|
||||
{
|
||||
match ($name) {
|
||||
'POSTFIX' => throw new exception('Запрещено реинициализировать постфикс ($this::POSTFIX)', 500),
|
||||
default => throw new exception("Свойство \"\$$name\" не найдено", 404)
|
||||
};
|
||||
}
|
||||
@@ -53,7 +52,6 @@ class model
|
||||
public function __get(string $name): mixed
|
||||
{
|
||||
return match ($name) {
|
||||
'POSTFIX' => $this::POSTFIX ?? throw new exception("Свойство \"POSTFIX\" не инициализировано", 500),
|
||||
default => throw new exception("Свойство \"\$$name\" не обнаружено", 404)
|
||||
};
|
||||
}
|
||||
|
12
mirzaev/minimal/system/router.php
Normal file → Executable file
12
mirzaev/minimal/system/router.php
Normal file → Executable file
@@ -51,9 +51,11 @@ final class router
|
||||
*
|
||||
* @param ?string $uri URI запроса (https://domain.com/foo/bar)
|
||||
* @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'] ?? '/';
|
||||
@@ -115,16 +117,16 @@ final class router
|
||||
if (array_key_exists($method, $data)) {
|
||||
// Идентифицирован метод маршрута (GET, POST, PUT...)
|
||||
|
||||
$route = $data[$method];
|
||||
$route = $data[$method];
|
||||
|
||||
if (class_exists($controller = $core->namespace . '\\controllers\\' . $route['controller'] . $core->controller::POSTFIX)) {
|
||||
// Найден контроллер
|
||||
|
||||
// Инициализация инстанции ядра контроллера
|
||||
$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);
|
||||
|
Reference in New Issue
Block a user