示例#1
0
 public function testRules()
 {
     $route = new Route('name', 'sourceRoute', 'action');
     $this->assertEquals($route->getRules(), []);
     $route->setRules(['rule1' => '1', 'rule2' => 2]);
     $this->assertEquals($route->getRules(), ['rule1' => '1', 'rule2' => 2]);
     $route->addRule('name', 'value');
     $this->assertEquals($route->getRules(), ['rule1' => '1', 'rule2' => 2, 'name' => 'value']);
     $route->removeRule('rule2');
     $this->assertEquals($route->getRules(), ['rule1' => '1', 'name' => 'value']);
     $this->assertEquals($route->getRuleByName('rule1'), '1');
     $this->assertEquals($route->getRuleByName('name'), 'value');
     $this->assertEquals($route->getRuleByName('unexistent-rule'), null);
 }
示例#2
0
 /**
  * Transforms Route array to Route object.
  * @param  array  $route Route array with details.
  * @return Route
  */
 public function transformArrayToRoute(array $route)
 {
     if (!isset($route['name']) || !isset($route['sourceRoute']) || !isset($route['action'])) {
         throw new InvalidArgumentException('Each Route must contains name, sourceRoute and action indexes.');
     }
     $obj = new Route($route['name'], $route['sourceRoute'], $route['action']);
     if (isset($route['rules'])) {
         $obj->setRules($route['rules']);
     }
     if (isset($route['methods'])) {
         $obj->setMethods($route['methods']);
     }
     if (isset($route['route'])) {
         $obj->setRoute($route['route']);
     }
     if (isset($route['defaults'])) {
         $obj->setDefaults($route['defaults']);
     }
     if (isset($route['extras'])) {
         $obj->setExtras($route['extras']);
     }
     if (isset($route['tokens'])) {
         $obj->setTokens($route['tokens']);
     }
     if (isset($route['arguments'])) {
         $obj->setArguments($route['arguments']);
     }
     return $obj;
 }