/**
  * Method to test compile().
  *
  * @param string $pattern
  * @param string $expected
  * @param int    $line
  *
  * @return void
  *
  * @covers Windwalker\Router\Compiler\BasicCompiler::compile
  *
  * @dataProvider  regexList
  */
 public function testCompile($pattern, $expected, $route, $expectedMatches, $line)
 {
     $regex = BasicCompiler::compile($pattern, array('id' => '\\d+'));
     $this->assertEquals(chr(1) . '^' . $expected . '$' . chr(1), $regex, 'Fail at: ' . $line);
     preg_match($regex, $route, $matches);
     $this->assertNotEmpty($matches);
     $vars = RouteHelper::getVariables($matches);
     $this->assertEquals($expectedMatches, $vars);
 }
Beispiel #2
0
 /**
  * Match routes.
  *
  * @param string $route
  * @param Route  $routeItem
  *
  * @return  Route|false
  */
 public function matchRoute($route, Route $routeItem)
 {
     $regex = $routeItem->getRegex();
     if (!$regex || $this->debug) {
         $regex = BasicCompiler::compile($routeItem->getPattern(), $routeItem->getRequirements());
         $routeItem->setRegex($regex);
     }
     $route = RouteHelper::normalise($route);
     if (preg_match($regex, $route, $matches)) {
         $variables = RouteHelper::getVariables($matches);
         $variables['_rawRoute'] = $route;
     } else {
         return false;
     }
     $routeItem->setVariables(array_merge($routeItem->getVariables(), $variables));
     return $routeItem;
 }