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.
*
* @var array
* @var array<string, object>
* @since 1.0.0
*/
private array $controllers = [];
public array $controllers = [];
/**
* Constructor.
@ -127,19 +127,4 @@ final class Dispatcher implements DispatcherInterface
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);
if ($this->app->dispatcher !== null) {
$this->app->dispatcher->set($ctrl, $name);
$this->app->dispatcher->controllers[$name] = $ctrl;
}
// Handle providing->receiving

View File

@ -29,7 +29,7 @@ final class SocketRouter implements RouterInterface
/**
* 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
*/
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):
* return [
* '{REGEX_PATH}' => [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'permission' => [ // optional
* 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE},
* 'category' => PermissionCategory::{STATE},
* [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'verb' => RouteVerb::{VERB},
* 'csrf' => true,
* 'permission' => [ // optional
* 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE},
* 'category' => PermissionCategory::{STATE},
* ],
* ],
* // define different destination for different verb
* ],
* // define another regex path, destination, permission here
* ]
* // define another regex path here
* ];
*
* @param string $path Route file path

View File

@ -40,7 +40,7 @@ final class WebRouter implements RouterInterface
/**
* 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
*/
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):
* return [
* '{REGEX_PATH}' => [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'verb' => RouteVerb::{VERB},
* 'csrf' => true,
* 'permission' => [ // optional
* 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE},
* 'category' => PermissionCategory::{STATE},
* [
* 'dest' => '{DESTINATION_NAMESPACE:method}', // use :: for static functions
* 'verb' => RouteVerb::{VERB},
* 'csrf' => true,
* 'permission' => [ // optional
* 'module' => '{NAME}',
* 'type' => PermissionType::{TYPE},
* 'category' => PermissionCategory::{STATE},
* ],
* ],
* // define different destination for different verb
* ],
* // define another regex path, destination, permission here
* ]
* // define another regex path here
* ];
*
* @param string $path Route file path
@ -113,6 +115,7 @@ final class WebRouter implements RouterInterface
'dest' => $destination,
'verb' => $verb,
'csrf' => $csrf,
'active' => true,
'validation' => empty($validation) ? null : $validation,
'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')]
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 function testFunction() { return $this->name; }
}, 'test');
};
$localization = new Localization();