/**
  * @covers Brickoo\Component\Routing\Route\RoutePathRegexGenerator::generate
  * @covers Brickoo\Component\Routing\Route\RoutePathRegexGenerator::getRoutePath
  * @covers Brickoo\Component\Routing\Route\RoutePathRegexGenerator::replaceRoutePathWithRulesExpressions
  * @covers Brickoo\Component\Routing\Route\RoutePathRegexGenerator::replaceRoutePathParameter
  * @covers Brickoo\Component\Routing\Route\RoutePathRegexGenerator::getRoutePathRegexTemplates
  */
 public function testGeneratePathRegexFromRouteWithoutRules()
 {
     $expectedRegex = "~^/(articles|artikeln)/(?<articleName>[^/]+)\$~i";
     $aliases = array("articles" => "artikeln");
     $route = new GenericRoute("articles", "/articles/{articleName}", "MyBlog", "displayArticle");
     $routePathRegexGenerator = new RoutePathRegexGenerator($aliases);
     $this->assertEquals($expectedRegex, $routePathRegexGenerator->generate($route));
 }
Ejemplo n.º 2
0
 /** {@inheritDoc} */
 public function matchesRoute(Route $route)
 {
     $this->routeParameters = [];
     if ($doesMatch = $this->isMatchingRoute($this->matchingPath, $this->regexGenerator->generate($route))) {
         $this->routeParameters = $this->collectRouteParameters($route);
     }
     return $doesMatch;
 }
Ejemplo n.º 3
0
 /** {@inheritDoc} */
 public function matchesRoute(Route $route)
 {
     if (!$route instanceof HttpRoute || !$this->isAllowedRoute($route)) {
         return false;
     }
     $this->routeParameters = [];
     if ($doesMatch = $this->isMatchingRoute($this->request->getUri()->getPath(), $this->regexGenerator->generate($route))) {
         $this->routeParameters = $this->collectRouteParameters($route);
     }
     return $doesMatch;
 }
Ejemplo n.º 4
0
 /**
  * Builds an uri string based on the parameters provided.
  * @param string $routeName the route to use for the build
  * @param array $pathParameters the path parameters as key/value pairs
  * @param string $queryString
  * @throws \Brickoo\Component\Routing\Route\Exception\PathNotValidException
  * @internal param string $queryParameters the query parameters
  * @return string the built uri
  */
 public function build($routeName, array $pathParameters = [], $queryString = "")
 {
     Assert::isString($routeName);
     Assert::isString($queryString);
     $route = $this->router->getRoute($routeName);
     $expectedPath = $this->getExpectedRoutePath($route, $pathParameters);
     $matches = [];
     if (preg_match_all($this->regexGenerator->generate($route), $expectedPath, $matches) === 0) {
         throw new PathNotValidException($routeName, $expectedPath);
     }
     return $this->createUriString($expectedPath, $queryString);
 }