Router::promote PHP Method

promote() public static method

Promote a route (by default, the last one added) to the beginning of the list
public static promote ( integer $which = null ) : boolean
$which integer A zero-based array index representing the route to move. For example, if 3 routes have been added, the last route would be 2.
return boolean Returns false if no route exists at the position specified by $which.
    public static function promote($which = null)
    {
        if ($which === null) {
            $which = count(static::$routes) - 1;
        }
        if (!isset(static::$routes[$which])) {
            return false;
        }
        $route =& static::$routes[$which];
        unset(static::$routes[$which]);
        array_unshift(static::$routes, $route);
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * testHomeRoute
  */
 public function testHomeRoute()
 {
     $promoted = array('plugin' => 'nodes', 'controller' => 'nodes', 'action' => 'promoted');
     $result = CroogoRouter::connect('/', $promoted);
     $translateLoaded = CakePlugin::loaded('Translate');
     $expected = $translateLoaded ? 2 : 1;
     $this->assertEquals($expected, count($result));
     $this->assertNotEmpty($result[0]);
     $this->assertInstanceOf('CakeRoute', $result[0]);
     $reversed = Router::parse('/');
     $this->assertEquals($promoted, array_intersect_key($promoted, $reversed));
     // another route
     $index = array('plugin' => 'nodes', 'controller' => 'nodes', 'action' => 'index');
     $result = CroogoRouter::connect('/nodes', $index);
     $expected = $translateLoaded ? 4 : 2;
     $this->assertEquals($expected, count($result));
     $reversed = Router::parse('/');
     $this->assertEquals($promoted, array_intersect_key($promoted, $reversed));
     $terms = array('plugin' => 'nodes', 'controller' => 'nodes', 'action' => 'terms');
     $result = CroogoRouter::connect('/', $terms);
     $expected = $translateLoaded ? 6 : 3;
     $this->assertEquals($expected, count($result));
     // override '/' route
     Router::promote();
     $reversed = Router::parse('/');
     $this->assertEquals($terms, array_intersect_key($terms, $reversed));
 }
All Usage Examples Of Router::promote