Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 23d7fc72a9 | |||
| 38a0af6b86 |
@@ -22,7 +22,8 @@
|
|||||||
"issues": "https://git.svoboda.works/mirzaev/minimal/issues"
|
"issues": "https://git.svoboda.works/mirzaev/minimal/issues"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "~8.4"
|
"php": "~8.4",
|
||||||
|
"mobiledetect/mobiledetectlib": "^4.8"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"mirzaev/baza": "Baza database",
|
"mirzaev/baza": "Baza database",
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ use Closure as closure,
|
|||||||
InvalidArgumentException as exception_argument,
|
InvalidArgumentException as exception_argument,
|
||||||
UnexpectedValueException as exception_value,
|
UnexpectedValueException as exception_value,
|
||||||
LogicException as exception_logic,
|
LogicException as exception_logic,
|
||||||
ReflectionClass as reflection;
|
Error as error,
|
||||||
|
ArgumentCountError as error_argument_count,
|
||||||
|
ReflectionClass as reflection,
|
||||||
|
ReflectionMethod as reflection_method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core
|
* Core
|
||||||
@@ -255,12 +258,21 @@ final class core
|
|||||||
// Writing the request options from the route options
|
// Writing the request options from the route options
|
||||||
$request->options = $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)
|
// Processing the method of the controller and exit (success)
|
||||||
$action = function() use ($route, $request): string {
|
$action = function () use ($route, $request, $arguments): string {
|
||||||
try {
|
if (array_keys($arguments) === array_column((new reflection_method($route->controller, $route->method))->getParameters(), 'name')) {
|
||||||
return (string) $route->controller->{$route->method}(...($route->parameters + $route->variables + $request->parameters));
|
// Arguments match the controller method arguments
|
||||||
} catch (exception $exception) {
|
|
||||||
return (string) $route->controller->{$route->method}($route->parameters + $route->variables + $request->parameters);
|
// 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ use mirzaev\minimal\http\enumerations\method,
|
|||||||
mirzaev\minimal\http\enumerations\content,
|
mirzaev\minimal\http\enumerations\content,
|
||||||
mirzaev\minimal\http\response;
|
mirzaev\minimal\http\response;
|
||||||
|
|
||||||
|
// The smartphones detection library
|
||||||
|
use Detection\MobileDetect as mobile;
|
||||||
|
|
||||||
// Built-in libraries
|
// Built-in libraries
|
||||||
use DomainException as exception_domain,
|
use DomainException as exception_domain,
|
||||||
InvalidArgumentException as exception_argument,
|
InvalidArgumentException as exception_argument,
|
||||||
@@ -297,6 +300,50 @@ final class request
|
|||||||
get => $this->options ?? [];
|
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->{__PROPERTY__})) {
|
||||||
|
// The property is not initialized
|
||||||
|
|
||||||
|
// Writing into the property
|
||||||
|
$this->{__PROPERTY__} = new mobile()->isMobile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $this->{__PROPERTY__};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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->{__PROPERTY__})) {
|
||||||
|
// The property is not initialized
|
||||||
|
|
||||||
|
// Writing into the property
|
||||||
|
$this->{__PROPERTY__} = new mobile()->isTablet();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit (success)
|
||||||
|
return $this->{__PROPERTY__};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user