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'],
);
}
}