8000 fixed CS · symfony/symfony@6cd3457 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6cd3457

Browse files
committed
fixed CS
1 parent 8366b8a commit 6cd3457

22 files changed

+94
-77
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function outputRoutes(OutputInterface $output, $routes = null)
9393
? implode(', ', $requirements['_method']) : $requirements['_method']
9494
)
9595
: 'ANY';
96-
$hostname = null !== $route->getHostnamePattern()
96+
$hostname = '' !== $route->getHostnamePattern()
9797
? $route->getHostnamePattern() : 'ANY';
9898

9999
$maxName = max($maxName, strlen($name));

src/Symfony/Component/Routing/CompiledRoute.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class CompiledRoute
3030
/**
3131
* Constructor.
3232
*
33-
* @param string $staticPrefix The static prefix of the compiled route
34-
* @param string $regex The regular expression to use to match this route
35-
* @param array $tokens An array of tokens to use to generate URL for this route
36-
* @param array $pathVariables An array of path variables
37-
* @param array $hostnameRegex Hostname regex
38-
* @param array $hostnameTokens Hostname tokens
39-
* @param array $hostnameVariables An array of hostname variables
40-
* @param array $variables An array of variables (variables defined in the path and in the hostname patterns)
33+
* @param string $staticPrefix The static prefix of the compiled route
34+
* @param string $regex The regular expression to use to match this route
35+
* @param array $tokens An array of tokens to use to generate URL for this route
36+
* @param array $pathVariables An array of path variables
37+
* @param array $hostnameRegex|null Hostname regex
38+
* @param array $hostnameTokens Hostname tokens
39+
* @param array $hostnameVariables An array of hostname variables
40+
* @param array $variables An array of variables (variables defined in the path and in the hostname patterns)
4141
*/
4242
public function __construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostnameRegex = null, array $hostnameTokens = array(), array $hostnameVariables = array(), array $variables = array())
4343
{
@@ -74,7 +74,7 @@ public function getRegex()
7474
/**
7575
* Returns the hostname regex
7676
*
77-
* @return string The hostname regex
77+
* @return string|null The hostname regex or null
7878
*/
7979
public function getHostnameRegex()
8080
{

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function load($class, $type = null)
101101
'requirements' => array(),
102102
'options' => array(),
103103
'defaults' => array(),
104-
'hostname_pattern' => null,
104+
'hostname_pattern' => '',
105105
);
106106

107107
$class = new \ReflectionClass($class);

src/Symfony/Component/Routing/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function load($file, $type = null)
7070
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
7171
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
7272
$options = isset($config['options']) ? $config['options'] : array();
73-
$hostnamePattern = isset($config['hostname_pattern']) ? $config['hostname_pattern'] : null;
73+
$hostnamePattern = isset($config['hostname_pattern']) ? $config['hostname_pattern'] : '';
7474

7575
$this->setCurrentDir(dirname($path));
7676
$collection->addCollection($this->import($config['resource'], $type, false, $file), $prefix, $defaults, $requirements, $options, $hostnamePattern);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public function dump(array $options = array())
111111
* @param Route $route The route
112112
* @param array $options Options
113113
* @param bool $hostnameRegexUnique Unique identifier for the hostname regex
114+
*
114115
* @return string The compiled route
115116
*/
116117
private function dumpRoute($name, $route, array $options, $hostnameRegexUnique)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function setParent(DumperCollection $parent)
102102
/**
103103
* Returns true if the attribute is defined.
104104
*
105-
* @param string $name The attribute name
105+
* @param string $name The attribute name
106106
*
107107
* @return Boolean true if the attribute is defined, false otherwise
108108
*/
@@ -117,7 +117,7 @@ public function hasAttribute($name)
117117
* @param string $name The attribute name
118118
* @param mixed $default Default value is the attribute doesn't exist
119119
*
120-
* @return mixed The attribute value
120+
* @return mixed The attribute value
121121
*/
122122
public function getAttribute($name, $default = null)
123123
{
@@ -138,7 +138,7 @@ public function setAttribute($name, $value)
138138
/**
139139
* Sets multiple attributes.
140140
*
141-
* @param array $attributes The attributes
141+
* @param array $attributes The attributes
142142
*/
143143
public function setAttributes($attributes)
144144
{

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections)
144144
/**
145145
* Generates PHP code recursively to match a tree of routes
146146
*
147-
* @param DumperPrefixCollection $routes A DumperPrefixCollection instance
147+
* @param DumperPrefixCollection $routes A DumperPrefixCollection instance
148148
* @param Boolean $supportsRedirections Whether redirections are supported by the base class
149-
* @parma string $prefix Prefix of the parent collection
149+
* @parma string $prefix Prefix of the parent collection
150150
*
151151
* @return string PHP code
152152
*/
@@ -302,7 +302,11 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
302302
if ($hostnameMatches) {
303303
$vars[] = '$hostnameMatches';
304304
}
305-
$matchesExpr = implode(' + ', $vars);
305+
if (count($vars) > 1) {
306+
$matchesExpr = 'array_merge(' . implode(', ', array_reverse($vars)) . ')';
307+
} else {
308+
$matchesExpr = current($vars);
309+
}
306310

307311
$code .= sprintf(" return array_merge(\$this->mergeDefaults(%s, %s), array('_route' => '%s'));\n"
308312
, $matchesExpr, str_replace("\n", '', var_export($route->getDefaults(), true)), $name);
@@ -313,7 +317,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
313317
$code .= " \$matches = \$hostnameMatches;\n";
314318
} else {
315319
if ($hostnameMatches) {
316-
$code .= " \$matches = \$matches + \$hostnameMatches;\n";
320+
$code .= " \$matches = array_merge(\$hostnameMatches, \$matches);\n";
317321
}
318322
}
319323

@@ -336,8 +340,8 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
336340
/**
337341
* Flattens a tree of routes to a single collection.
338342
*
339-
* @param RouteCollection $routes Collection of routes
340-
* @param DumperCollection $to A DumperCollection to add routes to
343+
* @param RouteCollection $routes Collection of routes
344+
* @param DumperCollection $to A DumperCollection to add routes to
341345
*
342346
* @return DumperCollection
343347
*/
@@ -394,7 +398,7 @@ private function groupRoutesByHostnameRegex(DumperCollection $routes)
394398
* Routes order is preserved such that traversing the tree will traverse the
395399
* routes in the origin order
396400
*
397-
* @param DumperCollection $collection A collection of routes
401+
* @param DumperCollection $collection A collection of routes
398402
*
399403
* @return DumperPrefixCollection
400404
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
147147
continue;
148148
}
149149

