Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Improve localized routes performances #35855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 8 src/Symfony/Component/Routing/RouteCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ public static function compile(Route $route)
$hostRegex = $result['regex'];
}

$locale = $route->getDefault('_locale');
if (null !== $locale && null !== $route->getDefault('_canonical_route') && preg_quote($locale, self::REGEX_DELIMITER) === $route->getRequirement('_locale')) {
$requirements = $route->getRequirements();
unset($requirements['_locale']);
$route->setRequirements($requirements);
$route->setPath(str_replace('{_locale}', $locale, $route->getPath()));
}

$path = $route->getPath();

$result = self::compilePattern($route, $path, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* This file has been auto-generated
* by the Symfony Routing Component.
*/

return [
false, // $matchHost
[ // $staticRoutes
'/fr/accueil' => [[['_route' => 'home', '_locale' => 'fr'], null, null, null, false, false, null]],
'/en/home' => [[['_route' => 'home', '_locale' => 'en'], null, null, null, false, false, null]],
],
[ // $regexpList
],
[ // $dynamicRoutes
],
null, // $checkCondition
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
use Symfony\Component\Routing\Loader\PhpFileLoader;
use Symfony\Component\Routing\Matcher\CompiledUrlMatcher;
use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
Expand Down Expand Up @@ -442,21 +445,34 @@ public function getRouteCollections()
$hostCollection->add('r1', (new Route('abc{foo}'))->setHost('{foo}.exampple.com'));
$hostCollection->add('r2', (new Route('abc{foo}'))->setHost('{foo}.exampple.com'));

/* test case 14 */
$fixedLocaleCollection = new RouteCollection();
$routes = new RoutingConfigurator($fixedLocaleCollection, new PhpFileLoader(new FileLocator()), __FILE__, __FILE__);
$routes
->collection()
->prefix('/{_locale}')
->add('home', [
'fr' => 'accueil',
'en' => 'home',
])
;

return [
[new RouteCollection(), 'compiled_url_matcher0.php'],
[$collection, 'compiled_url_matcher1.php'],
[$redirectCollection, 'compiled_url_matcher2.php'],
[$rootprefixCollection, 'compiled_url_matcher3.php'],
[$headMatchCasesCollection, 'compiled_url_matcher4.php'],
[$groupOptimisedCollection, 'compiled_url_matcher5.php'],
[$trailingSlashCollection, 'compiled_url_matcher6.php'],
[$trailingSlashCollection, 'compiled_url_matcher7.php'],
[$unicodeCollection, 'compiled_url_matcher8.php'],
[$hostTreeCollection, 'compiled_url_matcher9.php'],
[$chunkedCollection, 'compiled_url_matcher10.php'],
[$demoCollection, 'compiled_url_matcher11.php'],
[$suffixCollection, 'compiled_url_matcher12.php'],
[$hostCollection, 'compiled_url_matcher13.php'],
[new RouteCollection(), 'compiled_url_matcher0.php'],
[$collection, 'compiled_url_matcher1.php'],
[$redirectCollection, 'compiled_url_matcher2.php'],
[$rootprefixCollection, 'compiled_url_matcher3.php'],
[$headMatchCasesCollection, 'compiled_url_matcher4.php'],
[$groupOptimisedCollection, 'compiled_url_matcher5.php'],
[$trailingSlashCollection, 'compiled_url_matcher6.php'],
[$trailingSlashCollection, 'compiled_url_matcher7.php'],
[$unicodeCollection, 'compiled_url_matcher8.php'],
[$hostTreeCollection, 'compiled_url_matcher9.php'],
[$chunkedCollection, 'compiled_url_matcher10.php'],
[$demoCollection, 'compiled_url_matcher11.php'],
[$suffixCollection, 'compiled_url_matcher12.php'],
[$hostCollection, 'compiled_url_matcher13.php'],
[$fixedLocaleCollection, 'compiled_url_matcher14.php'],
];
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.