Example #1
0
 /**
  * parseRoute
  *
  * @param string $route
  * @param string $method
  * @param array  $options
  *
  * @throws  \UnexpectedValueException
  * @return  array|boolean
  */
 public function match($route, $method = 'GET', $options = array())
 {
     $matched = parent::match($route, $method, $options);
     $vars = $matched->getVariables();
     if (!array_key_exists('_controller', $vars)) {
         throw new \UnexpectedValueException('Controller not found.', 500);
     }
     $controller = $vars['_controller'];
     unset($vars['_controller']);
     $this->setVariables($vars);
     return $controller;
 }
Example #2
0
 /**
  * Method to test match().
  *
  * @return void
  *
  * @covers Windwalker\Router\Router::match
  */
 public function testMatch()
 {
     $routes = array(new Route(null, 'flower/(id)/(alias)', array('_controller' => 'FlowerController')), new Route('sakura', 'foo/bar(/id,sakura)', array('_controller' => 'SakuraController')));
     $this->instance->addRoutes($routes);
     $result = $this->instance->match('flower/5/foo');
     $this->assertInstanceOf('Windwalker\\Router\\Route', $result);
     $result = $result->getVariables();
     $this->assertEquals('FlowerController', $result['_controller']);
     $this->assertEquals('foo', $result['alias']);
     $result = $this->instance->match('foo/bar/5/baz');
     $this->assertInstanceOf('Windwalker\\Router\\Route', $result);
     $result = $result->getVariables();
     $this->assertEquals('SakuraController', $result['_controller']);
     $this->assertEquals('baz', $result['sakura']);
 }
 /**
  * Match route.
  *
  * @param string $route
  * @param string $method
  * @param array  $options
  *
  * @return  Route|boolean
  */
 public function match($route, $method = 'GET', $options = array())
 {
     $matched = parent::match($route, $method, $options);
     $extra = $matched->getExtra();
     if (isset($extra['parseHandler']) && is_callable($extra['parseHandler'])) {
         $variables = call_user_func_array($extra['parseHandler'], array($matched->getVariables()));
         $matched->setVariables($variables);
     }
     $this->matched = $matched;
     $this->extra->reset()->load($matched->getExtra());
     return $matched;
 }