Development

Changeset 7625

You must first sign up to be able to contribute.

Changeset 7625

Show
Ignore:
Timestamp:
02/27/08 08:12:30 (1 year ago)
Author:
fabien
Message:

added sfPatternRouting::insertRouteBefore() (based on a patch from francois)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/routing/sfPatternRouting.class.php

    r7617 r7625  
    241241 
    242242  /** 
     243   * Adds a new route before a given one in the current list of routes. 
     244   * 
     245   * @see connect 
     246   */ 
     247  public function insertRouteBefore($pivot, $name, $route, $default = array(), $requirements = array()) 
     248  { 
     249    if (!isset($this->routes[$pivot])) 
     250    { 
     251      throw new sfConfigurationException(sprintf('Unable to insert route "%s" before inexistent route "%s".', $name, $pivot)); 
     252    } 
     253 
     254    $routes = $this->routes; 
     255    $this->routes = array(); 
     256    $newroutes = array(); 
     257    foreach ($routes as $key => $value) 
     258    { 
     259      if ($key == $pivot) 
     260      { 
     261        $newroutes = array_merge($newroutes, $this->connect($name, $route, $default, $requirements)); 
     262      } 
     263      $newroutes[$key] = $value; 
     264    } 
     265 
     266    return $this->routes = $newroutes; 
     267  } 
     268 
     269  /** 
    243270   * Adds a new route at the end of the current list of routes. 
    244271   * 
  • branches/1.1/test/unit/routing/sfPatternRoutingTest.php

    r7616 r7625  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(123, new lime_output_color()); 
     13$t = new lime_test(125, new lime_output_color()); 
    1414 
    1515class sfPatternRoutingTest extends sfPatternRouting 
     
    409409$t->is(implode('-', $p_route_names), implode('-', array_reverse($route_names)), '->prependRoute() adds new routes at the beginning of the existings ones'); 
    410410 
     411// ->addRouteBefore() 
     412$t->diag('->insertRouteBefore()'); 
     413$r->clearRoutes(); 
     414$r->connect('test1', '/:module', array('action' => 'index')); 
     415$r->connect('test3', '/:module/:action/*', array()); 
     416$r->insertRouteBefore('test3', 'test2', '/:module/:action', array('module' => 'default')); 
     417$route_names = array_keys($r->getRoutes()); 
     418$r->clearRoutes(); 
     419$r->connect('test1', '/:module', array('action' => 'index')); 
     420$r->connect('test2', '/:module/:action', array('module' => 'default')); 
     421$r->connect('test3', '/:module/:action/*', array()); 
     422$test_route_names = array_keys($r->getRoutes()); 
     423$t->is(implode('-', $test_route_names), implode('-', $route_names), '->insertRouteBefore() adds a new route before another existings one'); 
     424$r->clearRoutes(); 
     425$msg = '->insertRouteBefore() throws an sfConfigurationException when trying to insert a route before a non existent one'; 
     426try 
     427{ 
     428  $r->insertRouteBefore('test2', 'test', '/index.php/:module/:action', array('module' => 'default', 'action' => 'index')); 
     429  $t->fail($msg); 
     430} 
     431catch (sfConfigurationException $e) 
     432{ 
     433  $t->pass($msg); 
     434} 
     435 
    411436// ->getCurrentInternalUri() 
    412437$t->diag('->getCurrentInternalUri()'); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.