Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ebd793a2d3 | |||
| ec370baa45 | |||
| aca9694723 | |||
| 23d7fc72a9 | |||
| 38a0af6b86 | |||
| 17c15b0860 | |||
| b7eda7a944 | |||
| 1123b75d9e |
@@ -22,7 +22,8 @@
|
||||
"issues": "https://git.svoboda.works/mirzaev/minimal/issues"
|
||||
},
|
||||
"require": {
|
||||
"php": "~8.4"
|
||||
"php": "~8.4",
|
||||
"mobiledetect/mobiledetectlib": "^4.8"
|
||||
},
|
||||
"suggest": {
|
||||
"mirzaev/baza": "Baza database",
|
||||
|
||||
@@ -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 ? $arguments : null);
|
||||
}
|
||||
};
|
||||
|
||||
foreach ($route->middlewares as $middleware) {
|
||||
// Iterating over the route middlewares
|
||||
|
||||
@@ -11,6 +11,9 @@ use mirzaev\minimal\http\enumerations\method,
|
||||
mirzaev\minimal\http\enumerations\content,
|
||||
mirzaev\minimal\http\response;
|
||||
|
||||
// The smartphones detection library
|
||||
use Detection\MobileDetect as mobile;
|
||||
|
||||
// Built-in libraries
|
||||
use DomainException as exception_domain,
|
||||
InvalidArgumentException as exception_argument,
|
||||
@@ -297,6 +300,50 @@ final class request
|
||||
get => $this->options ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Smartphone
|
||||
*
|
||||
* @see https://docs.mobiledetect.net/home/usage-composer Documentation
|
||||
*
|
||||
* @var bool $smartphone The request was sent from a smartphone?
|
||||
*/
|
||||
public bool $smartphone {
|
||||
// Read
|
||||
get {
|
||||
if (!isset($this->smartphone)) {
|
||||
// The property is not initialized
|
||||
|
||||
// Writing into the property
|
||||
$this->smartphone = new mobile()->isMobile();
|
||||
}
|
||||
|
||||
// Exit (success)
|
||||
return $this->smartphone;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tablet
|
||||
*
|
||||
* @see https://docs.mobiledetect.net/home/usage-composer Documentation
|
||||
*
|
||||
* @var bool $tablet The request was sent from a tablet?
|
||||
*/
|
||||
public bool $tablet {
|
||||
// Read
|
||||
get {
|
||||
if (!isset($this->tablet)) {
|
||||
// The property is not initialized
|
||||
|
||||
// Writing into the property
|
||||
$this->tablet = new mobile()->isTablet();
|
||||
}
|
||||
|
||||
// Exit (success)
|
||||
return $this->tablet;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
|
||||
@@ -129,6 +129,7 @@ final class router
|
||||
// Skipping unmatched routes based on results of previous iterations
|
||||
if (isset($matches[$route]) && $matches[$route] === false) continue;
|
||||
|
||||
|
||||
// Initializing of route directory
|
||||
$route_directory = $routes[$route][$i] ?? null;
|
||||
|
||||
@@ -161,17 +162,30 @@ final class router
|
||||
}
|
||||
}
|
||||
|
||||
// Finding a priority route from match results
|
||||
if (array_all($matches, fn($value) => $value === false)) {
|
||||
// Not found any route
|
||||
|
||||
if (false) {
|
||||
// Initialized the errors controller
|
||||
|
||||
// Processing the `404` error method
|
||||
|
||||
}
|
||||
} else {
|
||||
// Found At least one route
|
||||
|
||||
// Finding a priority route from all match results (setting the $route variable)
|
||||
foreach ($matches as $route => $match) if ($match !== false) break;
|
||||
unset($match);
|
||||
|
||||
if ($route && !empty($data = $this->routes[$route])) {
|
||||
// Route found
|
||||
// The route found
|
||||
|
||||
// Universalization of route
|
||||
// Universalization of the route
|
||||
$route = self::universalize($route);
|
||||
|
||||
/**
|
||||
* Initialization of route variables
|
||||
* Initialization of the route variables
|
||||
*/
|
||||
|
||||
foreach ($routes[$route] as $i => $route_directory) {
|
||||
@@ -180,7 +194,7 @@ final class router
|
||||
if (preg_match('/^\$([a-zA-Z_\x80-\xff]+)$/', $route_directory) === 1) {
|
||||
// The directory is a variable ($variable)
|
||||
|
||||
// Запись в реестр переменных и перещапись директории в маршруте
|
||||
// Запись в реестр переменных и перезапись директории в маршруте
|
||||
$data[$request->method->value]->variables[trim($route_directory, '$')] = $directories[$i];
|
||||
} else if (preg_match('/^\$([a-zA-Z_\x80-\xff]+\.\.\.)$/', $route_directory) === 1) {
|
||||
// The directory of route is a collector ($variable...)
|
||||
@@ -209,8 +223,9 @@ final class router
|
||||
return $data[$request->method->value] ?? null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Exit (fail)
|
||||
// Exit (success/fail)
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ trait magic
|
||||
*/
|
||||
public function __set(string $name, mixed $value = null): void
|
||||
{
|
||||
if (property_exists(static, $name)) {
|
||||
if (property_exists(static::static, $name)) {
|
||||
// Exist the property
|
||||
|
||||
// Writing the property
|
||||
|
||||
Reference in New Issue
Block a user