Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed CS

  • Loading branch information...
commit 6cd34570d7f0060c0259da80ee180c4643e503f2 1 parent 8366b8a
@arnaud-lb arnaud-lb authored
Showing with 94 additions and 77 deletions.
  1. +1 −1  src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
  2. +9 −9 src/Symfony/Component/Routing/CompiledRoute.php
  3. +1 −1  src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
  4. +1 −1  src/Symfony/Component/Routing/Loader/YamlFileLoader.php
  5. +1 −0  src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php
  6. +3 −3 src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php
  7. +11 −7 src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
  8. +1 −1  src/Symfony/Component/Routing/Matcher/UrlMatcher.php
  9. +12 −2 src/Symfony/Component/Routing/Route.php
  10. +37 −29 src/Symfony/Component/Routing/RouteCollection.php
  11. +1 −1  src/Symfony/Component/Routing/RouteCompiler.php
  12. +2 −2 src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php
  13. +2 −2 src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php
  14. +1 −1  src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml
  15. +2 −2 src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
  16. +1 −1  src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
  17. +0 −1  src/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php
  18. +0 −1  src/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php
  19. +4 −7 src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php
  20. +1 −1  src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php
  21. +1 −1  src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
  22. +2 −3 src/Symfony/Component/Routing/Tests/RouteCompilerTest.php