150-
return array_merge($this->mergeDefaults($hostnameMatches + $matches, $route->getDefaults()), array('_route' => $name));
150+
return array_merge($this->mergeDefaults(array_merge($matches, $hostnameMatches), $route->getDefaults()), array('_route' => $name));
151151
}
152152
}
153153

src/Symfony/Component/Routing/Route.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Route implements \Serializable
4444
*
4545
* @api
4646
*/
47-
public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array(), $hostnamePattern = null)
47+
public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array(), $hostnamePattern = '')
4848
{
4949
$this->setPattern($pattern);
5050
$this->setDefaults($defaults);
@@ -106,14 +106,24 @@ public function setPattern($pattern)
106106
return $this;
107107
}
108108

109+
/**
110+
* Returns the hostname pattern.
111+
*
112+
* @return string The pattern
113+
*/
109114
public function getHostnamePattern()
110115
{
111116
return $this->hostnamePattern;
112117
}
113118

119+
/**
120+
* Sets the hostname pattern.
121+
*
122+
* @param string $pattern The pattern
123+
*/
114124
public function setHostnamePattern($pattern)
115125
{
116-
$this->hostnamePattern = $pattern;
126+
$this->hostnamePattern = (string) $pattern;
117127

118128
return $this;
119129
}

src/Symfony/Component/Routing/RouteCollection.php

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct()
4242
$this->routes = array();
4343
$this->resources = array();
4444
$this->prefix = '';
45-
$this->hostnamePattern = null;
45+
$this->hostnamePattern = '';
4646
}
4747

4848
public function __clone()
@@ -185,18 +185,18 @@ public function remove($name)
185185
/**
186186
* Adds a route collection to the current set of routes (at the end of the current set).
187187
*
188-
* @param RouteCollection $collection A RouteCollection instance
189-
* @param string $prefix An optional prefix to add before each pattern of the route collection
190-
* @param array $defaults An array of default values
191-
* @param array $requirements An array of requirements
192-
* @param array $options An array of options
193-
* @param string $hostnamePattern Hostname pattern
188+
* @param RouteCollection $collection A RouteCollection instance
189+
* @param string $prefix An optional prefix to add before each pattern of the route collection
190+
* @param array $defaults An array of default values
191+
* @param array $requirements An array of requirements
192+
* @param array $options An array of options
193+
* @param string $hostnamePattern Hostname pattern
194194
*
195195
* @throws \InvalidArgumentException When the RouteCollection already exists in the tree
196196
*
197197
* @api
198198
*/
199-
public function addCollection(RouteCollection $collection, $prefix = '', $defaults = array(), $requirements = array(), $options = array(), $hostnamePattern = null)
199+
public function addCollection(RouteCollection $collection, $prefix = '', $defaults = array(), $requirements = array(), $options = array(), $hostnamePattern = '')
200200
{
201201
// prevent infinite loops by recursive referencing
202202
$root = $this->getRoot();
@@ -212,10 +212,7 @@ public function addCollection(RouteCollection $collection, $prefix = '', $defaul
212212
// necessarily already have it applied (depending on the order RouteCollections are added to each other)
213213
$collection->addPrefix($this->getPrefix() . $prefix, $defaults, $requirements, $options);
214214

215-
// Allow child collection to have a different pattern
216-
if (!$collection->getHostnamePattern()) {
217-
$collection->setHostnamePattern($hostnamePattern);
218-
}
215+
$collection->setHostnamePattern($hostnamePattern);
219216

220217
$this->routes[] = $collection;
221218
}
@@ -268,6 +265,34 @@ public function getPrefix()
268265
return $this->prefix;
269266
}
270267

