6 Commits

Author SHA1 Message Date
38a0af6b86 a litle bit reflection in the router, sorry 2026-04-12 18:02:02 +05:00
17c15b0860 fixed controller arguments fixing 2026-04-09 07:33:44 +05:00
b7eda7a944 controller arguments fixed 2026-04-08 15:03:49 +05:00
1123b75d9e fix magix static::class 2026-03-17 17:43:36 +05:00
6d1f1b79ba magic methods fixed 2026-03-09 09:10:11 +05:00
393f37577d json POST $variables fix 2025-12-02 18:58:04 +03:00
3 changed files with 38 additions and 10 deletions

View File

@@ -22,7 +22,10 @@ use Closure as closure,
InvalidArgumentException as exception_argument,
UnexpectedValueException as exception_value,
LogicException as exception_logic,
ReflectionClass as reflection;
Error as error,
ArgumentCountError as error_argument_count,
ReflectionClass as reflection,
ReflectionMethod as reflection_method;
/**
* Core
@@ -255,8 +258,23 @@ final class core
// Writing the request options from the route options
$request->options = $route->options;
// Initializing the controller method arguments
$arguments = $route->parameters + $route->variables + $request->parameters;
// 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, $arguments): string {
if (array_keys($arguments) === array_column((new reflection_method($route->controller, $route->method))->getParameters(), 'name')) {
// Arguments match the controller method arguments
// Exit (success)
return (string) $route->controller->{$route->method}(...$arguments);
} else {
// Arguments not match the controller method arguments
// Exit (success)
return (string) $route->controller->{$route->method}($arguments);
}
};
foreach ($route->middlewares as $middleware) {
// Iterating over the route middlewares

View File

@@ -408,9 +408,6 @@ final class request
// Exit (false)
throw new exception_argument('Failed to validate JSON from the input buffer', status::unprocessable_content->value);
}
// Writing parameters from environment into the property
$this->parameters = $_POST ?? [];
} else if ($this->method === method::post) {
// POST method

View File

@@ -8,7 +8,8 @@ namespace mirzaev\minimal\traits;
use mirzaev\minimal\http\enumerations\status;
// Built-in libraries
use exception;
use Exception as exception,
DomainException as exception_domain;
/**
* Trait of magical methods
@@ -28,6 +29,8 @@ trait magic
/**
* Write property
*
* @throws exception_domain Not found the proprty
*
* @param string $name Name 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
{
match ($name) {
default => throw new exception('Failed to find property: ' . static::class . "::\$$name", status::not_found->value)
};
if (property_exists(static::static, $name)) {
// 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
*
* @throws exception_domain Not found the property
*
* @param string $name Name of the property
*
* @return mixed Value of the property
@@ -50,7 +63,7 @@ trait magic
public function __get(string $name): mixed
{
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)
};
}