public function testMagic()
 {
     $magic = new RouteParameterMatchGenerator();
     $path = '/something/:id/:name';
     $actual = $magic->getRegexPattern($path);
     $expected = '/^\\/something\\/(?P<id>[^\\/]+)\\/(?P<name>[^\\/]+)$/';
     $this->assertEquals($expected, $actual);
 }
Exemple #2
0
 /**
  * @param string $effectiveUri
  *
  * @return Route
  * @throws PathNotFoundException When it was not possible to find a matching route.
  */
 private function getResolvedRoute($effectiveUri)
 {
     foreach (array_keys($this->routingTable) as $path) {
         $pattern = $this->magic->getRegexPattern($path);
         if (preg_match($pattern, $effectiveUri, $matches) === 1) {
             array_pop($matches);
             if (count($matches) > 0) {
                 return $this->routingTable[$path];
             }
         }
     }
     throw new PathNotFoundException($effectiveUri);
 }