268+
/**
269+
* Returns the hostname pattern.
270+
*
271+
* @return string The pattern
272+
*/
273+
public function getHostnamePattern()
274+
{
275+
return $this->hostnamePattern;
276+
}
277+
278+
/**
279+
* Sets the hostname pattern on this collection and all children.
280+
*
281+
* @param string $pattern The pattern
282+
*/
283+
public function setHostnamePattern($pattern)
284+
{
285+
$this->hostnamePattern = $pattern;
286+
287+
if ('' === $pattern) {
288+
return;
289+
}
290+
291+
foreach ($this->routes as $name => $route) {
292+
$route->setHostnamePattern($pattern);
293+
}
294+
}
295+
271296
/**
272297
* Returns an array of resources loaded to build this collection.
273298
*
@@ -350,21 +375,4 @@ private function hasCollection(RouteCollection $collection)
350375

351376
return false;
352377
}
353-
354-
public function getHostnamePattern()
355-
{
356-
return $this->hostnamePattern;
357-
}
358-
359-
public function setHostnamePattern($pattern)
360-
{
361-
$this->hostnamePattern = $pattern;
362-
363-
foreach ($this->routes as $name => $route) {
364-
// Allow individual routes to have a different pattern
365-
if (!$route->getHostnamePattern()) {
366-
$route->setHostnamePattern($pattern);
367-
}
368-
}
369-
}
370378
}

src/Symfony/Component/Routing/RouteCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function compile(Route $route)
4646
$hostnameRegex = null;
4747
$hostnameTokens = array();
4848

49-
if (null !== $hostnamePattern = $route->getHostnamePattern()) {
49+
if ('' !== $hostnamePattern = $route->getHostnamePattern()) {
5050
$result = $this->compilePattern($route, $hostnamePattern, true);
5151

5252
$hostnameVariables = $result['variables'];

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

Lines changed: 2 additions & 2 deletions
< 10000 td data-grid-cell-id="diff-47618778d082fc8d87c63cba88c44ddf47810b46d7a3947517832b5a208c7fac-296-296-1" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">296
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,15 @@ public function match($pathinfo)
282282

283283
// route13
284284
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
285-
$matches = $matches + $hostnameMatches;
285+
$matches = array_merge($hostnameMatches, $matches);
286286
$matches['_route'] = 'route13';
287287

288288
return $matches;
289289
}
290290

291291
// route14
292292
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
293-
return array_merge($this->mergeDefaults($matches + $hostnameMatches, array ( 'var1' => 'val',)), array('_route' => 'route14'));
293+
return array_merge($this->mergeDefaults(array_merge($hostnameMatches, $matches), array ( 'var1' => 'val',)), array('_route' => 'route14'));
294294
}
295295

296
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ public function match($pathinfo)
294294

295295
// route13
296296
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
297-
$matches = $matches + $hostnameMatches;
297+
$matches = array_merge($hostnameMatches, $matches);
298298
$matches['_route'] = 'route13';
299299

300300
return $matches;
301301
}
302302

303303
// route14
304304
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
305-
return array_merge($this->mergeDefaults($matches + $hostnameMatches, array ( 'var1' => 'val',)), array('_route' => 'route14'));
305+
return array_merge($this->mergeDefaults(array_merge($hostnameMatches, $matches), array ( 'var1' => 'val',)), array('_route' => 'route14'));
306306
}
307307

308308
}

src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ blog_show:
22
pattern: /blog/{slug}
33
defaults: { _controller: MyBlogBundle:Blog:show }
44
hostname_pattern: "{locale}.example.com"
5-
requirements: { 'foo': '\d+' }
5+
requirements: { 'locale': '\d+' }
66
options:
77
compiler_class: RouteCompiler

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function testGenerateForRouteWithInvalidMandatoryParameter()
235235
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+')));
236236
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
237237
}
238-
238+
239239
/**
240240
* @expectedException Symfony\Component\Routing\Exception\InvalidParameterException
241241
*/
@@ -262,7 +262,7 @@ public function testSchemeRequirementForcesAbsoluteUrl()
262262
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http')));
263263
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
264264
}
265-
265+
266266
public function testPathWithTwoStartingSlashes()
267267
{
268268
$routes = $this->getRoutes('test', new Route('//path-and-not-domain'));

src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testLoadWithPattern()
9090
$route = $routes['blog_show'];
9191
$this->assertEquals('/blog/{slug}', $route->getPattern());
9292
$this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
93-
$this->assertEquals('\d+', $route->getRequirement('foo'));
93+
$this->assertEquals('\d+', $route->getRequirement('locale'));
9494
$this->assertEquals('{locale}.example.com', $route->getHostnamePattern());
9595
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
9696
}

src/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ public function testGetRoot()
2222
$this->assertSame($a, $c->getRoot());
2323
}
2424
}
25-

src/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,3 @@ private function collectionToString(DumperCollection $collection, $prefix)
112112
return $string;
113113
}
114114
}
115-

0 commit comments

Comments
 (0)
0