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 def4d7c

Browse filesBrowse files
committed
Merge branch '2.3' into 2.4
* 2.3: Revert "bug #9601 [Routing] Remove usage of deprecated _scheme requirement (Danez)"
2 parents 439664d + 146e666 commit def4d7c
Copy full SHA for def4d7c

File tree

Expand file treeCollapse file tree

14 files changed

+34
-219
lines changed
Filter options
Expand file treeCollapse file tree

14 files changed

+34
-219
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RedirectableUrlMatcherTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RedirectableUrlMatcherTest.php
+1-21Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,10 @@ public function testRedirectWhenNoSlash()
3838
);
3939
}
4040

41-
public function testSchemeRedirectBC()
42-
{
43-
$coll = new RouteCollection();
44-
$coll->add('foo', new Route('/foo', array(), array('_scheme' => 'https')));
45-
46-
$matcher = new RedirectableUrlMatcher($coll, $context = new RequestContext());
47-
48-
$this->assertEquals(array(
49-
'_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction',
50-
'path' => '/foo',
51-
'permanent' => true,
52-
'scheme' => 'https',
53-
'httpPort' => $context->getHttpPort(),
54-
'httpsPort' => $context->getHttpsPort(),
55-
'_route' => 'foo',
56-
),
57-
$matcher->match('/foo')
58-
);
59-
}
60-
6141
public function testSchemeRedirect()
6242
{
6343
$coll = new RouteCollection();
64-
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
44+
$coll->add('foo', new Route('/foo', array(), array('_scheme' => 'https')));
6545

6646
$matcher = new RedirectableUrlMatcher($coll, $context = new RequestContext());
6747

‎src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ private function generateDeclaredRoutes()
9292
$properties[] = $route->getRequirements();
9393
$properties[] = $compiledRoute->getTokens();
9494
$properties[] = $compiledRoute->getHostTokens();
95-
$properties[] = $route->getSchemes();
9695

9796
$routes .= sprintf(" '%s' => %s,\n", $name, str_replace("\n", '', var_export($properties, true)));
9897
}
@@ -115,9 +114,9 @@ public function generate(\$name, \$parameters = array(), \$referenceType = self:
115114
throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', \$name));
116115
}
117116
118-
list(\$variables, \$defaults, \$requirements, \$tokens, \$hostTokens, \$requiredSchemes) = self::\$declaredRoutes[\$name];
117+
list(\$variables, \$defaults, \$requirements, \$tokens, \$hostTokens) = self::\$declaredRoutes[\$name];
119118
120-
return \$this->doGenerate(\$variables, \$defaults, \$requirements, \$tokens, \$parameters, \$name, \$referenceType, \$hostTokens, \$requiredSchemes);
119+
return \$this->doGenerate(\$variables, \$defaults, \$requirements, \$tokens, \$parameters, \$name, \$referenceType, \$hostTokens);
121120
}
122121
EOF;
123122
}

‎src/Symfony/Component/Routing/Generator/UrlGenerator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Generator/UrlGenerator.php
+3-20Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ public function generate($name, $parameters = array(), $referenceType = self::AB
137137
// the Route has a cache of its own and is not recompiled as long as it does not get modified
138138
$compiledRoute = $route->compile();
139139

140-
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens(), $route->getSchemes());
140+
return $this->doGenerate($compiledRoute->getVariables(), $route->getDefaults(), $route->getRequirements(), $compiledRoute->getTokens(), $parameters, $name, $referenceType, $compiledRoute->getHostTokens());
141141
}
142142

