1 Commits

Author SHA1 Message Date
e604d19eb1 variables fix with Ksenia 2025-10-25 14:39:20 +03:00
8 changed files with 2364 additions and 146 deletions

3
.gitignore vendored
View File

@@ -1,2 +1 @@
vendor
composer.lock
vendor

View File

@@ -14,7 +14,7 @@
"name": "Arsen Mirzaev Tatyano-Muradovich",
"email": "arsen@mirzaev.sexy",
"homepage": "https://mirzaev.sexy",
"role": "Creator"
"role": "Programmer"
}
],
"support": {
@@ -22,16 +22,8 @@
"issues": "https://git.svoboda.works/mirzaev/minimal/issues"
},
"require": {
"php": "~8.4",
"mobiledetect/mobiledetectlib": "^4.8"
"php": "~8.4"
},
"suggest": {
"mirzaev/baza": "Baza database",
"mirzaev/pot": "Template for projects",
"mirzaev/files": "Easy working with files",
"mirzaev/languages": "Easy languages integration",
"mirzaev/currencies": "Easy currencies integration"
},
"autoload": {
"psr-4": {
"mirzaev\\minimal\\": "mirzaev/minimal/system"

2320
composer.lock generated Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -6,26 +6,23 @@ namespace mirzaev\minimal;
// Files of the project
use mirzaev\minimal\router,
mirzaev\minimal\route,
mirzaev\minimal\controller,
mirzaev\minimal\model,
mirzaev\minimal\http\request,
mirzaev\minimal\http\response,
mirzaev\minimal\http\enumerations\status;
mirzaev\minimal\route,
mirzaev\minimal\controller,
mirzaev\minimal\model,
mirzaev\minimal\http\request,
mirzaev\minimal\http\response,
mirzaev\minimal\http\enumerations\status;
// Built-in libraries
use Closure as closure,
Exception as exception,
RuntimeException as exception_runtime,
BadMethodCallException as exception_method,
DomainException as exception_domain,
InvalidArgumentException as exception_argument,
UnexpectedValueException as exception_value,
LogicException as exception_logic,
Error as error,
ArgumentCountError as error_argument_count,
ReflectionClass as reflection,
ReflectionMethod as reflection_method;
Exception as exception,
RuntimeException as exception_runtime,
BadMethodCallException as exception_method,
DomainException as exception_domain,
InvalidArgumentException as exception_argument,
UnexpectedValueException as exception_value,
LogicException as exception_logic,
ReflectionClass as reflection;
/**
* Core
@@ -37,7 +34,7 @@ use Closure as closure,
* @param model $model An instance of the model
* @param router $router An instance of the router
*
* @method void __construct(?string $namespace) Constructor
* @mathod void __construct(?string $namespace) Constructor
* @method void __destruct() Destructor
* @method string|null start() Initialize request by environment and handle it
* @method string|null request(request $request, array $parameters = []) Handle request
@@ -106,7 +103,9 @@ final class core
/**
* Destructor
*/
public function __destruct() {}
public function __destruct()
{
}
/**
* Start
@@ -258,23 +257,8 @@ 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 = 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);
}
};
$action = fn(): string => (string) $route->controller->{$route->method}(...($route->parameters + $route->variables + $request->parameters));
foreach ($route->middlewares as $middleware) {
// Iterating over the route middlewares

View File

@@ -11,9 +11,6 @@ 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,
@@ -300,50 +297,6 @@ 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->{__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
*
@@ -455,6 +408,9 @@ 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

@@ -10,9 +10,7 @@ use mirzaev\minimal\http\request,
mirzaev\minimal\route;
// Built-in libraries
use Closure as closure,
LogicException as exception_logic
;
use Closure as closure;
/**
* Middleware
@@ -28,14 +26,14 @@ use Closure as closure,
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
*/
class middleware
final class middleware
{
/**
* Function
*
* @var closure|array $function Function
* @var closure $function Function
*/
public readonly closure|array $function;
public readonly closure $function;
/**
* Constructor
@@ -44,28 +42,10 @@ class middleware
*
* @return void
*/
public function __construct(?closure $function = null)
public function __construct(closure $function)
{
if (static::class === self::class) {
// The middleware class itself
// Writing the function
$this->function = $function;
} else {
// The middleware inheriting class
if (method_exists($this, 'middleware')) {
// Found the method
// Writing the function
$this->function = [$this, 'middleware'];
} else {
// Not found the method
// Exit (fail)
throw new exception_logic('The middleware method is not initialized', 500);
}
}
// Writing the function
$this->function = $function;
}
/**
@@ -76,9 +56,9 @@ class middleware
*
* @return string Output
*/
public function __invoke(callable $next, controller $controller): string
{
// Processing the middleware (entering into recursion)
return (string) ($this->function)(next: $next, controller: $controller);
}
public function __invoke(callable $next, controller $controller): string
{
// Processing the middleware (entering into recursion)
return (string) ($this->function)(next: $next, controller: $controller);
}
}

View File

@@ -72,7 +72,7 @@ final class route
// Read
&get => $this->parameters;
}
/**
* Options
*
@@ -113,7 +113,7 @@ final class route
// Read
get => $this->options ?? [];
}
/**
* Parameters
*

View File

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