/** * 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); } }
/** * Stores a named route and returns it. The "action" will always be set to * "index" if it is not defined. * * Route::set('default', '(<controller>(/<action>(/<id>)))') * ->defaults(array( * 'controller' => 'welcome', * )); * * @param $name string route name * @param $uri string URI pattern * @param $regex array regex patterns for route keys * @param $options array Optional method and resource for the route * @return Route */ public static function set($name, $uri = NULL, $regex = NULL, array $options = array()) { $route = parent::set($name, $uri, $regex); $route->_resource_name = Arr::get($options, 'resource'); $route->method(Arr::get($options, 'method')); if ($route->_method) { $route->filter(array('Resource_Route', 'is_method_allowed')); } return $route; }