예제 #1
0
 public function testEventOptional()
 {
     $router = new DynamicRouter($this->context, $this->matcher, $this->generator);
     $parameters = $router->matchRequest($this->request);
     $this->assertEquals(array('foo' => 'bar'), $parameters);
     $this->assertRequestAttributes($this->request);
 }
예제 #2
0
 /**
  * @param string|Meta     $name
  * @param array           $parameters
  * @param bool|int|string $referenceType
  *
  * @return mixed|string
  *
  * @throws RouteNotFoundException
  */
 public function generate($name, $parameters = [], $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
 {
     $cacheKey = $this->getCacheKey($name, $parameters, $referenceType);
     if (array_key_exists($cacheKey, $this->internalRoutesCache)) {
         return $this->internalRoutesCache[$cacheKey];
     }
     if ($name instanceof Meta && $name->getValues() instanceof ArticleInterface) {
         $parameters['slug'] = $name->getValues()->getSlug();
         $route = $name->getValues()->getRoute();
         if (null === $route && $name->getContext()->getCurrentPage()) {
             $parameters['slug'] = null;
             $route = $name->getContext()->getCurrentPage()->getValues();
         }
     } elseif ($name instanceof Meta && $name->getValues() instanceof RouteInterface) {
         $route = $name->getValues();
     } else {
         $route = $name;
     }
     if (null === $route) {
         throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
     }
     $result = parent::generate($route, $parameters, $referenceType);
     $this->internalRoutesCache[$cacheKey] = $result;
     unset($route, $name, $parameters);
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function generate($name, $parameters = [], $referenceType = false)
 {
     if (null === $name && isset($parameters['content_id'])) {
         $contentId = $this->checkAndRemoveFirstSlash($parameters['content_id']);
         $parameters['content_id'] = $this->pathBuilder->build('/', $contentId);
     }
     if (is_string($name)) {
         $name = (string) $this->pathBuilder->build($this->checkAndRemoveFirstSlash($name));
     }
     return parent::generate($name, $parameters, $referenceType);
 }