diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index 58d094413..4d6a66c74 100755 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -40,10 +40,10 @@ final class Dispatcher implements DispatcherInterface * * Set in the module manager on module initialization. * - * @var array + * @var array * @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; - } } diff --git a/Module/ModuleManager.php b/Module/ModuleManager.php index cf1ed8c2d..525edccd6 100755 --- a/Module/ModuleManager.php +++ b/Module/ModuleManager.php @@ -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 diff --git a/Router/SocketRouter.php b/Router/SocketRouter.php index 84a4fa2a4..a5fae2caf 100755 --- a/Router/SocketRouter.php +++ b/Router/SocketRouter.php @@ -29,7 +29,7 @@ final class SocketRouter implements RouterInterface /** * Routes. * - * @var array + * @var array> * @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 diff --git a/Router/WebRouter.php b/Router/WebRouter.php index 68b158566..109d70970 100755 --- a/Router/WebRouter.php +++ b/Router/WebRouter.php @@ -40,7 +40,7 @@ final class WebRouter implements RouterInterface /** * Routes. * - * @var array + * @var array> * @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, ]; diff --git a/tests/Dispatcher/DispatcherTest.php b/tests/Dispatcher/DispatcherTest.php index b4efb4301..cab39db59 100755 --- a/tests/Dispatcher/DispatcherTest.php +++ b/tests/Dispatcher/DispatcherTest.php @@ -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();