Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 17c15b0860 | |||
| b7eda7a944 | |||
| 1123b75d9e | |||
| 6d1f1b79ba |
@@ -256,7 +256,13 @@ final class core
|
|||||||
$request->options = $route->options;
|
$request->options = $route->options;
|
||||||
|
|
||||||
// Processing the method of the controller and exit (success)
|
// Processing the method of the controller and exit (success)
|
||||||
$action = fn(): string => (string) $route->controller->{$route->method}(...($route->parameters + $route->variables + $request->parameters));
|
$action = function() use ($route, $request): string {
|
||||||
|
try {
|
||||||
|
return (string) $route->controller->{$route->method}(...($route->parameters + $route->variables + $request->parameters));
|
||||||
|
} catch (exception $exception) {
|
||||||
|
return (string) $route->controller->{$route->method}($route->parameters + $route->variables + $request->parameters);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
foreach ($route->middlewares as $middleware) {
|
foreach ($route->middlewares as $middleware) {
|
||||||
// Iterating over the route middlewares
|
// Iterating over the route middlewares
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ namespace mirzaev\minimal\traits;
|
|||||||
use mirzaev\minimal\http\enumerations\status;
|
use mirzaev\minimal\http\enumerations\status;
|
||||||
|
|
||||||
// Built-in libraries
|
// Built-in libraries
|
||||||
use exception;
|
use Exception as exception,
|
||||||
|
DomainException as exception_domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trait of magical methods
|
* Trait of magical methods
|
||||||
@@ -28,6 +29,8 @@ trait magic
|
|||||||
/**
|
/**
|
||||||
* Write property
|
* Write property
|
||||||
*
|
*
|
||||||
|
* @throws exception_domain Not found the proprty
|
||||||
|
*
|
||||||
* @param string $name Name of the property
|
* @param string $name Name of the property
|
||||||
* @param mixed $value Value of the property
|
* @param mixed $value Value of the property
|
||||||
*
|
*
|
||||||
@@ -35,14 +38,24 @@ trait magic
|
|||||||
*/
|
*/
|
||||||
public function __set(string $name, mixed $value = null): void
|
public function __set(string $name, mixed $value = null): void
|
||||||
{
|
{
|
||||||
match ($name) {
|
if (property_exists(static::static, $name)) {
|
||||||
default => throw new exception('Failed to find property: ' . static::class . "::\$$name", status::not_found->value)
|
// Exist the property
|
||||||
};
|
|
||||||
|
// Writing the property
|
||||||
|
$this->{$name} = $value;
|
||||||
|
} else {
|
||||||
|
// Not exist the property
|
||||||
|
|
||||||
|
// Exit (fail)
|
||||||
|
throw new exception_domain('Not found the property: ' . static::class . "::\$$name", status::not_found->value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read property
|
* Read property
|
||||||
*
|
*
|
||||||
|
* @throws exception_domain Not found the property
|
||||||
|
*
|
||||||
* @param string $name Name of the property
|
* @param string $name Name of the property
|
||||||
*
|
*
|
||||||
* @return mixed Value of the property
|
* @return mixed Value of the property
|
||||||
@@ -50,7 +63,7 @@ trait magic
|
|||||||
public function __get(string $name): mixed
|
public function __get(string $name): mixed
|
||||||
{
|
{
|
||||||
return match ($name) {
|
return match ($name) {
|
||||||
default => throw new exception('Failed to find property: ' . static::class . "::\$$name", status::not_found->value)
|
default => throw new exception_domain('Not found the property: ' . static::class . "::\$$name", status::not_found->value)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user