143143
/**
144144
* @throws MissingMandatoryParametersException When some parameters are missing that are mandatory for the route
145145
* @throws InvalidParameterException When a parameter value for a placeholder is not correct because
146146
* it does not match the requirement
147147
*/
148-
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
148+
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens)
149149
{
150150
$variables = array_flip($variables);
151151
$mergedParams = array_replace($defaults, $this->context->getParameters(), $parameters);
@@ -204,24 +204,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
204204
$schemeAuthority = '';
205205
if ($host = $this->context->getHost()) {
206206
$scheme = $this->context->getScheme();
207-
208-
if ($requiredSchemes) {
209-
$schemeMatched = false;
210-
foreach ($requiredSchemes as $requiredScheme) {
211-
if ($scheme === $requiredScheme) {
212-
$schemeMatched = true;
213-
214-
break;
215-
}
216-
}
217-
218-
if (!$schemeMatched) {
219-
$referenceType = self::ABSOLUTE_URL;
220-
$scheme = current($requiredSchemes);
221-
}
222-
223-
} elseif (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
224-
// We do this for BC; to be removed if _scheme is not supported anymore
207+
if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme !== $req) {
225208
$referenceType = self::ABSOLUTE_URL;
226209
$scheme = $req;
227210
}

‎src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
+7-11Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,14 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
288288
EOF;
289289
}
290290

291-
if ($schemes = $route->getSchemes()) {
291+
if ($scheme = $route->getRequirement('_scheme')) {
292292
if (!$supportsRedirections) {
293-
throw new \LogicException('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.');
293+
throw new \LogicException('The "_scheme" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.');
294294
}
295-
$schemes = str_replace("\n", '', var_export(array_flip($schemes), true));
295+
296296
$code .= <<<EOF
297-
\$requiredSchemes = $schemes;
298-
if (!isset(\$requiredSchemes[\$this->context->getScheme()])) {
299-
return \$this->redirect(\$pathinfo, '$name', key(\$requiredSchemes));
297+
if (\$this->context->getScheme() !== '$scheme') {
298+
return \$this->redirect(\$pathinfo, '$name', '$scheme');
300299
}
301300
302301
@@ -314,11 +313,8 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
314313
}
315314
$vars[] = "array('_route' => '$name')";
316315

317-
$code .= sprintf(
318-
" return \$this->mergeDefaults(array_replace(%s), %s);\n",
319-
implode(', ', $vars),
320-
str_replace("\n", '', var_export($route->getDefaults(), true))
321-
);
316+
$code .= sprintf(" return \$this->mergeDefaults(array_replace(%s), %s);\n"
317+
, implode(', ', $vars), str_replace("\n", '', var_export($route->getDefaults(), true)));
322318

323319
} elseif ($route->getDefaults()) {
324320
$code .= sprintf(" return %s;\n", str_replace("\n", '', var_export(array_replace($route->getDefaults(), array('_route' => $name)), true)));

‎src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ protected function handleRouteRequirements($pathinfo, $name, Route $route)
5656
}
5757

5858
// check HTTP scheme requirement
59-
$scheme = $this->context->getScheme();
60-
$schemes = $route->getSchemes();
61-
if ($schemes && !$route->hasScheme($scheme)) {
62-
return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, current($schemes)));
59+
$scheme = $route->getRequirement('_scheme');
60+
if ($scheme && $this->context->getScheme() !== $scheme) {
61+
return array(self::ROUTE_MATCH, $this->redirect($pathinfo, $name, $scheme));
6362
}
6463

6564
return array(self::REQUIREMENT_MATCH, null);

‎src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
103103
}
104104

105105
// check HTTP scheme requirement
106-
if ($requiredSchemes = $route->getSchemes()) {
107-
$scheme = $this->context->getScheme();
108-
109-
if (!$route->hasScheme($scheme)) {
110-
$this->addTrace(sprintf('Scheme "%s" does not match any of the required schemes ("%s"); the user will be redirected to first required scheme', $scheme, implode(', ', $requiredSchemes)), self::ROUTE_ALMOST_MATCHES, $name, $route);
106+
if ($scheme = $route->getRequirement('_scheme')) {
107+
if ($this->context->getScheme() !== $scheme) {
108+
$this->addTrace(sprintf('Scheme "%s" does not match the requirement ("%s"); the user will be redirected', $this->context->getScheme(), $scheme), self::ROUTE_ALMOST_MATCHES, $name, $route);
111109

112110
return true;
113111
}

‎src/Symfony/Component/Routing/Matcher/UrlMatcher.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Matcher/UrlMatcher.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ protected function handleRouteRequirements($pathinfo, $name, Route $route)
205205
}
206206

207207
// check HTTP scheme requirement
208-
$scheme = $this->context->getScheme();
209-
$status = $route->getSchemes() && !$route->hasScheme($scheme) ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
208+
$scheme = $route->getRequirement('_scheme');
209+
$status = $scheme && $scheme !== $this->context->getScheme() ? self::REQUIREMENT_MISMATCH : self::REQUIREMENT_MATCH;
210210

211211
return array($status, null);
212212
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Route.php
-19Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,25 +247,6 @@ public function setSchemes($schemes)
247247
return $this;
248248
}
249249

250-
/**
251-
* Checks if a scheme requirement has been set.
252-
*
253-
* @param string $scheme
254-
*
255-
* @return Boolean true if the scheme requirement exists, otherwise false
256-
*/
257-
public function hasScheme($scheme)
258-
{
259-
$scheme = strtolower($scheme);
260-
foreach ($this->schemes as $requiredScheme) {
261-
if ($scheme === $requiredScheme) {
262-
return true;
263-
}
264-
}
265-
266-
return false;
267-
}
268-
269250
/**
270251
* Returns the uppercased HTTP methods this route is restricted to.
271252
* So an empty array means that any method is allowed.

‎src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,17 @@ public function match($pathinfo)
321321

322322
// secure
323323
if ($pathinfo === '/secure') {
324-
$requiredSchemes = array ( 'https' => 0,);
325-
if (!isset($requiredSchemes[$this->context->getScheme()])) {
326-
return $this->redirect($pathinfo, 'secure', key($requiredSchemes));
324+
if ($this->context->getScheme() !== 'https') {
325+
return $this->redirect($pathinfo, 'secure', 'https');
327326
}
328327

329328
return array('_route' => 'secure');
330329
}
331330

332331
// nonsecure
333332
if ($pathinfo === '/nonsecure') {
334-
$requiredSchemes = array ( 'http' => 0,);
335-
if (!isset($requiredSchemes[$this->context->getScheme()])) {
336-
return $this->redirect($pathinfo, 'nonsecure', key($requiredSchemes));
333+
if ($this->context->getScheme() !== 'http') {
334+
return $this->redirect($pathinfo, 'nonsecure', 'http');
337335
}
338336

339337
return array('_route' => 'nonsecure');

‎src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Generator/Dumper/PhpGeneratorDumperTest.php
-33Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -114,37 +114,4 @@ public function testDumpForRouteWithDefaults()
114114

115115
$this->assertEquals($url, '/testing');
116116
}
117-
118-
public function testDumpWithSchemeRequirement()
119-
{
120-
$this->routeCollection->add('Test1', new Route('/testing', array(), array(), array(), '', array('ftp', 'https')));
121-
$this->routeCollection->add('Test2', new Route('/testing_bc', array(), array('_scheme' => 'https'))); // BC
122-
123-
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'SchemeUrlGenerator')));
124-
include ($this->testTmpFilepath);
125-
126-
$projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php'));
127-
128-
$absoluteUrl = $projectUrlGenerator->generate('Test1', array(), true);
129-
$absoluteUrlBC = $projectUrlGenerator->generate('Test2', array(), true);
130-
$relativeUrl = $projectUrlGenerator->generate('Test1', array(), false);
131-
$relativeUrlBC = $projectUrlGenerator->generate('Test2', array(), false);
132-
133-
$this->assertEquals($absoluteUrl, 'ftp://localhost/app.php/testing');
134-
$this->assertEquals($absoluteUrlBC, 'https://localhost/app.php/testing_bc');
135-
$this->assertEquals($relativeUrl, 'ftp://localhost/app.php/testing');
136-
$this->assertEquals($relativeUrlBC, 'https://localhost/app.php/testing_bc');
137-
138-
$projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php', 'GET', 'localhost', 'https'));
139-
140-
$absoluteUrl = $projectUrlGenerator->generate('Test1', array(), true);
141-
$absoluteUrlBC = $projectUrlGenerator->generate('Test2', array(), true);
142-
$relativeUrl = $projectUrlGenerator->generate('Test1', array(), false);
143-
$relativeUrlBC = $projectUrlGenerator->generate('Test2', array(), false);
144-
145-
$this->assertEquals($absoluteUrl, 'https://localhost/app.php/testing');
146-
$this->assertEquals($absoluteUrlBC, 'https://localhost/app.php/testing_bc');
147-
$this->assertEquals($relativeUrl, '/app.php/testing');
148-
$this->assertEquals($relativeUrlBC, '/app.php/testing_bc');
149-
}
150117
}

‎src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
+7-47Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -244,40 +244,22 @@ public function testRequiredParamAndEmptyPassed()
244244

245245
public function testSchemeRequirementDoesNothingIfSameCurrentScheme()
246246
{
247-
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http'))); // BC
247+
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http')));
248248
$this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test'));
249249

250-
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https'))); // BC
251-
$this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
252-
253-
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http')));
254-
$this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test'));
255-
256-
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https')));
250+
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https')));
257251
$this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
258252
}
259253

260254
public function testSchemeRequirementForcesAbsoluteUrl()
261255
{
262-
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https'))); // BC
263-
$this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
264-
265-
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http'))); // BC
266-
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
267-
268-
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https')));
256+
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https')));
269257
$this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
270258

271-
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http')));
259+
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http')));
272260
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
273261
}
274262

275-
public function testSchemeRequirementCreatesUrlForFirstRequiredScheme()
276-
{
277-
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('Ftp', 'https')));
278-
$this->assertEquals('ftp://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
279-
}
280-
281263
public function testPathWithTwoStartingSlashes()
282264
{
283265
$routes = $this->getRoutes('test', new Route('//path-and-not-domain'));
@@ -461,27 +443,9 @@ public function testUrlWithInvalidParameterInHostInNonStrictMode()
461443
$this->assertNull($generator->generate('test', array('foo' => 'baz'), false));
462444
}
463445

464-
public function testGenerateNetworkPathBC()
465-
{
466-
$routes = $this->getRoutes('test', new Route('/{name}', array(), array('_scheme' => 'http'), array(), '{locale}.example.com'));
467-
468-
$this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
469-
array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'
470-
);
471-
$this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test',
472-
array('name' =>'Fabien', 'locale' => 'fr', 'query' => 'string'), UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context'
473-
);
474-
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test',
475-
array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context'
476-
);
477-
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
478-
array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested'
479-
);
480-
}
481-
482446
public function testGenerateNetworkPath()
483447
{
484-
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com', array('http')));
448+
$routes = $this->getRoutes('test', new Route('/{name}', array(), array('_scheme' => 'http'), array(), '{locale}.example.com'));
485449

486450
$this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
487451
array('name' =>'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'
@@ -503,8 +467,7 @@ public function testGenerateRelativePath()
503467
$routes->add('article', new Route('/{author}/{article}/'));
504468
$routes->add('comments', new Route('/{author}/{article}/comments'));
505469
$routes->add('host', new Route('/{article}', array(), array(), array(), '{author}.example.com'));
506-
$routes->add('schemeBC', new Route('/{author}', array(), array('_scheme' => 'https'))); // BC
507-
$routes->add('scheme', new Route('/{author}/blog', array(), array(), array(), '', array('https')));
470+
$routes->add('scheme', new Route('/{author}', array(), array('_scheme' => 'https')));
508471
$routes->add('unrelated', new Route('/about'));
509472

510473
$generator = $this->getGenerator($routes, array('host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/'));
@@ -524,12 +487,9 @@ public function testGenerateRelativePath()
524487
$this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host',
525488
array('author' =>'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH)
526489
);
527-
$this->assertSame('https://example.com/app.php/bernhard', $generator->generate('schemeBC',
490+
$this->assertSame('https://example.com/app.php/bernhard', $generator->generate('scheme',
528491
array('author' =>'bernhard'), UrlGeneratorInterface::RELATIVE_PATH)
529492
);
530-
$this->assertSame('https://example.com/app.php/bernhard/blog', $generator->generate('scheme',
531-
array('author' =>'bernhard'), UrlGeneratorInterface::RELATIVE_PATH)
532-
);
533493
$this->assertSame('../../about', $generator->generate('unrelated',
534494
array(), UrlGeneratorInterface::RELATIVE_PATH)
535495
);

0 commit comments

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