8000 Merge branch '4.0' · symfony/symfony@f06fa04 · GitHub
[go: up one dir, main page]

Skip to content

Commit f06fa04

Browse files
Merge branch '4.0'
* 4.0: Fix typos [Routing] remove useless failing mocks [appveyor] Workaround GitHub disabling of low versions of TLS Use long array syntax [Routing] Fix GC control of PHP-DSL [Routing] Don't throw 405 when scheme requirement doesn't match [Routing] Revert throwing 405 on missed slash/scheme redirections [WebProfilerBundle] fix test after ajax path updated Fix ArrayInput::toString() for InputArgument::IS_ARRAY args Update excluded_ajax_paths for sf4 Add missing use for RoleInterface Add missing use of Role [Routing] fix CS add container.autowiring.strict_mode to 3.4 docs Set controller without __invoke method from invokable class [VarDumper] Fixed PHPDoc
2 parents cd5f410 + 8d9d7e7 commit f06fa04

File tree

23 files changed

+159
-84
lines changed

23 files changed

+159
-84
lines changed

src/Symfony/Bundle/FrameworkBundle/Routing/AnnotatedRouteControllerLoader.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader
2929
*/
3030
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
3131
{
32-
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
32+
if ('__invoke' === $method->getName()) {
33+
$route->setDefault('_controller', $class->getName());
34+
} else {
35+
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
36+
}
3337
}
3438

3539
/**

src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getConfigTreeBuilder()
3838
->children()
3939
->booleanNode('toolbar')->defaultFalse()->end()
4040
->booleanNode('intercept_redirects')->defaultFalse()->end()
41-
->scalarNode('excluded_ajax_paths')->defaultValue('^/(app(_[\\w]+)?\\.php/)?_wdt')->end()
41+
->scalarNode('excluded_ajax_paths')->defaultValue('^/((index|app(_[\w]+)?)\.php/)?_wdt')->end()
4242
->end()
4343
;
4444

src/Symfony/Bundle/WebProfilerBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public function testConfigTree($options, $results)
3232
public function getDebugModes()
3333
{
3434
return array(
35-
array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
36-
array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
37-
array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
38-
array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
35+
array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
36+
array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
37+
array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
38+
array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'excluded_ajax_paths' => '^/((index|app(_[\w]+)?)\.php/)?_wdt')),
3939
array(array('excluded_ajax_paths' => 'test'), array('intercept_redirects' => false, 'toolbar' => false, 'excluded_ajax_paths' => 'test')),
4040
);
4141
}

src/Symfony/Component/Console/Input/ArrayInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function __toString()
114114
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
115115
}
116116
} else {
117-
$params[] = is_array($val) ? array_map(array($this, 'escapeToken'), $val) : $this->escapeToken($val);
117+
$params[] = is_array($val) ? implode(' ', array_map(array($this, 'escapeToken'), $val)) : $this->escapeToken($val);
118118
}
119119
}
120120

src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,8 @@ public function testToString()
170170

171171
$input = new ArrayInput(array('-b' => array('bval_1', 'bval_2'), '--f' => array('fval_1', 'fval_2')));
172172
$this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2& F42D #39;, (string) $input);
173+
174+
$input = new ArrayInput(array('array_arg' => array('val_1', 'val_2')));
175+
$this->assertSame('val_1 val_2', (string) $input);
173176
}
174177
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testProcessedEnvsAreIncompatibleWithResolve()
110110
{
111111
$container = new ContainerBuilder();
112112
$container->registerExtension(new BarExtension());
113-
$container->prependExtensionConfig('bar', []);
113+
$container->prependExtensionConfig('bar', array());
114114

115115
(new MergeExtensionConfigurationPass())->process($container);
116116
}

src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ class CollectionConfigurator
2323
use Traits\RouteTrait;
2424

2525
private $parent;
26+
private $parentConfigurator;
2627

27-
public function __construct(RouteCollection $parent, string $name)
28+
public function __construct(RouteCollection $parent, string $name, self $parentConfigurator = null)
2829
{
2930
$this->parent = $parent;
3031
$this->name = $name;
3132
$this->collection = new RouteCollection();
3233
$this->route = new Route('');
34+
$this->parentConfigurator = $parentConfigurator; // for GC control
3335
}
3436

3537
public function __destruct()
@@ -45,7 +47,7 @@ final public function add(string $name, string $path): RouteConfigurator
4547
{
4648
$this->collection->add($this->name.$name, $route = clone $this->route);
4749

48-
return new RouteConfigurator($this->collection, $route->setPath($path), $this->name);
50+
return new RouteConfigurator($this->collection, $route->setPath($path), $this->name, $this);
4951
}
5052

5153
/**
@@ -55,7 +57,7 @@ final public function add(string $name, string $path): RouteConfigurator
5557
*/
5658
final public function collection($name = '')
5759
{
58-
return new self($this->collection, $this->name.$name);
60+
return new self($this->collection, $this->name.$name, $this);
5961
}
6062

