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

Commit 6a96afd

Browse filesBrowse files
committed
bug #47855 [Routing] TypeError in Router when using UrlGenerator (Maximilian.Beckers)
This PR was merged into the 5.4 branch. Discussion ---------- [Routing] TypeError in Router when using UrlGenerator | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47844 | License | MIT | Doc PR | Fix the array_merge problem when using the `UrlGenerator ` and not the `CompiledUrlGenerator`. For more details about the bug see the issue #47844 Commits ------- 3a20334 Fix TypeError in Router when using UrlGenerator
2 parents 429bfbb + 3a20334 commit 6a96afd
Copy full SHA for 6a96afd

File tree

Expand file treeCollapse file tree

2 files changed

+16
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-4
lines changed

‎src/Symfony/Component/Routing/Router.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Router.php
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,12 @@ public function getGenerator()
313313

314314
if (null === $this->options['cache_dir']) {
315315
$routes = $this->getRouteCollection();
316-
$aliases = [];
317316
$compiled = is_a($this->options['generator_class'], CompiledUrlGenerator::class, true);
318317
if ($compiled) {
319318
$generatorDumper = new CompiledUrlGeneratorDumper($routes);
320-
$routes = $generatorDumper->getCompiledRoutes();
321-
$aliases = $generatorDumper->getCompiledAliases();
319+
$routes = array_merge($generatorDumper->getCompiledRoutes(), $generatorDumper->getCompiledAliases());
322320
}
323-
$this->generator = new $this->options['generator_class'](array_merge($routes, $aliases), $this->context, $this->logger, $this->defaultLocale);
321+
$this->generator = new $this->options['generator_class']($routes, $this->context, $this->logger, $this->defaultLocale);
324322
} else {
325323
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/url_generating_routes.php',
326324
function (ConfigCacheInterface $cache) {

‎src/Symfony/Component/Routing/Tests/RouterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/RouterTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
1616
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
1718
use Symfony\Component\Routing\Generator\UrlGenerator;
1819
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1920
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
@@ -124,11 +125,24 @@ public function testGeneratorIsCreatedIfCacheIsNotConfigured()
124125
{
125126
$this->router->setOption('cache_dir', null);
126127

128+
$this->loader->expects($this->once())
129+
->method('load')->with('routing.yml', null)
130+
->willReturn(new RouteCollection());
131+
132+
$this->assertInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
133+
}
134+
135+
public function testGeneratorIsCreatedIfCacheIsNotConfiguredNotCompiled()
136+
{
137+
$this->router->setOption('cache_dir', null);
138+
$this->router->setOption('generator_class', UrlGenerator::class);
139+
127140
$this->loader->expects($this->once())
128141
->method('load')->with('routing.yml', null)
129142
->willReturn(new RouteCollection());
130143

131144
$this->assertInstanceOf(UrlGenerator::class, $this->router->getGenerator());
145+
$this->assertNotInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
132146
}
133147

134148
public function testMatchRequestWithUrlMatcherInterface()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.