Skip to content

[Routing][i18n] Wrong PHP format example #10762

Closed
@fsevestre

Description

@fsevestre

Hello,

There are some issues in the PHP format example (https://github.com/symfony/symfony-docs/blame/e350b3efcfadbb26ab51768e5f6a2bcb07d9dc14/routing.rst#L260) which don't generate the same result as the YAML or the XML formats examples.


# config/routes/annotations.yaml

controllers:
    resource: ../../src/Controller/
    type: annotation
    prefix:
        en: '' # don't prefix URLs for English, the default locale
        nl: '/nl'
        it: '/it'
// var/cache/dev/srcApp_KernelDevDebugContainerUrlMatcher

<?php

use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;

/**
 * This class has been auto-generated
 * by the Symfony Routing Component.
 */
class srcApp_KernelDevDebugContainerUrlMatcher extends Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher
{
    use PhpMatcherTrait;

    public function __construct(RequestContext $context)
    {
        $this->context = $context;
        $this->staticRoutes = array(
            '/' => array(array(array('_route' => 'app_default_index', '_controller' => 'App\\Controller\\DefaultController::index', '_locale' => 'en'), null, null, null, false, null)),
            '/nl' => array(array(array('_route' => 'app_default_index', '_controller' => 'App\\Controller\\DefaultController::index', '_locale' => 'nl'), null, null, null, true, null)),
            '/it' => array(array(array('_route' => 'app_default_index', '_controller' => 'App\\Controller\\DefaultController::index', '_locale' => 'it'), null, null, null, true, null)),
            '/test' => array(array(array('_route' => 'app_default_index2', '_controller' => 'App\\Controller\\DefaultController::index2', '_locale' => 'en'), null, null, null, false, null)),
            '/nl/test' => array(array(array('_route' => 'app_default_index2', '_controller' => 'App\\Controller\\DefaultController::index2', '_locale' => 'nl'), null, null, null, false, null)),
            '/it/test' => array(array(array('_route' => 'app_default_index2', '_controller' => 'App\\Controller\\DefaultController::index2', '_locale' => 'it'), null, null, null, false, null)),
        );
        $this->regexpList = array(
            0 => '{^(?'
                    .'|/_error/(\\d+)(?:\\.([^/]++))?(*:35)'
                .')(?:/?)$}sDu',
        );
        $this->dynamicRoutes = array(
            35 => array(array(array('_route' => '_twig_error_test', '_controller' => 'twig.controller.preview_error::previewErrorPageAction', '_format' => 'html'), array('code', '_format'), null, null, false, null)),
        );
    }
}
php bin/console debug:router

 ----------------------- -------- -------- ------ -------------------------- 
  Name                    Method   Scheme   Host   Path                      
 ----------------------- -------- -------- ------ -------------------------- 
  app_default_index.en    ANY      ANY      ANY    /                         
  app_default_index.nl    ANY      ANY      ANY    /nl/                      
  app_default_index.it    ANY      ANY      ANY    /it/                      
  app_default_index2.en   ANY      ANY      ANY    /test                     
  app_default_index2.nl   ANY      ANY      ANY    /nl/test                  
  app_default_index2.it   ANY      ANY      ANY    /it/test                  
  _twig_error_test        ANY      ANY      ANY    /_error/{code}.{_format}  
 ----------------------- -------- -------- ------ --------------------------

// config/routes/annotations.php

<?php

use Symfony\Component\Routing\RouteCollection;

/** @var RouteCollection $routes */
$routes = $loader->import('../../src/Controller/', 'annotation');

$routes->addPrefix('/', array('_locale' => 'en'));
$routes->addPrefix('/nl', array('_locale' => 'nl'));
$routes->addPrefix('/it', array('_locale' => 'it'));

return $routes;
// var/cache/dev/srcApp_KernelDevDebugContainerUrlMatcher

<?php

use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherTrait;
use Symfony\Component\Routing\RequestContext;

/**
 * This class has been auto-generated
 * by the Symfony Routing Component.
 */
class srcApp_KernelDevDebugContainerUrlMatcher extends Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher
{
    use PhpMatcherTrait;

    public function __construct(RequestContext $context)
    {
        $this->context = $context;
        $this->staticRoutes = array(
            '/it/nl' => array(array(array('_route' => 'app_default_index', '_controller' => 'App\\Controller\\DefaultController::index', '_locale' => 'it'), null, null, null, true, null)),
            '/it/nl/test' => array(array(array('_route' => 'app_default_index2', '_controller' => 'App\\Controller\\DefaultController::index2', '_locale' => 'it'), null, null, null, false, null)),
        );
        $this->regexpList = array(
            0 => '{^(?'
                    .'|/_error/(\\d+)(?:\\.([^/]++))?(*:35)'
                .')(?:/?)$}sDu',
        );
        $this->dynamicRoutes = array(
            35 => array(array(array('_route' => '_twig_error_test', '_controller' => 'twig.controller.preview_error::previewErrorPageAction', '_format' => 'html'), array('code', '_format'), null, null, false, null)),
        );
    }
}
php bin/console debug:router

 -------------------- -------- -------- ------ -------------------------- 
  Name                 Method   Scheme   Host   Path                      
 -------------------- -------- -------- ------ -------------------------- 
  app_default_index    ANY      ANY      ANY    /it/nl/                   
  app_default_index2   ANY      ANY      ANY    /it/nl/test               
  _twig_error_test     ANY      ANY      ANY    /_error/{code}.{_format}  
 -------------------- -------- -------- ------ --------------------------

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions