general fixes

This commit is contained in:
Dennis Eichhorn 2024-04-19 02:08:38 +00:00
parent 121e6b4486
commit 189d37580d
5 changed files with 30 additions and 38 deletions

View File

@ -40,10 +40,10 @@ final class Dispatcher implements DispatcherInterface
* *
* Set in the module manager on module initialization. * Set in the module manager on module initialization.
* *
* @var array * @var array<string, object>
* @since 1.0.0 * @since 1.0.0
*/ */
private array $controllers = []; public array $controllers = [];
/** /**
* Constructor. * Constructor.
@ -127,19 +127,4 @@ final class Dispatcher implements DispatcherInterface
return $this->controllers[$controller]; return $this->controllers[$controller];
} }
/**
* Set controller by alias.
*
* @param object $controller Controller
* @param string $name Controller string
*
* @return void
*
* @since 1.0.0
*/
public function set(object $controller, string $name) : void
{
$this->controllers[$name] = $controller;
}
} }

View File

@ -674,7 +674,7 @@ final class ModuleManager
$ctrl = $this->get($module, $ctlName); $ctrl = $this->get($module, $ctlName);
if ($this->app->dispatcher !== null) { if ($this->app->dispatcher !== null) {
$this->app->dispatcher->set($ctrl, $name); $this->app->dispatcher->controllers[$name] = $ctrl;
} }
// Handle providing->receiving // Handle providing->receiving

View File

@ -29,7 +29,7 @@ final class SocketRouter implements RouterInterface
/** /**
* Routes. * Routes.
* *
* @var array<string, array> * @var array<string, array<int, array{dest:string, verb:int, csrf?:bool, active?:bool, permission:array{module:string, type:int, category:int}, validation?:array{}, pattern?:string}>>
* @since 1.0.0 * @since 1.0.0
*/ */
private array $routes = []; private array $routes = [];
@ -40,15 +40,19 @@ final class SocketRouter implements RouterInterface
* Files need to return a php array of the following structure (see PermissionHandlingTrait): * Files need to return a php array of the following structure (see PermissionHandlingTrait):
* return [ * return [
* '{REGEX_PATH}' => [ * '{REGEX_PATH}' => [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions * [
* 'permission' => [ // optional * 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'module' => '{NAME}', * 'verb' => RouteVerb::{VERB},
* 'type' => PermissionType::{TYPE}, * 'csrf' => true,
* 'category' => PermissionCategory::{STATE}, * 'permission' => [ // optional
* 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE},
* 'category' => PermissionCategory::{STATE},
* ],
* ], * ],
* // define different destination for different verb * // define different destination for different verb
* ], * ]
* // define another regex path, destination, permission here * // define another regex path here
* ]; * ];
* *
* @param string $path Route file path * @param string $path Route file path

View File

@ -40,7 +40,7 @@ final class WebRouter implements RouterInterface
/** /**
* Routes. * Routes.
* *
* @var array<string, array> * @var array<string, array<int, array{dest:string, verb:int, csrf?:bool, active?:bool, permission:array{module:string, type:int, category:int}, validation?:array{}, pattern?:string}>>
* @since 1.0.0 * @since 1.0.0
*/ */
private array $routes = []; private array $routes = [];
@ -51,17 +51,19 @@ final class WebRouter implements RouterInterface
* Files need to return a php array of the following structure (see PermissionHandlingTrait): * Files need to return a php array of the following structure (see PermissionHandlingTrait):
* return [ * return [
* '{REGEX_PATH}' => [ * '{REGEX_PATH}' => [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions * [
* 'verb' => RouteVerb::{VERB}, * 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'csrf' => true, * 'verb' => RouteVerb::{VERB},
* 'permission' => [ // optional * 'csrf' => true,
* 'module' => '{NAME}', * 'permission' => [ // optional
* 'type' => PermissionType::{TYPE}, * 'module' => '{NAME}',
* 'category' => PermissionCategory::{STATE}, * 'type' => PermissionType::{TYPE},
* 'category' => PermissionCategory::{STATE},
* ],
* ], * ],
* // define different destination for different verb * // define different destination for different verb
* ], * ]
* // define another regex path, destination, permission here * // define another regex path here
* ]; * ];
* *
* @param string $path Route file path * @param string $path Route file path
@ -113,6 +115,7 @@ final class WebRouter implements RouterInterface
'dest' => $destination, 'dest' => $destination,
'verb' => $verb, 'verb' => $verb,
'csrf' => $csrf, 'csrf' => $csrf,
'active' => true,
'validation' => empty($validation) ? null : $validation, 'validation' => empty($validation) ? null : $validation,
'pattern' => empty($dataPattern) ? null : $dataPattern, 'pattern' => empty($dataPattern) ? null : $dataPattern,
]; ];

View File

@ -51,11 +51,11 @@ final class DispatcherTest extends \PHPUnit\Framework\TestCase
#[\PHPUnit\Framework\Attributes\TestDox('A route can be added and dispatched')] #[\PHPUnit\Framework\Attributes\TestDox('A route can be added and dispatched')]
public function testControllerInputOutput() : void public function testControllerInputOutput() : void
{ {
$this->app->dispatcher->set(new class() extends ModuleAbstract { $this->app->dispatcher->controllers['test'] = new class() extends ModuleAbstract {
public string $name = 'test'; public string $name = 'test';
public function testFunction() { return $this->name; } public function testFunction() { return $this->name; }
}, 'test'); };
$localization = new Localization(); $localization = new Localization();