{"action":"created","issue":{"url":"https://api.github.com/repos/auraphp/Aura.Router/issues/106","labels_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/106/labels{/name}","comments_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/106/comments","events_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/106/events","html_url":"https://github.com/auraphp/Aura.Router/issues/106","id":103777476,"number":106,"title":"[NFR 3.x] Load route definitions from array","user":{"login":"iotch","id":2292500,"avatar_url":"https://avatars.githubusercontent.com/u/2292500?v=3","gravatar_id":"","url":"https://api.github.com/users/iotch","html_url":"https://github.com/iotch","followers_url":"https://api.github.com/users/iotch/followers","following_url":"https://api.github.com/users/iotch/following{/other_user}","gists_url":"https://api.github.com/users/iotch/gists{/gist_id}","starred_url":"https://api.github.com/users/iotch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iotch/subscriptions","organizations_url":"https://api.github.com/users/iotch/orgs","repos_url":"https://api.github.com/users/iotch/repos","events_url":"https://api.github.com/users/iotch/events{/privacy}","received_events_url":"https://api.github.com/users/iotch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-08-28T19:05:00Z","updated_at":"2015-08-29T10:48:30Z","closed_at":null,"body":"Hello.\r\nWill be great to have the ability to load route definitions from an array, like so:\r\n\r\n````php\r\n$routes = [\r\n    'route' => [\r\n        '__arguments' => ['test.route', '/{controller}{/action,id}', function($request, $response, $next) { \r\n            return $next($request, $response);\r\n        }],\r\n        'tokens' => [\r\n            '__arguments' => [\r\n                [\r\n                    'id' => '\\d{2,}'\r\n                ]\r\n            ]\r\n        ]\r\n    ]\r\n];\r\n\r\n$routerContainer = \\Aura\\Router\\RouterContainer('/', $routes);\r\n````\r\nThis will lead to easier configuration within the DI container, IMO.\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/auraphp/Aura.Router/issues/comments/135970192","html_url":"https://github.com/auraphp/Aura.Router/issues/106#issuecomment-135970192","issue_url":"https://api.github.com/repos/auraphp/Aura.Router/issues/106","id":135970192,"user":{"login":"iotch","id":2292500,"avatar_url":"https://avatars.githubusercontent.com/u/2292500?v=3","gravatar_id":"","url":"https://api.github.com/users/iotch","html_url":"https://github.com/iotch","followers_url":"https://api.github.com/users/iotch/followers","following_url":"https://api.github.com/users/iotch/following{/other_user}","gists_url":"https://api.github.com/users/iotch/gists{/gist_id}","starred_url":"https://api.github.com/users/iotch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iotch/subscriptions","organizations_url":"https://api.github.com/users/iotch/orgs","repos_url":"https://api.github.com/users/iotch/repos","events_url":"https://api.github.com/users/iotch/events{/privacy}","received_events_url":"https://api.github.com/users/iotch/received_events","type":"User","site_admin":false},"created_at":"2015-08-29T10:48:30Z","updated_at":"2015-08-29T10:48:30Z","body":"@harikt, thanks for the reference!\r\n\r\nCurrently I'm using this approach (sample dispatcher class code):\r\n\r\n````php\r\n    public function __construct(string $basepath, array $routes = [])\r\n    {\r\n        $this->routerContainer = new RouterContainer($basepath);\r\n\r\n        $this->compileRoutes($routes);\r\n    }\r\n\r\n    protected function compileRoutes()\r\n    {\r\n        try {\r\n            if(! empty($this->routes)) {\r\n                $this->routesMapper($this->routes, $this->routerContainer->getMap());\r\n            }\r\n            \r\n        } catch(\\Throwable $t) {\r\n            throw new Exception('Failed to load routes from definitions array', null, $t);\r\n        }\r\n    }\r\n    \r\n    protected function routesMapper(array $arr, $target, string $args_key = '__arguments')\r\n    {\r\n        foreach($arr as $key => $val) {           \r\n            if($key !== $args_key) {\r\n                $arguments = $val[$args_key] ?? [];\r\n                $target = $target->$key(...$arguments);                     \r\n                $this->routesMapper($val, $target, $args_key);\r\n            }\r\n        }\r\n    }\r\n````\r\n\r\nIt's about 15% slower, than regular routes setup, but that's ok. As far as I can tell it works with all `Map` public methods,but I may miss something, of course."}}