Example #1
0
 /**
  * Adds a route to the array of routes with the option of placing it before a specific
  * other named route in the array.
  * @static
  * @param  $name
  * @param  $uri
  * @param  $regex
  * @param  $before
  * @return void
  */
 public static function add($name, $uri, array $regex = NULL, $before = null)
 {
     if (empty($before)) {
         return parent::set($name, $uri, $regex);
     }
     $keys = array_keys(Route::$_routes);
     //Jx_Debug::dump($keys,'route keys before replacement');
     $index = array_search($before, $keys);
     //Jx_Debug::dump($index,'key index');
     if (false !== $index) {
         //Jx_Debug::dump('in right spot');
         $values = array_values(Route::$_routes);
         //Jx_Debug::dump($values,'values before replacement');
         array_splice($keys, $index, 0, $name);
         //Jx_Debug::dump($keys,'route keys after replacement');
         array_splice($values, $index, 0, array(new Route($uri, $regex)));
         //Jx_Debug::dump($values,'values after replacement');
         Route::$_routes = array_combine($keys, $values);
         //Jx_Debug::dump(Route::$_routes,'routes after adding test');
         return Route::$_routes[$name];
     } else {
         //Jx_Debug::dump('in bad spot');
         return parent::set($name, $uri, $regex);
     }
 }
Example #2
0
 public static function cache($save = FALSE, $append = FALSE)
 {
     if ($save === TRUE) {
         try {
             JsonApiApplication::cache('Route::cache()', Route::$_routes);
         } catch (Exception $e) {
             throw new JsonApiApplication_Exception('One or more routes could not be cached (:message)', array(':message' => $e->getMessage()), 0, $e);
         }
     } else {
         if ($routes = JsonApiApplication::cache('Route::cache()')) {
             if ($append) {
                 Route::$_routes += $routes;
             } else {
                 Route::$_routes = $routes;
             }
             return Route::$cache = TRUE;
         } else {
             return Route::$cache = FALSE;
         }
     }
 }
Example #3
0
 /**
  * Saves or loads the route cache.
  *
  * @param   boolean   cache the current routes
  * @return  void      when saving routes
  * @return  boolean   when loading routes
  */
 public static function cache($save = FALSE)
 {
     if ($save === TRUE) {
         // Cache all defined routes
         Kohana::cache('Route::cache()', Route::$_routes);
     } else {
         if ($routes = Kohana::cache('Route::cache()')) {
             Route::$_routes = $routes;
             // Routes were cached
             return TRUE;
         } else {
             // Routes were not cached
             return FALSE;
         }
     }
 }
Example #4
0
 /**
  * Saves or loads the route cache. If your routes will remain the same for
  * a long period of time, use this to reload the routes from the cache
  * rather than redefining them on every page load.
  *
  *     if ( ! Route::cache())
  *     {
  *         // Set routes here
  *         Route::cache(TRUE);
  *     }
  *
  * @param   boolean $save   cache the current routes
  * @param   boolean $append append, rather than replace, cached routes when loading
  * @return  void    when saving routes
  * @return  boolean when loading routes
  * @uses    Kohana::cache
  */
 public static function cache($save = FALSE, $append = FALSE)
 {
     if ($save === TRUE) {
         try {
             // Cache all defined routes
             Kohana::cache('Route::cache()', Route::$_routes);
         } catch (Exception $e) {
             // We most likely have a lambda in a route, which cannot be cached
             throw new Kohana_Exception('One or more routes could not be cached (:message)', array(':message' => $e->getMessage()), 0, $e);
         }
     } else {
         if ($routes = Kohana::cache('Route::cache()')) {
             if ($append) {
                 // Append cached routes
                 Route::$_routes += $routes;
             } else {
                 // Replace existing routes
                 Route::$_routes = $routes;
             }
             // Routes were cached
             return Route::$cache = TRUE;
         } else {
             // Routes were not cached
             return Route::$cache = FALSE;
         }
     }
 }