Example #1
0
 /**
  * Loads a modules routes. If a modules callback only contains two items,
  * the current module name is prepended to the callback.
  */
 public static function load($routes, $module)
 {
     foreach ($routes as &$route) {
         if (isset($route['callback']) && count($route['callback']) == 2) {
             array_unshift($route['callback'], $module);
         }
     }
     self::$_routes = array_merge($routes, self::$_routes);
 }
Example #2
0
 private static function setRoutes($routes)
 {
     self::$_routes = $routes;
 }
Example #3
0
 /**
  * Generates a routed URI from given URI.
  * @param array $segments
  * @return array
  */
 private static function _getRouted(array $segments)
 {
     $ent = Exido::config('global.core.uri_entities');
     if (self::$_routes === null) {
         // Load routes
         self::$_routes = Exido::config('route');
     }
     // Join additional routes
     if (!empty(self::$_additional_routes)) {
         foreach (self::$_additional_routes as $key => $value) {
             self::$_routes->set($key, $value);
         }
     }
     $segments_string = implode('/', $segments);
     // Is there a literal match? If so we're done
     if (isset(self::$_routes[$segments_string])) {
         return explode('/', self::$_routes[$segments_string]);
     }
     $routed_uri = array();
     // Loop through the routes and see if anything matches
     foreach (self::$_routes as $key => $val) {
         if ($key === 'default_controller') {
             continue;
         }
         $key = strtr($key, $ent);
         if (preg_match('#^' . $key . '$#', $segments_string)) {
             // Do we have a back-reference?
             if (strpos($val, '$') !== false and strpos($key, '(') !== false) {
                 $val = preg_replace('#^' . $key . '$#', $val, $segments_string);
             }
             // Change a route
             $routed_uri = explode('/', $val);
             break;
         } else {
             // Get the original route
             $routed_uri = $segments;
         }
     }
     return $routed_uri;
 }