6163
/**

src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ class RouteConfigurator
2222
use Traits\AddTrait;
2323
use Traits\RouteTrait;
2424

25-
public function __construct(RouteCollection $collection, Route $route, string $name = '')
25+
public function __construct(RouteCollection $collection, Route $route, string $name = '', CollectionConfigurator $parentConfigurator = null)
2626
{
2727
$this->collection = $collection;
2828
$this->route = $route;
2929
$this->name = $name;
30+
$this->parentConfigurator = $parentConfigurator; // for GC control
3031
}
3132
}

src/Symfony/Component/Routing/Loader/Configurator/Traits/AddTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ trait AddTrait
2929
*/
3030
final public function add(string $name, string $path): RouteConfigurator
3131
{
32+
$parentConfigurator = $this instanceof RouteConfigurator ? $this->parentConfigurator : null;
3233
$this->collection->add($this->name.$name, $route = new Route($path));
3334

34-
return new RouteConfigurator($this->collection, $route);
35+
return new RouteConfigurator($this->collection, $route, '', $parentConfigurator);
3536
}
3637

3738
/**

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,18 +538,26 @@ private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
538538
if ($this->supportsRedirections) {
539539
$code .= <<<EOF
540540
541-
if (\$requiredSchemes && !isset(\$requiredSchemes[\$context->getScheme()])) {
541+
\$hasRequiredScheme = !\$requiredSchemes || isset(\$requiredSchemes[\$context->getScheme()]);
542+
if (\$requiredMethods && !isset(\$requiredMethods[\$canonicalMethod]) && !isset(\$requiredMethods[\$requestMethod])) {
543+
if (\$hasRequiredScheme) {
544+
\$allow += \$requiredMethods;
545+
}
546+
break;
547+
}
548+
if (!\$hasRequiredScheme) {
542549
if ('GET' !== \$canonicalMethod) {
543-
\$allow['GET'] = 'GET';
544550
break;
545551
}
546552
547553
return \$this->redirect(\$rawPathinfo, \$ret['_route'], key(\$requiredSchemes)) + \$ret;
548554
}
549555
556+
return \$ret;
557+
550558
EOF;
551-
}
552-
$code .= <<<EOF
559+
} else {
560+
$code .= <<<EOF
553561
554562
if (\$requiredMethods && !isset(\$requiredMethods[\$canonicalMethod]) && !isset(\$requiredMethods[\$requestMethod])) {
555563
\$allow += \$requiredMethods;
@@ -559,6 +567,7 @@ private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
559567
return \$ret;
560568
561569
EOF;
570+
}
562571

563572
return $code;
564573
}
@@ -637,11 +646,20 @@ private function compileRoute(Route $route, string $name, bool $checkHost): stri
637646
throw new \LogicException('The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.');
638647
}
639648
$schemes = self::export(array_flip($schemes));
640-
$code .= <<<EOF
649+
if ($methods) {
650+
$methodVariable = isset($methods['GET']) ? '$canonicalMethod' : '$requestMethod';
651+
$methods = self::export($methods);
652+
$code .= <<<EOF
641653
\$requiredSchemes = $schemes;
642-
if (!isset(\$requiredSchemes[\$context->getScheme()])) {
654+
\$hasRequiredScheme = isset(\$requiredSchemes[\$context->getScheme()]);
655+
if (!isset((\$a = {$methods})[{$methodVariable}])) {
656+
if (\$hasRequiredScheme) {
657+
\$allow += \$a;
658+
}
659+
goto $gotoname;
660+
}
661+
if (!\$hasRequiredScheme) {
643662
if ('GET' !== \$canonicalMethod) {
644-
\$allow['GET'] = 'GET';
645663
goto $gotoname;
646664
}
647665
@@ -650,9 +668,21 @@ private function compileRoute(Route $route, string $name, bool $checkHost): stri
650668
651669
652670
EOF;
653-
}
671+
} else {
672+
$code .= <<<EOF
673+
\$requiredSchemes = $schemes;
674+
if (!isset(\$requiredSchemes[\$context->getScheme()])) {
675+
if ('GET' !== \$canonicalMethod) {
676+
goto $gotoname;
677+
}
678+
679+
return \$this->redirect(\$rawPathinfo, '$name', key(\$requiredSchemes)) + \$ret;
680+
}
654681
655-
if ($methods) {
682+
683+
EOF;
684+
}
685+
} elseif ($methods) {
656686
$methodVariable = isset($methods['GET']) ? '$canonicalMethod' : '$requestMethod';
657687
$methods = self::export($methods);
658688

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
135135
continue;
136136
}
137137

138+
$status = $this->handleRouteRequirements($pathinfo, $name, $route);
139+
140+
if (self::REQUIREMENT_MISMATCH === $status[0]) {
141+
continue;
142+
}
143+
138144
// check HTTP method requirement
139145
if ($requiredMethods = $route->getMethods()) {
140146
// HEAD and GET are equivalent as per RFC
@@ -143,18 +149,14 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
143149
}
144150

145151
if (!in_array($method, $requiredMethods)) {
146-
$this->allow = array_merge($this->allow, $requiredMethods);
152+
if (self::REQUIREMENT_MATCH === $status[0]) {
153+
$this->allow = array_merge($this->allow, $requiredMethods);
154+
}
147155

148156
continue;
149157
}
150158
}
151159

152-
$status = $this->handleRouteRequirements($pathinfo, $name, $route);
153-
154-
if (self::REQUIREMENT_MISMATCH === $status[0]) {
155-
continue;
156-
}
157-
158160
return $this->getAttributes($route, $name, array_replace($matches, $hostMatches, isset($status[1]) ? $status[1] : array()));
159161
}
160162
}

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function remove($name)
117117
* Adds a route collection at the end of the current set by appending all
118118
* routes of the added collection.
119119
*/
120-
public function addCollection(RouteCollection $collection)
120+
public function addCollection(self $collection)
121121
{
122122
// we need to remove all routes with the same names first because just replacing them
123123
// would not place the new route at the end of the merged array

src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher11.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,21 @@ private function doMatch(string $rawPathinfo, array &$allow = array()): ?array
105105
}
106106
}
107107

