From: Andrey Kutejko Date: Thu, 21 Aug 2014 09:22:18 +0000 (+0300) Subject: more free routes nesting X-Git-Tag: 0.6~177 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=60cd5c0eb02bf29b9a6095002418bb9f659bd0f1;p=ipf.git more free routes nesting --- diff --git a/ipf/router.php b/ipf/router.php index 2c85ab5..84f5950 100644 --- a/ipf/router.php +++ b/ipf/router.php @@ -6,19 +6,25 @@ class IPF_Router public function __construct() { - foreach (IPF::get('urls') as $url) { - $prefix = $url['prefix']; - foreach ($url['urls'] as $suburl) { - if (isset($suburl['regex'])) - $matcher = new IPF_Router_RegexMatch($prefix . $suburl['regex']); - elseif (isset($suburl['expr'])) - $matcher = RouteExpression::compile($prefix . $suburl['expr']); + $this->flattenRoutes(IPF::get('urls')); + } + + private function flattenRoutes($routes, $prefix='') + { + foreach ($routes as $route) { + if (isset($route['prefix'])) { + $this->flattenRoutes($route['urls'], $prefix . $route['prefix']); + } else { + if (isset($route['regex'])) + $matcher = new IPF_Router_RegexMatch($prefix . $route['regex']); + elseif (isset($route['expr'])) + $matcher = RouteExpression::compile($prefix . $route['expr']); else throw new IPF_Exception('Unsupported route type'); $this->routes[] = array( $matcher, - $suburl['func'], + $route['func'], ); } }