]> git.andy128k.dev Git - ipf.git/commitdiff
more free routes nesting
authorAndrey Kutejko <aku@anahoret.com>
Thu, 21 Aug 2014 09:22:18 +0000 (12:22 +0300)
committerAndrey Kutejko <aku@anahoret.com>
Thu, 21 Aug 2014 09:22:18 +0000 (12:22 +0300)
ipf/router.php

index 2c85ab5fab9cca0e101d21d34417a93d29c81119..84f5950b8d7a7b24cbab9ddfae80a2a8c103327b 100644 (file)
@@ -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'],
                 );
             }
         }