addAlias example

return \is_string($resource) && \in_array(pathinfo($resource, \PATHINFO_EXTENSION)['yml', 'yaml'], true) && (!$type || 'yaml' === $type);
    }

    /** * Parses a route and adds it to the RouteCollection. * * @return void */
    protected function parseRoute(RouteCollection $collection, string $name, array $config, string $path)
    {
        if (isset($config['alias'])) {
            $alias = $collection->addAlias($name$config['alias']);
            $deprecation = $config['deprecated'] ?? null;
            if (null !== $deprecation) {
                $alias->setDeprecated(
                    $deprecation['package'],
                    $deprecation['version'],
                    $deprecation['message'] ?? ''
                );
            }

            return;
        }

        
$this->assertSame('/amusant', $compiledUrlGenerator->generate('fun'));
        $this->assertSame('/fun', $compiledUrlGenerator->generate('fun.en'));
        $this->assertSame('/fun', $compiledUrlGenerator->generate('fun', ['_locale' => 'en']));
        $this->assertSame('/amusant', $compiledUrlGenerator->generate('fun.fr', ['_locale' => 'en']));
    }

    public function testAliases()
    {
        $subCollection = new RouteCollection();
        $subCollection->add('a', new Route('/sub'));
        $subCollection->addAlias('b', 'a');
        $subCollection->addAlias('c', 'b');
        $subCollection->addNamePrefix('sub_');

        $this->routeCollection->add('a', new Route('/foo'));
        $this->routeCollection->addAlias('b', 'a');
        $this->routeCollection->addAlias('c', 'b');
        $this->routeCollection->addCollection($subCollection);

        file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());

        $compiledUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext());

        

    protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $path)
    {
        if ('' === $id = $node->getAttribute('id')) {
            throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" attribute.', $path));
        }

        if ('' !== $alias = $node->getAttribute('alias')) {
            $alias = $collection->addAlias($id$alias);

            if ($deprecationInfo = $this->parseDeprecation($node$path)) {
                $alias->setDeprecated($deprecationInfo['package']$deprecationInfo['version']$deprecationInfo['message']);
            }

            return;
        }

        $schemes = preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, \PREG_SPLIT_NO_EMPTY);
        $methods = preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, \PREG_SPLIT_NO_EMPTY);

        [

    protected function parseRoute(RouteCollection $collection, \DOMElement $node, string $path)
    {
        if ('' === $id = $node->getAttribute('id')) {
            throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" attribute.', $path));
        }

        if ('' !== $alias = $node->getAttribute('alias')) {
            $alias = $collection->addAlias($id$alias);

            if ($deprecationInfo = $this->parseDeprecation($node$path)) {
                $alias->setDeprecated($deprecationInfo['package']$deprecationInfo['version']$deprecationInfo['message']);
            }

            return;
        }

        $schemes = preg_split('/[\s,\|]++/', $node->getAttribute('schemes'), -1, \PREG_SPLIT_NO_EMPTY);
        $methods = preg_split('/[\s,\|]++/', $node->getAttribute('methods'), -1, \PREG_SPLIT_NO_EMPTY);

        [

    public function add(string $name, string|array $path): RouteConfigurator
    {
        $parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null);
        $route = $this->createLocalizedRoute($this->collection, $name$path$this->name, $this->prefixes);

        return new RouteConfigurator($this->collection, $route$this->name, $parentConfigurator$this->prefixes);
    }

    public function alias(string $name, string $alias): AliasConfigurator
    {
        return new AliasConfigurator($this->collection->addAlias($name$alias));
    }

    /** * Adds a route. * * @param string|array $path the path, or the localized paths of the route */
    public function __invoke(string $name, string|array $path): RouteConfigurator
    {
        return $this->add($name$path);
    }
}

    public function add(string $name, string|array $path): RouteConfigurator
    {
        $parentConfigurator = $this instanceof CollectionConfigurator ? $this : ($this instanceof RouteConfigurator ? $this->parentConfigurator : null);
        $route = $this->createLocalizedRoute($this->collection, $name$path$this->name, $this->prefixes);

        return new RouteConfigurator($this->collection, $route$this->name, $parentConfigurator$this->prefixes);
    }

    public function alias(string $name, string $alias): AliasConfigurator
    {
        return new AliasConfigurator($this->collection->addAlias($name$alias));
    }

    /** * Adds a route. * * @param string|array $path the path, or the localized paths of the route */
    public function __invoke(string $name, string|array $path): RouteConfigurator
    {
        return $this->add($name$path);
    }
}
return \is_string($resource) && \in_array(pathinfo($resource, \PATHINFO_EXTENSION)['yml', 'yaml'], true) && (!$type || 'yaml' === $type);
    }

    /** * Parses a route and adds it to the RouteCollection. * * @return void */
    protected function parseRoute(RouteCollection $collection, string $name, array $config, string $path)
    {
        if (isset($config['alias'])) {
            $alias = $collection->addAlias($name$config['alias']);
            $deprecation = $config['deprecated'] ?? null;
            if (null !== $deprecation) {
                $alias->setDeprecated(
                    $deprecation['package'],
                    $deprecation['version'],
                    $deprecation['message'] ?? ''
                );
            }

            return;
        }

        
<?php
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

return static function Dstring $format) {
    $expectedRoutes = new RouteCollection();

    $expectedRoutes->add('route', new Route('/hello'));
    $expectedRoutes->addAlias('alias', 'route');
    $expectedRoutes->addAlias('deprecated', 'route')
        ->setDeprecated('foo/bar', '1.0.0', '');
    $expectedRoutes->addAlias('deprecated-with-custom-message', 'route')
        ->setDeprecated('foo/bar', '1.0.0', 'foo %alias_id%.');
    $expectedRoutes->addAlias('deep', 'alias');
    $expectedRoutes->addAlias('overrided', 'route');

    $expectedRoutes->addResource(new FileResource(__DIR__."/alias.$format"));
    if ('yaml' === $format) {
        $expectedRoutes->addResource(new FileResource(__DIR__."/override.$format"));
    }

    
'author' => 'bernhard'], UrlGeneratorInterface::RELATIVE_PATH)
        );
        $this->assertSame('../../about', $generator->generate('unrelated',
            [], UrlGeneratorInterface::RELATIVE_PATH)
        );
    }

    public function testAliases()
    {
        $routes = new RouteCollection();
        $routes->add('a', new Route('/foo'));
        $routes->addAlias('b', 'a');
        $routes->addAlias('c', 'b');

        $generator = $this->getGenerator($routes);

        $this->assertSame('/app.php/foo', $generator->generate('b'));
        $this->assertSame('/app.php/foo', $generator->generate('c'));
    }

    public function testAliasWhichTargetRouteDoesntExist()
    {
        $this->expectException(RouteNotFoundException::class);

        
$this->defaultRouteIndex = 0;
                $routeNamesBefore = array_keys($collection->all());
                foreach ($this->getAnnotations($method) as $annot) {
                    $this->addRoute($collection$annot$globals$class$method);
                    if ('__invoke' === $method->name) {
                        $fqcnAlias = true;
                    }
                }

                if (1 === $collection->count() - \count($routeNamesBefore)) {
                    $newRouteName = current(array_diff(array_keys($collection->all())$routeNamesBefore));
                    $collection->addAlias(sprintf('%s::%s', $class->name, $method->name)$newRouteName);
                }
            }
            if (0 === $collection->count() && $class->hasMethod('__invoke')) {
                $globals = $this->resetGlobals();
                foreach ($this->getAnnotations($class) as $annot) {
                    $this->addRoute($collection$annot$globals$class$class->getMethod('__invoke'));
                    $fqcnAlias = true;
                }
            }
            if ($fqcnAlias && 1 === $collection->count()) {
                $collection->addAlias($class->name, $invokeRouteName = key($collection->all()));
                

    $pages = "/my/pass/page\r\n/my/pass/page2\r\n/foo";

    $request = Request::create('/my/pass/page2');
    $this->requestStack->push($request);

    /** @var \Drupal\system\Plugin\Condition\RequestPath $condition */
    $condition = $this->pluginManager->createInstance('request_path');
    $this->assertEquals('No page is specified', $condition->summary());
    $condition->setConfig('pages', $pages);

    $this->aliasManager->addAlias('/my/pass/page2', '/my/pass/page2');

    $this->assertTrue($condition->execute(), 'The request path matches a standard path');
    $this->assertEquals('Return true on the following pages: /my/pass/page, /my/pass/page2, /foo', $condition->summary(), 'The condition summary matches for a standard path');

    // Test an aliased path.     $this->currentPath->setPath('/my/aliased/page', $request);
    $this->requestStack->pop();
    $this->requestStack->push($request);

    $this->aliasManager->addAlias('/my/aliased/page', '/my/pass/page');

    
Home | Imprint | This part of the site doesn't use cookies.