View
2  src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
@@ -93,7 +93,7 @@ protected function outputRoutes(OutputInterface $output, $routes = null)
? implode(', ', $requirements['_method']) : $requirements['_method']
)
: 'ANY';
- $hostname = null !== $route->getHostnamePattern()
+ $hostname = '' !== $route->getHostnamePattern()
? $route->getHostnamePattern() : 'ANY';
$maxName = max($maxName, strlen($name));
View
18 src/Symfony/Component/Routing/CompiledRoute.php
@@ -30,14 +30,14 @@ class CompiledRoute
/**
* Constructor.
*
- * @param string $staticPrefix The static prefix of the compiled route
- * @param string $regex The regular expression to use to match this route
- * @param array $tokens An array of tokens to use to generate URL for this route
- * @param array $pathVariables An array of path variables
- * @param array $hostnameRegex Hostname regex
- * @param array $hostnameTokens Hostname tokens
- * @param array $hostnameVariables An array of hostname variables
- * @param array $variables An array of variables (variables defined in the path and in the hostname patterns)
+ * @param string $staticPrefix The static prefix of the compiled route
+ * @param string $regex The regular expression to use to match this route
+ * @param array $tokens An array of tokens to use to generate URL for this route
+ * @param array $pathVariables An array of path variables
+ * @param array $hostnameRegex|null Hostname regex
+ * @param array $hostnameTokens Hostname tokens
+ * @param array $hostnameVariables An array of hostname variables
+ * @param array $variables An array of variables (variables defined in the path and in the hostname patterns)
*/
public function __construct($staticPrefix, $regex, array $tokens, array $pathVariables, $hostnameRegex = null, array $hostnameTokens = array(), array $hostnameVariables = array(), array $variables = array())
{
@@ -74,7 +74,7 @@ public function getRegex()
/**
* Returns the hostname regex
*
- * @return string The hostname regex
+ * @return string|null The hostname regex or null
*/
public function getHostnameRegex()
{
View
2  src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php
@@ -101,7 +101,7 @@ public function load($class, $type = null)
'requirements' => array(),
'options' => array(),
'defaults' => array(),
- 'hostname_pattern' => null,
+ 'hostname_pattern' => '',
);
$class = new \ReflectionClass($class);
View
2  src/Symfony/Component/Routing/Loader/YamlFileLoader.php
@@ -70,7 +70,7 @@ public function load($file, $type = null)
$defaults = isset($config['defaults']) ? $config['defaults'] : array();
$requirements = isset($config['requirements']) ? $config['requirements'] : array();
$options = isset($config['options']) ? $config['options'] : array();
- $hostnamePattern = isset($config['hostname_pattern']) ? $config['hostname_pattern'] : null;
+ $hostnamePattern = isset($config['hostname_pattern']) ? $config['hostname_pattern'] : '';
$this->setCurrentDir(dirname($path));
$collection->addCollection($this->import($config['resource'], $type, false, $file), $prefix, $defaults, $requirements, $options, $hostnamePattern);
View
1  src/Symfony/Component/Routing/Matcher/Dumper/ApacheMatcherDumper.php
@@ -111,6 +111,7 @@ public function dump(array $options = array())
* @param Route $route The route
* @param array $options Options
* @param bool $hostnameRegexUnique Unique identifier for the hostname regex
+ *
* @return string The compiled route
*/
private function dumpRoute($name, $route, array $options, $hostnameRegexUnique)
View
6 src/Symfony/Component/Routing/Matcher/Dumper/DumperCollection.php
@@ -102,7 +102,7 @@ protected function setParent(DumperCollection $parent)
/**
* Returns true if the attribute is defined.
*
- * @param string $name The attribute name
+ * @param string $name The attribute name
*
* @return Boolean true if the attribute is defined, false otherwise
*/
@@ -117,7 +117,7 @@ public function hasAttribute($name)
* @param string $name The attribute name
* @param mixed $default Default value is the attribute doesn't exist
*
- * @return mixed The attribute value
+ * @return mixed The attribute value
*/
public function getAttribute($name, $default = null)
{
@@ -138,7 +138,7 @@ public function setAttribute($name, $value)
/**
* Sets multiple attributes.
*
- * @param array $attributes The attributes
+ * @param array $attributes The attributes
*/
public function setAttributes($attributes)
{
View
18 src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php
@@ -144,9 +144,9 @@ private function compileRoutes(RouteCollection $routes, $supportsRedirections)
/**
* Generates PHP code recursively to match a tree of routes
*
- * @param DumperPrefixCollection $routes A DumperPrefixCollection instance
+ * @param DumperPrefixCollection $routes A DumperPrefixCollection instance
* @param Boolean $supportsRedirections Whether redirections are supported by the base class
- * @parma string $prefix Prefix of the parent collection
+ * @parma string $prefix Prefix of the parent collection
*
* @return string PHP code
*/
@@ -302,7 +302,11 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
if ($hostnameMatches) {
$vars[] = '$hostnameMatches';
}
- $matchesExpr = implode(' + ', $vars);
+ if (count($vars) > 1) {
+ $matchesExpr = 'array_merge(' . implode(', ', array_reverse($vars)) . ')';
+ } else {
+ $matchesExpr = current($vars);
+ }
$code .= sprintf(" return array_merge(\$this->mergeDefaults(%s, %s), array('_route' => '%s'));\n"
, $matchesExpr, str_replace("\n", '', var_export($route->getDefaults(), true)), $name);
@@ -313,7 +317,7 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
$code .= " \$matches = \$hostnameMatches;\n";
} else {
if ($hostnameMatches) {
- $code .= " \$matches = \$matches + \$hostnameMatches;\n";
+ $code .= " \$matches = array_merge(\$hostnameMatches, \$matches);\n";
}
}
@@ -336,8 +340,8 @@ private function compileRoute(Route $route, $name, $supportsRedirections, $paren
/**
* Flattens a tree of routes to a single collection.
*
- * @param RouteCollection $routes Collection of routes
- * @param DumperCollection $to A DumperCollection to add routes to
+ * @param RouteCollection $routes Collection of routes
+ * @param DumperCollection $to A DumperCollection to add routes to
*
* @return DumperCollection
*/
@@ -394,7 +398,7 @@ private function groupRoutesByHostnameRegex(DumperCollection $routes)
* Routes order is preserved such that traversing the tree will traverse the
* routes in the origin order
*
- * @param DumperCollection $collection A collection of routes
+ * @param DumperCollection $collection A collection of routes
*
* @return DumperPrefixCollection
*/
View
2  src/Symfony/Component/Routing/Matcher/UrlMatcher.php
@@ -147,7 +147,7 @@ protected function matchCollection($pathinfo, RouteCollection $routes)
continue;
}
- return array_merge($this->mergeDefaults($hostnameMatches + $matches, $route->getDefaults()), array('_route' => $name));
+ return array_merge($this->mergeDefaults(array_merge($matches, $hostnameMatches), $route->getDefaults()), array('_route' => $name));
}
}
View
14 src/Symfony/Component/Routing/Route.php
@@ -44,7 +44,7 @@ class Route implements \Serializable
*
* @api
*/
- public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array(), $hostnamePattern = null)
+ public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array(), $hostnamePattern = '')
{
$this->setPattern($pattern);
$this->setDefaults($defaults);
@@ -106,14 +106,24 @@ public function setPattern($pattern)
return $this;
}
+ /**
+ * Returns the hostname pattern.
+ *
+ * @return string The pattern
+ */
public function getHostnamePattern()
{
return $this->hostnamePattern;
}
+ /**
+ * Sets the hostname pattern.
+ *
+ * @param string $pattern The pattern
+ */
public function setHostnamePattern($pattern)
{
- $this->hostnamePattern = $pattern;
+ $this->hostnamePattern = (string) $pattern;
return $this;
}
View
66 src/Symfony/Component/Routing/RouteCollection.php
@@ -42,7 +42,7 @@ public function __construct()
$this->routes = array();
$this->resources = array();
$this->prefix = '';
- $this->hostnamePattern = null;
+ $this->hostnamePattern = '';
}
public function __clone()
@@ -185,18 +185,18 @@ public function remove($name)
/**
* Adds a route collection to the current set of routes (at the end of the current set).
*
- * @param RouteCollection $collection A RouteCollection instance
- * @param string $prefix An optional prefix to add before each pattern of the route collection
- * @param array $defaults An array of default values
- * @param array $requirements An array of requirements
- * @param array $options An array of options
- * @param string $hostnamePattern Hostname pattern
+ * @param RouteCollection $collection A RouteCollection instance
+ * @param string $prefix An optional prefix to add before each pattern of the route collection
+ * @param array $defaults An array of default values
+ * @param array $requirements An array of requirements
+ * @param array $options An array of options
+ * @param string $hostnamePattern Hostname pattern
*
* @throws \InvalidArgumentException When the RouteCollection already exists in the tree
*
* @api
*/
- public function addCollection(RouteCollection $collection, $prefix = '', $defaults = array(), $requirements = array(), $options = array(), $hostnamePattern = null)
+ public function addCollection(RouteCollection $collection, $prefix = '', $defaults = array(), $requirements = array(), $options = array(), $hostnamePattern = '')
{
// prevent infinite loops by recursive referencing
$root = $this->getRoot();
@@ -212,10 +212,7 @@ public function addCollection(RouteCollection $collection, $prefix = '', $defaul
// necessarily already have it applied (depending on the order RouteCollections are added to each other)
$collection->addPrefix($this->getPrefix() . $prefix, $defaults, $requirements, $options);
- // Allow child collection to have a different pattern
- if (!$collection->getHostnamePattern()) {
- $collection->setHostnamePattern($hostnamePattern);
- }
+ $collection->setHostnamePattern($hostnamePattern);
$this->routes[] = $collection;
}
@@ -269,6 +266,34 @@ public function getPrefix()
}
/**
+ * Returns the hostname pattern.
+ *
+ * @return string The pattern
+ */
+ public function getHostnamePattern()
+ {
+ return $this->hostnamePattern;
+ }
+
+ /**
+ * Sets the hostname pattern on this collection and all children.
+ *
+ * @param string $pattern The pattern
+ */
+ public function setHostnamePattern($pattern)
+ {
+ $this->hostnamePattern = $pattern;
+
+ if ('' === $pattern) {
+ return;
+ }
+
+ foreach ($this->routes as $name => $route) {
+ $route->setHostnamePattern($pattern);
+ }
+ }
+
+ /**
* Returns an array of resources loaded to build this collection.
*
* @return ResourceInterface[] An array of resources
@@ -350,21 +375,4 @@ private function hasCollection(RouteCollection $collection)
return false;
}
-
- public function getHostnamePattern()
- {
- return $this->hostnamePattern;
- }
-
- public function setHostnamePattern($pattern)
- {
- $this->hostnamePattern = $pattern;
-
- foreach ($this->routes as $name => $route) {
- // Allow individual routes to have a different pattern
- if (!$route->getHostnamePattern()) {
- $route->setHostnamePattern($pattern);
- }
- }
- }
}
View
2  src/Symfony/Component/Routing/RouteCompiler.php
@@ -46,7 +46,7 @@ public function compile(Route $route)
$hostnameRegex = null;
$hostnameTokens = array();
- if (null !== $hostnamePattern = $route->getHostnamePattern()) {
+ if ('' !== $hostnamePattern = $route->getHostnamePattern()) {
$result = $this->compilePattern($route, $hostnamePattern, true);
$hostnameVariables = $result['variables'];
View
4 src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php
@@ -282,7 +282,7 @@ public function match($pathinfo)
// route13
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
- $matches = $matches + $hostnameMatches;
+ $matches = array_merge($hostnameMatches, $matches);
$matches['_route'] = 'route13';
return $matches;
@@ -290,7 +290,7 @@ public function match($pathinfo)
// route14
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
- return array_merge($this->mergeDefaults($matches + $hostnameMatches, array ( 'var1' => 'val',)), array('_route' => 'route14'));
+ return array_merge($this->mergeDefaults(array_merge($hostnameMatches, $matches), array ( 'var1' => 'val',)), array('_route' => 'route14'));
}
}
View
4 src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php
@@ -294,7 +294,7 @@ public function match($pathinfo)
// route13
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
- $matches = $matches + $hostnameMatches;
+ $matches = array_merge($hostnameMatches, $matches);
$matches['_route'] = 'route13';
return $matches;
@@ -302,7 +302,7 @@ public function match($pathinfo)
// route14
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?<name>[^/]++)$#s', $pathinfo, $matches)) {
- return array_merge($this->mergeDefaults($matches + $hostnameMatches, array ( 'var1' => 'val',)), array('_route' => 'route14'));
+ return array_merge($this->mergeDefaults(array_merge($hostnameMatches, $matches), array ( 'var1' => 'val',)), array('_route' => 'route14'));
}
}
View
2  src/Symfony/Component/Routing/Tests/Fixtures/validpattern.yml
@@ -2,6 +2,6 @@ blog_show:
pattern: /blog/{slug}
defaults: { _controller: MyBlogBundle:Blog:show }
hostname_pattern: "{locale}.example.com"
- requirements: { 'foo': '\d+' }
+ requirements: { 'locale': '\d+' }
options:
compiler_class: RouteCompiler
View
4 src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php
@@ -235,7 +235,7 @@ public function testGenerateForRouteWithInvalidMandatoryParameter()
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+')));
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true);
}
-
+
/**
* @expectedException Symfony\Component\Routing\Exception\InvalidParameterException
*/
@@ -262,7 +262,7 @@ public function testSchemeRequirementForcesAbsoluteUrl()
$routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http')));
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
}
-
+
public function testPathWithTwoStartingSlashes()
{
$routes = $this->getRoutes('test', new Route('//path-and-not-domain'));
View
2  src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
@@ -90,7 +90,7 @@ public function testLoadWithPattern()
$route = $routes['blog_show'];
$this->assertEquals('/blog/{slug}', $route->getPattern());
$this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
- $this->assertEquals('\d+', $route->getRequirement('foo'));
+ $this->assertEquals('\d+', $route->getRequirement('locale'));
$this->assertEquals('{locale}.example.com', $route->getHostnamePattern());
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
}
View
1  src/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperCollectionTest.php
@@ -22,4 +22,3 @@ public function testGetRoot()
$this->assertSame($a, $c->getRoot());
}
}
-
View
1  src/Symfony/Component/Routing/Tests/Matcher/Dumper/DumperPrefixCollectionTest.php
@@ -112,4 +112,3 @@ private function collectionToString(DumperCollection $collection, $prefix)
return $string;
}
}
-
View
11 src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php
@@ -14,7 +14,6 @@
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
-use Symfony\Component\Routing\Matcher\Dumper\DumperCollection;
class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
{
@@ -165,13 +164,11 @@ public function getRouteCollections()
$collection2 = new RouteCollection();
- $route2 = new Route('/route2', array(), array(), array(), 'a.example.com');
- $collection2->add('route2', $route2);
+ $route2 = new Route('/c2/route2', array(), array(), array(), 'a.example.com');
+ $collection1->add('route2', $route2);
- $route3 = new Route('/route3', array(), array(), array(), 'b.example.com');
- $collection2->add('route3', $route3);
-
- $collection1->addCollection($collection2, '/c2');
+ $route3 = new Route('/c2/route3', array(), array(), array(), 'b.example.com');
+ $collection1->add('route3', $route3);
$route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
$collection1->add('route4', $route4);
View
2  src/Symfony/Component/Routing/Tests/Matcher/UrlMatcherTest.php
@@ -348,7 +348,7 @@ public function testWithHostnameOnRouteCollection()
$matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar'));
- $matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.net'));
+ $matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('foo' => 'bar', '_route' => 'bar', 'locale' => 'en'), $matcher->match('/bar/bar'));
}
View
2  src/Symfony/Component/Routing/Tests/RouteCollectionTest.php
@@ -309,6 +309,6 @@ public function testSetHostnamePattern()
$collection->setHostnamePattern('{locale}.example.com');
$this->assertEquals('{locale}.example.com', $routea->getHostnamePattern());
- $this->assertEquals('{locale}.example.net', $routeb->getHostnamePattern());
+ $this->assertEquals('{locale}.example.com', $routeb->getHostnamePattern());
}
}
View
5 src/Symfony/Component/Routing/Tests/RouteCompilerTest.php
@@ -197,7 +197,7 @@ public function testCompileWithHostname($name, $arguments, $prefix, $regex, $var
$this->assertEquals($hostnameRegex, str_replace(array("\n", ' '), '', $compiled->getHostnameRegex()), $name.' (hostname regex)');
$this->assertEquals($hostnameVariables, $compiled->getHostnameVariables(), $name.' (hostname variables)');
$this->assertEquals($hostnameTokens, $compiled->getHostnameTokens(), $name.' (hostname tokens)');
- }
+ }
public function provideCompileWithHostnameData()
{
@@ -247,8 +247,7 @@ public function provideCompileWithHostnameData()
array('text', '.example'),
array('variable', '', '[^\.]++', 'locale'),
),
- ),
+ ),
);
}
}
-
Please sign in to comment.
Something went wrong with that request. Please try again.