108-
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
108+
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
109+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
110+
if ($hasRequiredScheme) {
111+
$allow += $requiredMethods;
112+
}
113+
break;
114+
}
115+
if (!$hasRequiredScheme) {
109116
if ('GET' !== $canonicalMethod) {
110-
$allow['GET'] = 'GET';
111117
break;
112118
}
113119

114120
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
115121
}
116122

117-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
118-
$allow += $requiredMethods;
119-
break;
120-
}
121-
122123
return $ret;
123124
}
124125

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,21 @@ private function doMatch(string $rawPathinfo, array &$allow = array()): ?array
8282
}
8383
}
8484

85-
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
85+
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
86+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
87+
if ($hasRequiredScheme) {
88+
$allow += $requiredMethods;
89+
}
90+
break;
91+
}
92+
if (!$hasRequiredScheme) {
8693
if ('GET' !== $canonicalMethod) {
87-
$allow['GET'] = 'GET';
8894
break;
8995
}
9096

9197
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
9298
}
9399

94-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
95-
$allow += $requiredMethods;
96-
break;
97-
}
98-
99100
return $ret;
100101
}
101102

@@ -236,20 +237,21 @@ private function doMatch(string $rawPathinfo, array &$allow = array()): ?array
236237
}
237238
}
238239

239-
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
240+
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
241+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
242+
if ($hasRequiredScheme) {
243+
$allow += $requiredMethods;
244+
}
245+
break;
246+
}
247+
if (!$hasRequiredScheme) {
240248
if ('GET' !== $canonicalMethod) {
241-
$allow['GET'] = 'GET';
242249
break;
243250
}
244251

245252
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
246253
}
247254

248-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
249-
$allow += $requiredMethods;
250-
break;
251-
}
252-
253255
return $ret;
254256
}
255257

src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher5.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,21 @@ private function doMatch(string $rawPathinfo, array &$allow = array()): ?array
6464
}
6565
list($ret, $requiredHost, $requiredMethods, $requiredSchemes) = $routes[$pathinfo];
6666

67-
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
67+
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
68+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
69+
if ($hasRequiredScheme) {
70+
$allow += $requiredMethods;
71+
}
72+
break;
73+
}
74+
if (!$hasRequiredScheme) {
6875
if ('GET' !== $canonicalMethod) {
69-
$allow['GET'] = 'GET';
7076
break;
7177
}
7278

7379
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
7480
}
7581

76-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
77-
$allow += $requiredMethods;
78-
break;
79-
}
80-
8182
return $ret;
8283
}
8384

@@ -106,20 +107,21 @@ private function doMatch(string $rawPathinfo, array &$allow = array()): ?array
106107
}
107108
}
108109

109-
if ($requiredSchemes && !isset($requiredSchemes[$context->getScheme()])) {
110+
$hasRequiredScheme = !$requiredSchemes || isset($requiredSchemes[$context->getScheme()]);
111+
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
112+
if ($hasRequiredScheme) {
113+
$allow += $requiredMethods;
114+
}
115+
break;
116+
}
117+
if (!$hasRequiredScheme) {
110118
if ('GET' !== $canonicalMethod) {
111-
$allow['GET'] = 'GET';
112119
break;
113120
}
114121

115122
return $this->redirect($rawPathinfo, $ret['_route'], key($requiredSchemes)) + $ret;
116123
}
117124

118-
if ($requiredMethods && !isset($requiredMethods[$canonicalMethod]) && !isset($requiredMethods[$requestMethod])) {
119-
$allow += $requiredMethods;
120-
break;
121-
}
122-
123125
return $ret;
124126
}
125127

0 commit comments

Comments
 (0)
0