From 6a0ee27de1b11c16cb93a6e87d18d3b9afd618ba Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Wed, 17 Oct 2012 09:31:31 +0200 Subject: [PATCH 001/175] [Console] fixed progress bar jumping --- .../Component/Console/Helper/ProgressHelper.php | 15 +++------------ .../Console/Tests/Helper/ProgressHelperTest.php | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/ProgressHelper.php b/src/Symfony/Component/Console/Helper/ProgressHelper.php index ed0ccab140..e2db53bc5f 100644 --- a/src/Symfony/Component/Console/Helper/ProgressHelper.php +++ b/src/Symfony/Component/Console/Helper/ProgressHelper.php @@ -380,21 +380,12 @@ class ProgressHelper extends Helper * * @param OutputInterface $output An Output instance * @param string|array $messages The message as an array of lines or a single string - * @param Boolean $newline Whether to add a newline or not - * @param integer $size The size of line */ - private function overwrite(OutputInterface $output, $messages, $newline = false, $size = 80) + private function overwrite(OutputInterface $output, $messages) { - $output->write(str_repeat("\x08", $size)); + $output->write("\x0D"); // carriage return + $output->write("\x1B\x5B\x4B"); // clear line $output->write($messages); - $output->write(str_repeat(' ', $size - strlen($messages))); - - // clean up the end line - $output->write(str_repeat("\x08", $size - strlen($messages))); - - if ($newline) { - $output->writeln(''); - } } /** diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php index 8f96e90e4e..8eafb57f79 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php @@ -82,6 +82,6 @@ class ProgressHelperTest extends \PHPUnit_Framework_TestCase protected function generateOutput($expected) { - return str_repeat("\x08", 80).$expected.str_repeat(' ', 80 - strlen($expected)).str_repeat("\x08", 80 - strlen($expected)); + return "\x0D\x1B\x5B\x4B".$expected; } } From 12a890f7cb5fb4979956f38cf6e8fd2cbfc5d083 Mon Sep 17 00:00:00 2001 From: Iwan van Staveren Date: Sat, 24 Nov 2012 15:35:35 +0100 Subject: [PATCH 002/175] Issue 5288 fix --- .../Locale/Tests/Stub/StubNumberFormatterTest.php | 2 +- src/Symfony/Component/Locale/Tests/TestCase.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Locale/Tests/Stub/StubNumberFormatterTest.php b/src/Symfony/Component/Locale/Tests/Stub/StubNumberFormatterTest.php index 9471f820d1..7f033a31a9 100644 --- a/src/Symfony/Component/Locale/Tests/Stub/StubNumberFormatterTest.php +++ b/src/Symfony/Component/Locale/Tests/Stub/StubNumberFormatterTest.php @@ -210,7 +210,7 @@ class StubNumberFormatterTest extends LocaleTestCase public function formatCurrencyWithCurrencyStyleBrazilianRealRoundingProvider() { - $brl = $this->isIntlExtensionLoaded() && $this->isSameAsIcuVersion('4.8') ? 'BR' : 'R'; + $brl = $this->isIntlExtensionLoaded() && $this->isGreaterOrEqualThanIcuVersion('4.8') ? 'BR' : 'R'; return array( array(100, 'BRL', $brl, '%s$100.00'), diff --git a/src/Symfony/Component/Locale/Tests/TestCase.php b/src/Symfony/Component/Locale/Tests/TestCase.php index b6483285a2..1cc2e9fcfb 100644 --- a/src/Symfony/Component/Locale/Tests/TestCase.php +++ b/src/Symfony/Component/Locale/Tests/TestCase.php @@ -89,7 +89,16 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase protected function normalizeIcuVersion($version) { - return ((float) $version) * 100; + $versionIds = explode(".", $version); + + $multi = 1000; + $intVersion = 0; + foreach ($versionIds as $id) { + $intVersion += $id * $multi; + $multi = $multi/10; + } + + return (int) $intVersion; } protected function getIntlExtensionIcuVersion() From 98f3ca83959e71f91e54315d7f50923a86ba3a45 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 26 Nov 2012 18:28:37 +0100 Subject: [PATCH 003/175] [Routing] removed tree structure from RouteCollection --- .../Bundle/FrameworkBundle/Routing/Router.php | 20 +- .../Matcher/Dumper/PhpMatcherDumper.php | 34 +--- .../Routing/Matcher/TraceableUrlMatcher.php | 8 - .../Component/Routing/Matcher/UrlMatcher.php | 12 -- .../Component/Routing/RouteCollection.php | 185 +++++------------- 5 files changed, 65 insertions(+), 194 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php index 31fbc63ef6..cc6df98a41 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/Router.php @@ -84,19 +84,15 @@ class Router extends BaseRouter implements WarmableInterface private function resolveParameters(RouteCollection $collection) { foreach ($collection as $route) { - if ($route instanceof RouteCollection) { - $this->resolveParameters($route); - } else { - foreach ($route->getDefaults() as $name => $value) { - $route->setDefault($name, $this->resolve($value)); - } - - foreach ($route->getRequirements() as $name => $value) { - $route->setRequirement($name, $this->resolve($value)); - } - - $route->setPattern($this->resolve($route->getPattern())); + foreach ($route->getDefaults() as $name => $value) { + $route->setDefault($name, $this->resolve($value)); } + + foreach ($route->getRequirements() as $name => $value) { + $route->setRequirement($name, $this->resolve($value)); + } + + $route->setPattern($this->resolve($route->getPattern())); } } diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 454e26ca7b..2c86761b63 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -111,7 +111,6 @@ EOF; { $fetchedHostname = false; - $routes = $this->flattenRouteCollection($routes); $groups = $this->groupRoutesByHostnameRegex($routes); $code = ''; @@ -321,31 +320,6 @@ EOF; return $code; } - /** - * Flattens a tree of routes to a single collection. - * - * @param RouteCollection $routes Collection of routes - * @param DumperCollection|null $to A DumperCollection to add routes to - * - * @return DumperCollection - */ - private function flattenRouteCollection(RouteCollection $routes, DumperCollection $to = null) - { - if (null === $to) { - $to = new DumperCollection(); - } - - foreach ($routes as $name => $route) { - if ($route instanceof RouteCollection) { - $this->flattenRouteCollection($route, $to); - } else { - $to->add(new DumperRoute($name, $route)); - } - } - - return $to; - } - /** * Groups consecutive routes having the same hostname regex. * @@ -355,7 +329,7 @@ EOF; * * @return DumperCollection A collection with routes grouped by hostname regex in sub-collections */ - private function groupRoutesByHostnameRegex(DumperCollection $routes) + private function groupRoutesByHostnameRegex(RouteCollection $routes) { $groups = new DumperCollection(); @@ -363,14 +337,14 @@ EOF; $currentGroup->setAttribute('hostname_regex', null); $groups->add($currentGroup); - foreach ($routes as $route) { - $hostnameRegex = $route->getRoute()->compile()->getHostnameRegex(); + foreach ($routes as $name => $route) { + $hostnameRegex = $route->compile()->getHostnameRegex(); if ($currentGroup->getAttribute('hostname_regex') !== $hostnameRegex) { $currentGroup = new DumperCollection(); $currentGroup->setAttribute('hostname_regex', $hostnameRegex); $groups->add($currentGroup); } - $currentGroup->add($route); + $currentGroup->add(new DumperRoute($name, $route)); } return $groups; diff --git a/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php b/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php index 1e2491c488..6ef846dd69 100644 --- a/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/TraceableUrlMatcher.php @@ -44,14 +44,6 @@ class TraceableUrlMatcher extends UrlMatcher protected function matchCollection($pathinfo, RouteCollection $routes) { foreach ($routes as $name => $route) { - if ($route instanceof RouteCollection) { - if (!$ret = $this->matchCollection($pathinfo, $route)) { - continue; - } - - return true; - } - $compiledRoute = $route->compile(); if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) { diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 5c6985447c..7a12dd16b9 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -105,18 +105,6 @@ class UrlMatcher implements UrlMatcherInterface protected function matchCollection($pathinfo, RouteCollection $routes) { foreach ($routes as $name => $route) { - if ($route instanceof RouteCollection) { - if (false === strpos($route->getPrefix(), '{') && $route->getPrefix() !== substr($pathinfo, 0, strlen($route->getPrefix()))) { - continue; - } - - if (!$ret = $this->matchCollection($pathinfo, $route)) { - continue; - } - - return $ret; - } - $compiledRoute = $route->compile(); // check the static prefix of the URL first. Only use the more expensive preg_match when it matches diff --git a/src/Symfony/Component/Routing/RouteCollection.php b/src/Symfony/Component/Routing/RouteCollection.php index ebbf236b58..91efdf4a71 100644 --- a/src/Symfony/Component/Routing/RouteCollection.php +++ b/src/Symfony/Component/Routing/RouteCollection.php @@ -14,10 +14,11 @@ namespace Symfony\Component\Routing; use Symfony\Component\Config\Resource\ResourceInterface; /** - * A RouteCollection represents a set of Route instances as a tree structure. + * A RouteCollection represents a set of Route instances. * - * When adding a route, it overrides existing routes with the - * same name defined in the instance or its children and parents. + * When adding a route at the end of the collection, an existing route + * with the same name is removed first. So there can only be one route + * with a given name. * * @author Fabien Potencier * @author Tobias Schultze @@ -27,7 +28,7 @@ use Symfony\Component\Config\Resource\ResourceInterface; class RouteCollection implements \IteratorAggregate, \Countable { /** - * @var (RouteCollection|Route)[] + * @var Route[] */ private $routes = array(); @@ -43,6 +44,7 @@ class RouteCollection implements \IteratorAggregate, \Countable /** * @var RouteCollection|null + * @deprecated since version 2.2, will be removed in 2.3 */ private $parent; @@ -50,9 +52,6 @@ class RouteCollection implements \IteratorAggregate, \Countable { foreach ($this->routes as $name => $route) { $this->routes[$name] = clone $route; - if ($route instanceof RouteCollection) { - $this->routes[$name]->setParent($this); - } } } @@ -60,6 +59,8 @@ class RouteCollection implements \IteratorAggregate, \Countable * Gets the parent RouteCollection. * * @return RouteCollection|null The parent RouteCollection or null when it's the root + * + * @deprecated since version 2.2, will be removed in 2.3 */ public function getParent() { @@ -67,9 +68,11 @@ class RouteCollection implements \IteratorAggregate, \Countable } /** - * Gets the root RouteCollection of the tree. + * Gets the root RouteCollection. * * @return RouteCollection The root RouteCollection + * + * @deprecated since version 2.2, will be removed in 2.3 */ public function getRoot() { @@ -82,9 +85,13 @@ class RouteCollection implements \IteratorAggregate, \Countable } /** - * Gets the current RouteCollection as an Iterator that includes all routes and child route collections. + * Gets the current RouteCollection as an Iterator that includes all routes. + * + * It implements \IteratorAggregate. * - * @return \ArrayIterator An \ArrayIterator interface + * @see all() + * + * @return \ArrayIterator An \ArrayIterator object for iterating over routes */ public function getIterator() { @@ -94,16 +101,11 @@ class RouteCollection implements \IteratorAggregate, \Countable /** * Gets the number of Routes in this collection. * - * @return int The number of routes in this collection, including nested collections + * @return int The number of routes */ public function count() { - $count = 0; - foreach ($this->routes as $route) { - $count += $route instanceof RouteCollection ? count($route) : 1; - } - - return $count; + return count($this->routes); } /** @@ -122,32 +124,23 @@ class RouteCollection implements \IteratorAggregate, \Countable throw new \InvalidArgumentException(sprintf('The provided route name "%s" contains non valid characters. A route name must only contain digits (0-9), letters (a-z and A-Z), underscores (_) and dots (.).', $name)); } - $this->remove($name); + unset($this->routes[$name]); $this->routes[$name] = $route; } /** - * Returns all routes in this collection and its children. + * Returns all routes in this collection. * * @return Route[] An array of routes */ public function all() { - $routes = array(); - foreach ($this->routes as $name => $route) { - if ($route instanceof RouteCollection) { - $routes = array_merge($routes, $route->all()); - } else { - $routes[$name] = $route; - } - } - - return $routes; + return $this->routes; } /** - * Gets a route by name defined in this collection or its children. + * Gets a route by name. * * @param string $name The route name * @@ -155,36 +148,31 @@ class RouteCollection implements \IteratorAggregate, \Countable */ public function get($name) { - if (isset($this->routes[$name])) { - return $this->routes[$name] instanceof RouteCollection ? null : $this->routes[$name]; - } - - foreach ($this->routes as $routes) { - if ($routes instanceof RouteCollection && null !== $route = $routes->get($name)) { - return $route; - } - } - - return null; + return isset($this->routes[$name]) ? $this->routes[$name] : null; } /** - * Removes a route or an array of routes by name from all connected - * collections (this instance and all parents and children). + * Removes a route or an array of routes by name from the collection + * + * For BC it's also removed from the root, which will not be the case in 2.3 + * as the RouteCollection won't be a tree structure. * * @param string|array $name The route name or an array of route names */ public function remove($name) { + // just for BC $root = $this->getRoot(); foreach ((array) $name as $n) { - $root->removeRecursively($n); + unset($root->routes[$n]); + unset($this->routes[$n]); } } /** - * Adds a route collection to the current set of routes (at the end of the current set). + * Adds a route collection at the end of the current set by appending all + * routes of the added collection. * * @param RouteCollection $collection A RouteCollection instance * @param string $prefix An optional prefix to add before each pattern of the route collection @@ -193,22 +181,16 @@ class RouteCollection implements \IteratorAggregate, \Countable * @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 = '') { - // prevent infinite loops by recursive referencing - $root = $this->getRoot(); - if ($root === $collection || $root->hasCollection($collection)) { - throw new \InvalidArgumentException('The RouteCollection already exists in the tree.'); - } + // This is to keep BC for getParent() and getRoot(). It does not prevent + // infinite loops by recursive referencing. But we don't need that logic + // anymore as the tree logic has been deprecated and we are just widening + // the accepted range. + $collection->parent = $this; - // remove all routes with the same names in all existing collections - $this->remove(array_keys($collection->all())); - - $collection->setParent($this); // the sub-collection must have the prefix of the parent (current instance) prepended because it does not // necessarily already have it applied (depending on the order RouteCollections are added to each other) $collection->addPrefix($this->getPrefix() . $prefix, $defaults, $requirements, $options); @@ -217,7 +199,14 @@ class RouteCollection implements \IteratorAggregate, \Countable $collection->setHostnamePattern($hostnamePattern); } - $this->routes[] = $collection; + // we need to remove all routes with the same names first because just replacing them + // would not place the new route at the end of the merged array + foreach ($collection->all() as $name => $route) { + unset($this->routes[$name]); + $this->routes[$name] = $route; + } + + $this->resources = array_merge($this->resources, $collection->getResources()); } /** @@ -244,17 +233,12 @@ class RouteCollection implements \IteratorAggregate, \Countable } foreach ($this->routes as $route) { - if ($route instanceof RouteCollection) { - // we add the slashes so the prefix is not lost by trimming in the sub-collection - $route->addPrefix('/' . $prefix . '/', $defaults, $requirements, $options); - } else { - if ('' !== $prefix) { - $route->setPattern('/' . $prefix . $route->getPattern()); - } - $route->addDefaults($defaults); - $route->addRequirements($requirements); - $route->addOptions($options); + if ('' !== $prefix) { + $route->setPattern('/' . $prefix . $route->getPattern()); } + $route->addDefaults($defaults); + $route->addRequirements($requirements); + $route->addOptions($options); } } @@ -269,7 +253,7 @@ class RouteCollection implements \IteratorAggregate, \Countable } /** - * Sets the hostname pattern on all child routes. + * Sets the hostname pattern on all routes. * * @param string $pattern The pattern */ @@ -287,14 +271,7 @@ class RouteCollection implements \IteratorAggregate, \Countable */ public function getResources() { - $resources = $this->resources; - foreach ($this->routes as $routes) { - if ($routes instanceof RouteCollection) { - $resources = array_merge($resources, $routes->getResources()); - } - } - - return array_unique($resources); + return array_unique($this->resources); } /** @@ -306,60 +283,4 @@ class RouteCollection implements \IteratorAggregate, \Countable { $this->resources[] = $resource; } - - /** - * Sets the parent RouteCollection. It's only used internally from one RouteCollection - * to another. It makes no sense to be available as part of the public API. - * - * @param RouteCollection $parent The parent RouteCollection - */ - private function setParent(RouteCollection $parent) - { - $this->parent = $parent; - } - - /** - * Removes a route by name from this collection and its children recursively. - * - * @param string $name The route name - * - * @return Boolean true when found - */ - private function removeRecursively($name) - { - // It is ensured by the adders (->add and ->addCollection) that there can - // only be one route per name in all connected collections. So we can stop - // iterating recursively on the first hit. - if (isset($this->routes[$name])) { - unset($this->routes[$name]); - - return true; - } - - foreach ($this->routes as $routes) { - if ($routes instanceof RouteCollection && $routes->removeRecursively($name)) { - return true; - } - } - - return false; - } - - /** - * Checks whether the given RouteCollection is already set in any child of the current instance. - * - * @param RouteCollection $collection A RouteCollection instance - * - * @return Boolean - */ - private function hasCollection(RouteCollection $collection) - { - foreach ($this->routes as $routes) { - if ($routes === $collection || $routes instanceof RouteCollection && $routes->hasCollection($collection)) { - return true; - } - } - - return false; - } } From 50e625962c004650e03c8e2481591e7ae8170b42 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 26 Nov 2012 18:29:17 +0100 Subject: [PATCH 004/175] adjusted tests --- .../Matcher/Dumper/PhpMatcherDumperTest.php | 4 +- .../Routing/Tests/RouteCollectionTest.php | 74 ++----------------- 2 files changed, 7 insertions(+), 71 deletions(-) diff --git a/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php b/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php index 9c15be5642..e04310cc9a 100644 --- a/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/src/Symfony/Component/Routing/Tests/Matcher/Dumper/PhpMatcherDumperTest.php @@ -135,8 +135,8 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase $collection3 = new RouteCollection(); $collection3->add('overridden2', new Route('/new')); $collection3->add('hey', new Route('/hey/')); - $collection1->addCollection($collection2); $collection2->addCollection($collection3); + $collection1->addCollection($collection2); $collection->addCollection($collection1, '/multi'); // "dynamic" prefix @@ -216,8 +216,8 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase $collection3 = new RouteCollection(); $collection3->add('c', new Route('/{var}')); - $collection1->addCollection($collection2, '/b'); $collection2->addCollection($collection3, '/c'); + $collection1->addCollection($collection2, '/b'); $collection->addCollection($collection1, '/a'); /* test case 2 */ diff --git a/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php index 16d193e34b..840a1d0dc6 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCollectionTest.php @@ -70,8 +70,8 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase $collection->add('foo', new Route('/foo')); $collection1 = new RouteCollection(); - $collection->addCollection($collection1); $collection1->add('foo', new Route('/foo1')); + $collection->addCollection($collection1); $this->assertEquals('/foo1', $this->getFirstNamedRoute($collection, 'foo')->getPattern()); } @@ -82,8 +82,8 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase $collection->add('foo', new Route('/foo')); $collection1 = new RouteCollection(); - $collection->addCollection($collection1); $collection1->add('foo1', new Route('/foo1')); + $collection->addCollection($collection1); $this->assertCount(2, $collection); } @@ -212,19 +212,12 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase $collection3 = new RouteCollection(); $collection3->add('foo', $new = new Route('/new')); - $collection1->addCollection($collection2); $collection2->addCollection($collection3); - - $collection1->add('stay', new Route('/stay')); - - $iterator = $collection1->getIterator(); + $collection1->addCollection($collection2); $this->assertSame($new, $collection1->get('foo'), '->get() returns new route that overrode previous one'); - // size of 2 because collection1 contains collection2 and /stay but not /old anymore - $this->assertCount(2, $iterator, '->addCollection() removes previous routes when adding new routes with the same name'); - $this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $iterator->current(), '->getIterator returns both Routes and RouteCollections'); - $iterator->next(); - $this->assertInstanceOf('Symfony\Component\Routing\Route', $iterator->current(), '->getIterator returns both Routes and RouteCollections'); + // size of 1 because collection1 contains /new but not /old anymore + $this->assertCount(1, $collection1->getIterator(), '->addCollection() removes previous routes when adding new routes with the same name'); } public function testGet() @@ -241,63 +234,6 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase $this->assertNull($collection1->get(0), '->get() does not disclose internal child RouteCollection'); } - /** - * @expectedException \InvalidArgumentException - */ - public function testCannotSelfJoinCollection() - { - $collection = new RouteCollection(); - - $collection->addCollection($collection); - } - - /** - * @expectedException \InvalidArgumentException - */ - public function testCannotAddExistingCollectionToTree() - { - $collection1 = new RouteCollection(); - $collection2 = new RouteCollection(); - $collection3 = new RouteCollection(); - - $collection1->addCollection($collection2); - $collection1->addCollection($collection3); - $collection2->addCollection($collection3); - } - - public function testPatternDoesNotChangeWhenDefinitionOrderChanges() - { - $collection1 = new RouteCollection(); - $collection1->add('a', new Route('/a...')); - $collection2 = new RouteCollection(); - $collection2->add('b', new Route('/b...')); - $collection3 = new RouteCollection(); - $collection3->add('c', new Route('/c...')); - - $rootCollection_A = new RouteCollection(); - $collection2->addCollection($collection3, '/c'); - $collection1->addCollection($collection2, '/b'); - $rootCollection_A->addCollection($collection1, '/a'); - - // above should mean the same as below - - $collection1 = new RouteCollection(); - $collection1->add('a', new Route('/a...')); - $collection2 = new RouteCollection(); - $collection2->add('b', new Route('/b...')); - $collection3 = new RouteCollection(); - $collection3->add('c', new Route('/c...')); - - $rootCollection_B = new RouteCollection(); - $collection1->addCollection($collection2, '/b'); - $collection2->addCollection($collection3, '/c'); - $rootCollection_B->addCollection($collection1, '/a'); - - // test it now - - $this->assertEquals($rootCollection_A, $rootCollection_B); - } - public function testSetHostnamePattern() { $collection = new RouteCollection(); From 51223c05fff207b6a1b954c0be0575470fc16279 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Tue, 27 Nov 2012 20:03:51 +0100 Subject: [PATCH 005/175] added upgrade instructions --- UPGRADE-2.2.md | 36 ++++++++++++++++++++++ src/Symfony/Component/Routing/CHANGELOG.md | 33 ++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/UPGRADE-2.2.md b/UPGRADE-2.2.md index 8025bab73b..43cff13cb7 100644 --- a/UPGRADE-2.2.md +++ b/UPGRADE-2.2.md @@ -36,6 +36,42 @@ * The PasswordType is now not trimmed by default. +### Routing + + * RouteCollection does not behave like a tree structure anymore but as a flat + array of Routes. So when using PHP to build the RouteCollection, you must + make sure to add routes to the sub-collection before adding it to the parent + collection (this is not relevant when using YAML or XML for Route definitions). + + Before: + + ``` + $rootCollection = new RouteCollection(); + $subCollection = new RouteCollection(); + $rootCollection->addCollection($subCollection); + $subCollection->add('foo', new Route('/foo')); + ``` + + After: + + ``` + $rootCollection = new RouteCollection(); + $subCollection = new RouteCollection(); + $subCollection->add('foo', new Route('/foo')); + $rootCollection->addCollection($subCollection); + ``` + + Also one must call `addCollection` from the bottom to the top hierarchy. + So the correct sequence is the following (and not the reverse): + + ``` + $childCollection->->addCollection($grandchildCollection); + $rootCollection->addCollection($childCollection); + ``` + + * The methods `RouteCollection::getParent()` and `RouteCollection::getRoot()` + have been deprecated and will be removed in Symfony 2.3. + ### Validator * Interfaces were created for created for the classes `ConstraintViolation`, diff --git a/src/Symfony/Component/Routing/CHANGELOG.md b/src/Symfony/Component/Routing/CHANGELOG.md index 92a460dd14..39bf2b88b3 100644 --- a/src/Symfony/Component/Routing/CHANGELOG.md +++ b/src/Symfony/Component/Routing/CHANGELOG.md @@ -4,6 +4,39 @@ CHANGELOG 2.2.0 ----- + * [BC BREAK] RouteCollection does not behave like a tree structure anymore but as + a flat array of Routes. So when using PHP to build the RouteCollection, you must + make sure to add routes to the sub-collection before adding it to the parent + collection (this is not relevant when using YAML or XML for Route definitions). + + Before: + + ``` + $rootCollection = new RouteCollection(); + $subCollection = new RouteCollection(); + $rootCollection->addCollection($subCollection); + $subCollection->add('foo', new Route('/foo')); + ``` + + After: + + ``` + $rootCollection = new RouteCollection(); + $subCollection = new RouteCollection(); + $subCollection->add('foo', new Route('/foo')); + $rootCollection->addCollection($subCollection); + ``` + + Also one must call `addCollection` from the bottom to the top hierarchy. + So the correct sequence is the following (and not the reverse): + + ``` + $childCollection->->addCollection($grandchildCollection); + $rootCollection->addCollection($childCollection); + ``` + + * The methods `RouteCollection::getParent()` and `RouteCollection::getRoot()` + have been deprecated and will be removed in Symfony 2.3. * added support for the method default argument values when defining a @Route * Adjacent placeholders without separator work now, e.g. `/{x}{y}{z}.{_format}`. * Characters that function as separator between placeholders are now whitelisted From 7f16c1f5bcc65c0830573ef2d6f58c575a921428 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 29 Nov 2012 14:58:56 +0100 Subject: [PATCH 006/175] [HttpKernel] Add DI extension configs as ressources when possible --- .../DependencyInjection/Configuration.php | 20 +++++-------------- .../FrameworkExtension.php | 5 ----- .../DependencyInjection/Extension.php | 6 ++++++ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 4ff15f16e7..007c1f977b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -22,22 +22,12 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; */ class Configuration implements ConfigurationInterface { - private $debug; - - /** - * Constructor - * - * @param Boolean $debug Whether to use the debug mode - */ - public function __construct($debug) - { - $this->debug = (Boolean) $debug; - } - /** * Generates the configuration tree builder. * - * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + * @return TreeBuilder The tree builder + * + * @throws \RuntimeException When using the deprecated 'charset' setting */ public function getConfigTreeBuilder() { @@ -54,7 +44,7 @@ class Configuration implements ConfigurationInterface $message = 'The charset setting is deprecated. Just remove it from your configuration file.'; if ('UTF-8' !== $v) { - $message .= sprintf(' You need to define a getCharset() method in your Application Kernel class that returns "%s".', $v); + $message .= sprintf('You need to define a getCharset() method in your Application Kernel class that returns "%s".', $v); } throw new \RuntimeException($message); @@ -384,7 +374,7 @@ class Configuration implements ConfigurationInterface ->children() ->scalarNode('cache')->defaultValue('file')->end() ->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end() - ->booleanNode('debug')->defaultValue($this->debug)->end() + ->booleanNode('debug')->defaultValue('%kernel.debug%')->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index ad1de4438c..c38844e15e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -141,11 +141,6 @@ class FrameworkExtension extends Extension )); } - public function getConfiguration(array $config, ContainerBuilder $container) - { - return new Configuration($container->getParameter('kernel.debug')); - } - /** * Loads Form configuration. * diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php index 5c8d5e69ad..c14aa81635 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\DependencyInjection; use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; @@ -84,6 +85,8 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn * This can be overridden in a sub-class to specify the alias manually. * * @return string The alias + * + * @throws \BadMethodCallException When the extension name does not follow conventions */ public function getAlias() { @@ -113,6 +116,9 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn $class = $namespace . '\\Configuration'; if (class_exists($class)) { + $r = new \ReflectionClass($class); + $container->addResource(new FileResource($r->getFileName())); + if (!method_exists($class, '__construct')) { $configuration = new $class(); From 972e503fa83e24b8009a2bc0b89e48be49fe9e3a Mon Sep 17 00:00:00 2001 From: Felix Labrecque Date: Thu, 29 Nov 2012 10:30:50 -0500 Subject: [PATCH 007/175] Fix problem when 1 column identifier in propel is a string. The ModelChoiceList thinks it can be used as the index of the ChoiceList, when it can only be used if it is an integer. --- .../Form/ChoiceList/ModelChoiceList.php | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index 54fe224d31..82d5e9d49d 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -45,6 +45,13 @@ class ModelChoiceList extends ObjectChoiceList */ private $loaded = false; + /** + * Whether to use the identifier for index generation + * + * @var Boolean + */ + private $identifierAsIndex = false; + /** * @param string $class * @param string $labelPath @@ -69,6 +76,13 @@ class ModelChoiceList extends ObjectChoiceList $choices = array(); } + if (1 === count($this->identifier)) { + // TODO this should be current($this->identifier)->isInteger() when propel ColumnMap contains the isInteger function + if ($this->isInteger(current($this->identifier))) { + $this->identifierAsIndex = true; + } + } + parent::__construct($choices, $labelPath, array(), $groupPath); } @@ -224,7 +238,7 @@ class ModelChoiceList extends ObjectChoiceList // know that the IDs are used as indices // Attention: This optimization does not check choices for existence - if (1 === count($this->identifier)) { + if ($this->identifierAsIndex) { $indices = array(); foreach ($models as $model) { @@ -259,7 +273,7 @@ class ModelChoiceList extends ObjectChoiceList // know that the IDs are used as indices and values // Attention: This optimization does not check values for existence - if (1 === count($this->identifier)) { + if ($this->identifierAsIndex) { return $this->fixIndices($values); } @@ -283,7 +297,7 @@ class ModelChoiceList extends ObjectChoiceList */ protected function createIndex($model) { - if (1 === count($this->identifier)) { + if ($this->identifierAsIndex) { return current($this->getIdentifierValues($model)); } @@ -351,4 +365,15 @@ class ModelChoiceList extends ObjectChoiceList return $model->getPrimaryKeys(); } + + /** + * Whether this column in an integer + * TODO we could add this function to propel ColumnMap class instead + * + * @return boolean + */ + private function isInteger($col) + { + return $col->getType() === \PDO::PARAM_INT; + } } From acfc750a48d83496e342a0876ca86a9627e306b6 Mon Sep 17 00:00:00 2001 From: "Konstantin.Myakshin" Date: Sun, 7 Oct 2012 22:03:04 +0300 Subject: [PATCH 008/175] #2042 initial implementation of fatal error handler --- .../HttpKernel/Debug/ErrorHandler.php | 34 ++++++++++++++++++ .../HttpKernel/Debug/ExceptionHandler.php | 3 ++ .../Exception/FatalErrorException.php | 22 ++++++++++++ .../HttpKernel/Exception/FlattenException.php | 36 ++++++++++++++++++- .../Tests/Debug/ErrorHandlerTest.php | 7 ++-- .../Tests/Exception/FlattenExceptionTest.php | 4 +-- 6 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 src/Symfony/Component/HttpKernel/Exception/FatalErrorException.php diff --git a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php index 605c08626c..197ec03cf3 100644 --- a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php +++ b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php @@ -11,6 +11,8 @@ namespace Symfony\Component\HttpKernel\Debug; +use Symfony\Component\HttpKernel\Exception\FatalErrorException; + /** * ErrorHandler. * @@ -28,10 +30,16 @@ class ErrorHandler E_RECOVERABLE_ERROR => 'Catchable Fatal Error', E_DEPRECATED => 'Deprecated', E_USER_DEPRECATED => 'User Deprecated', + E_ERROR => 'Error', + E_CORE_ERROR => 'Core Error', + E_COMPILE_ERROR => 'Compile Error', + E_PARSE => 'Parse', ); private $level; + private $reservedMemory; + /** * Register the error handler. * @@ -45,6 +53,8 @@ class ErrorHandler $handler->setLevel($level); set_error_handler(array($handler, 'handle')); + register_shutdown_function(array($handler, 'handleFatal')); + $handler->reservedMemory = str_repeat('x', 10240); return $handler; } @@ -69,4 +79,28 @@ class ErrorHandler return false; } + + public function handleFatal() + { + if (null === $error = error_get_last()) { + return; + } + + unset($this->reservedMemory); + $type = $error['type']; + if (0 === $this->level || !in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) { + return; + } + + // get current exception handler + $exceptionHandler = set_exception_handler(function() {}); + restore_exception_handler(); + + if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) { + $level = isset($this->levels[$type]) ? $this->levels[$type] : $type; + $message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']); + $exception = new FatalErrorException($message, 0, $type, $error['file'], $error['line']); + $exceptionHandler[0]->handle($exception); + } + } } diff --git a/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php b/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php index c0133d49f4..8660b9e781 100644 --- a/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php @@ -209,6 +209,9 @@ EOF border-radius: 10px; border: 1px solid #ccc; } + .xdebug-error { + display: none; + } diff --git a/src/Symfony/Component/HttpKernel/Exception/FatalErrorException.php b/src/Symfony/Component/HttpKernel/Exception/FatalErrorException.php new file mode 100644 index 0000000000..a082f80dc0 --- /dev/null +++ b/src/Symfony/Component/HttpKernel/Exception/FatalErrorException.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Exception; + +/** + * Fatal Error Exception. + * + * @author Konstanton Myakshin + */ +class FatalErrorException extends \ErrorException +{ + +} diff --git a/src/Symfony/Component/HttpKernel/Exception/FlattenException.php b/src/Symfony/Component/HttpKernel/Exception/FlattenException.php index eb5e5715fa..367b549440 100644 --- a/src/Symfony/Component/HttpKernel/Exception/FlattenException.php +++ b/src/Symfony/Component/HttpKernel/Exception/FlattenException.php @@ -47,7 +47,7 @@ class FlattenException $e->setStatusCode($statusCode); $e->setHeaders($headers); - $e->setTrace($exception->getTrace(), $exception->getFile(), $exception->getLine()); + $e->setTraceFromException($exception); $e->setClass(get_class($exception)); $e->setFile($exception->getFile()); $e->setLine($exception->getLine()); @@ -168,6 +168,40 @@ class FlattenException return $this->trace; } + public function setTraceFromException(\Exception $exception) + { + $trace = $exception->getTrace(); + + if ($exception instanceof FatalErrorException) { + if (function_exists('xdebug_get_function_stack')) { + $trace = array_slice(array_reverse(xdebug_get_function_stack()), 4); + + foreach ($trace as $i => $frame) { + // XDebug pre 2.1.1 doesn't currently set the call type key http://bugs.xdebug.org/view.php?id=695 + if (!isset($frame['type'])) { + $trace[$i]['type'] = '??'; + } + + if ('dynamic' === $trace[$i]['type']) { + $trace[$i]['type'] = '->'; + } elseif ('static' === $trace[$i]['type']) { + $trace[$i]['type'] = '::'; + } + + // XDebug also has a different name for the parameters array + if (isset($frame['params']) && !isset($frame['args'])) { + $trace[$i]['args'] = $frame['params']; + unset($trace[$i]['params']); + } + } + } else { + $trace = array_slice(array_reverse($trace), 1); + } + } + + $this->setTrace($trace, $exception->getFile(), $exception->getLine()); + } + public function setTrace($trace, $file, $line) { $this->trace = array(); diff --git a/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php b/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php index 0eb2d79d4c..e98d326a4b 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\HttpKernel\Tests\Debug; use Symfony\Component\HttpKernel\Debug\ErrorHandler; -use Symfony\Component\HttpKernel\Debug\ErrorException; /** * ErrorHandlerTest @@ -48,10 +47,10 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase $handler = ErrorHandler::register(3); try { - $handler->handle(1, 'foo', 'foo.php', 12, 'foo'); + $handler->handle(111, 'foo', 'foo.php', 12, 'foo'); } catch (\ErrorException $e) { - $this->assertSame('1: foo in foo.php line 12', $e->getMessage()); - $this->assertSame(1, $e->getSeverity()); + $this->assertSame('111: foo in foo.php line 12', $e->getMessage()); + $this->assertSame(111, $e->getSeverity()); $this->assertSame('foo.php', $e->getFile()); $this->assertSame(12, $e->getLine()); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Exception/FlattenExceptionTest.php b/src/Symfony/Component/HttpKernel/Tests/Exception/FlattenExceptionTest.php index cd76c3a637..fa76436744 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Exception/FlattenExceptionTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Exception/FlattenExceptionTest.php @@ -90,14 +90,14 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase public function testToArray(\Exception $exception, $statusCode) { $flattened = FlattenException::create($exception); - $flattened->setTrace(array(),'foo.php',123); + $flattened->setTrace(array(), 'foo.php', 123); $this->assertEquals(array( array( 'message'=> 'test', 'class'=>'Exception', 'trace'=>array(array( - 'namespace' => '', 'short_class' => '', 'class' => '','type' => '','function' => '', 'file' => 'foo.php','line' => 123, + 'namespace' => '', 'short_class' => '', 'class' => '','type' => '','function' => '', 'file' => 'foo.php', 'line' => 123, 'args' => array() )), ) From 918bad6b8587ec13abd83fb89798d1d5d0d7f82e Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 3 Dec 2012 14:13:44 +0100 Subject: [PATCH 009/175] fix phpdoc in ExecutionContextInterface --- .../Validator/ExecutionContextInterface.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Validator/ExecutionContextInterface.php b/src/Symfony/Component/Validator/ExecutionContextInterface.php index cae91a99b4..98a91caa71 100644 --- a/src/Symfony/Component/Validator/ExecutionContextInterface.php +++ b/src/Symfony/Component/Validator/ExecutionContextInterface.php @@ -142,15 +142,15 @@ interface ExecutionContextInterface * Any violations generated during the validation will be added to the * violation list that you can access with {@link getViolations}. * - * @param mixed $value The value to validate. - * @param string $subPath The path to append to the context's property path. - * @param null $groups The groups to validate in. If you don't pass any - * groups here, the current group of the context - * will be used. - * @param bool $traverse Whether to traverse the value if it is an array - * or an instance of \Traversable. - * @param bool $deep Whether to traverse the value recursively if - * it is a collection of collections. + * @param mixed $value The value to validate. + * @param string $subPath The path to append to the context's property path. + * @param null|string|string[] $groups The groups to validate in. If you don't pass any + * groups here, the current group of the context + * will be used. + * @param Boolean $traverse Whether to traverse the value if it is an array + * or an instance of \Traversable. + * @param Boolean $deep Whether to traverse the value recursively if + * it is a collection of collections. */ public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false); @@ -177,7 +177,7 @@ interface ExecutionContextInterface * @param mixed $value The value to validate. * @param Constraint|Constraint[] $constraints The constraint(s) to validate against. * @param string $subPath The path to append to the context's property path. - * @param null $groups The groups to validate in. If you don't pass any + * @param null|string|string[] $groups The groups to validate in. If you don't pass any * groups here, the current group of the context * will be used. */ From faeecf81ce1fa64fdab3fcdf61a80f86be0f534a Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Mon, 3 Dec 2012 15:24:31 +0100 Subject: [PATCH 010/175] Fix namespace of Validator and BrowserKit Tests --- src/Symfony/Component/BrowserKit/Tests/ClientTest.php | 2 +- src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php | 2 +- src/Symfony/Component/BrowserKit/Tests/CookieTest.php | 2 +- src/Symfony/Component/BrowserKit/Tests/HistoryTest.php | 2 +- src/Symfony/Component/BrowserKit/Tests/RequestTest.php | 2 +- src/Symfony/Component/BrowserKit/Tests/ResponseTest.php | 2 +- src/Symfony/Component/Validator/Tests/Constraints/AllTest.php | 2 +- .../Component/Validator/Tests/Constraints/CollectionTest.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php index 91d52df637..e03b73cf0b 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ClientTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ClientTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Tests\BrowserKit; +namespace Symfony\Component\BrowserKit\Tests; use Symfony\Component\BrowserKit\Client; use Symfony\Component\BrowserKit\History; diff --git a/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php b/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php index 0c077d3723..df5cc777d4 100644 --- a/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/CookieJarTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Tests\BrowserKit; +namespace Symfony\Component\BrowserKit\Tests; use Symfony\Component\BrowserKit\CookieJar; use Symfony\Component\BrowserKit\Cookie; diff --git a/src/Symfony/Component/BrowserKit/Tests/CookieTest.php b/src/Symfony/Component/BrowserKit/Tests/CookieTest.php index 2db3ac6f24..13e343a901 100644 --- a/src/Symfony/Component/BrowserKit/Tests/CookieTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/CookieTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Tests\BrowserKit; +namespace Symfony\Component\BrowserKit\Tests; use Symfony\Component\BrowserKit\Cookie; diff --git a/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php b/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php index 6794f31dde..882b730ef4 100644 --- a/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/HistoryTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Tests\BrowserKit; +namespace Symfony\Component\BrowserKit\Tests; use Symfony\Component\BrowserKit\History; use Symfony\Component\BrowserKit\Request; diff --git a/src/Symfony/Component/BrowserKit/Tests/RequestTest.php b/src/Symfony/Component/BrowserKit/Tests/RequestTest.php index c567faddee..b75b5fb5c0 100644 --- a/src/Symfony/Component/BrowserKit/Tests/RequestTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/RequestTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Tests\BrowserKit; +namespace Symfony\Component\BrowserKit\Tests; use Symfony\Component\BrowserKit\Request; diff --git a/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php b/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php index 1e8c638a3b..878752c75e 100644 --- a/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/ResponseTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Tests\BrowserKit; +namespace Symfony\Component\BrowserKit\Tests; use Symfony\Component\BrowserKit\Response; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AllTest.php b/src/Symfony/Component/Validator/Tests/Constraints/AllTest.php index 85b1283f2c..e2db52f60d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AllTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AllTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Allator\Tests\Constraints; +namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\All; use Symfony\Component\Validator\Constraints\Valid; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php index 184d254342..e2998689ac 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CollectionTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Collectionator\Tests\Constraints; +namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Validator\Constraints\Collection; use Symfony\Component\Validator\Constraints\Collection\Required; From 3d0c70e434926211dec019c48365ba169dd585dc Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Mon, 3 Dec 2012 19:34:26 +0100 Subject: [PATCH 011/175] made ExecutionContext more consistent --- src/Symfony/Component/Validator/ExecutionContext.php | 4 ++-- src/Symfony/Component/Validator/ExecutionContextInterface.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/ExecutionContext.php b/src/Symfony/Component/Validator/ExecutionContext.php index af9b2e6b32..75fe059dbb 100644 --- a/src/Symfony/Component/Validator/ExecutionContext.php +++ b/src/Symfony/Component/Validator/ExecutionContext.php @@ -172,9 +172,9 @@ class ExecutionContext implements ExecutionContextInterface /** * {@inheritdoc} */ - public function getPropertyPath($subPath = null) + public function getPropertyPath($subPath = '') { - if (null !== $subPath && '' !== $this->propertyPath && '' !== $subPath && '[' !== $subPath[0]) { + if ('' != $subPath && '' !== $this->propertyPath && '[' !== $subPath[0]) { return $this->propertyPath . '.' . $subPath; } diff --git a/src/Symfony/Component/Validator/ExecutionContextInterface.php b/src/Symfony/Component/Validator/ExecutionContextInterface.php index cae91a99b4..1d065c888c 100644 --- a/src/Symfony/Component/Validator/ExecutionContextInterface.php +++ b/src/Symfony/Component/Validator/ExecutionContextInterface.php @@ -300,5 +300,5 @@ interface ExecutionContextInterface * string if the validator is currently validating the * root value of the validation graph. */ - public function getPropertyPath($subPath = null); + public function getPropertyPath($subPath = ''); } From c70bd034a466a7b4d15b93c1eaaac2c264a7cf6e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 3 Dec 2012 20:10:17 +0100 Subject: [PATCH 012/175] Allow any callable to be passed to Command::setCode --- .../Component/Console/Command/Command.php | 8 ++++-- .../Console/Tests/Command/CommandTest.php | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index e9af834ed3..1b11bb8105 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -247,7 +247,7 @@ class Command * If this method is used, it overrides the code defined * in the execute() method. * - * @param \Closure $code A \Closure + * @param callable $code A callable(InputInterface $input, OutputInterface $output) * * @return Command The current instance * @@ -255,8 +255,12 @@ class Command * * @api */ - public function setCode(\Closure $code) + public function setCode($code) { + if (!is_callable($code)) { + throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.'); + } + $this->code = $code; return $this; diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index eb78b8911e..166ce7879e 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -240,6 +240,31 @@ class CommandTest extends \PHPUnit_Framework_TestCase $this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay()); } + public function testSetCodeWithNonClosureCallable() + { + $command = new \TestCommand(); + $ret = $command->setCode(array($this, 'callableMethodCommand')); + $this->assertEquals($command, $ret, '->setCode() implements a fluent interface'); + $tester = new CommandTester($command); + $tester->execute(array()); + $this->assertEquals('interact called'.PHP_EOL.'from the code...'.PHP_EOL, $tester->getDisplay()); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Invalid callable provided to Command::setCode. + */ + public function testSetCodeWithNonCallable() + { + $command = new \TestCommand(); + $command->setCode(array($this, 'nonExistentMethod')); + } + + public function callableMethodCommand(InputInterface $input, OutputInterface $output) + { + $output->writeln('from the code...'); + } + public function testAsText() { $command = new \TestCommand(); From 2ed30e702fe4beb44b153006f9f0160fbc621551 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Fri, 30 Nov 2012 00:55:51 +0100 Subject: [PATCH 013/175] Fixed DefaultValue for session.auto_start in NodeDefinition This is just for consistency with the node type (Boolean) --- .../FrameworkBundle/DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index e5c1387cfc..8d9b94cfff 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -192,7 +192,7 @@ class Configuration implements ConfigurationInterface ->children() ->booleanNode('auto_start') ->info('DEPRECATED! Session starts on demand') - ->defaultNull() + ->defaultFalse() ->beforeNormalization() ->ifTrue(function($v) { return null !== $v; }) ->then(function($v) { From 0e3671bbe7d5a1c88a3614c245c84f0ffc205643 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Fri, 23 Nov 2012 02:30:05 -0600 Subject: [PATCH 014/175] [WiP] Split urlmatcher for easier overriding --- .../Component/Routing/Matcher/UrlMatcher.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 5c6985447c..e945961a2e 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -43,7 +43,7 @@ class UrlMatcher implements UrlMatcherInterface /** * @var RouteCollection */ - private $routes; + protected $routes; /** * Constructor. @@ -157,10 +157,25 @@ class UrlMatcher implements UrlMatcherInterface continue; } - return $this->mergeDefaults(array_replace($matches, $hostnameMatches, array('_route' => $name)), $route->getDefaults()); + return $this->getAttributes($route, $name, array_replace($matches, $hostnameMatches)); } } + /** + * Returns an array of values to use as request attributes + * + * @param Route $route The route we are matching against + * @param string $name The name of the route + * @param array $attributes An array of attributes from the matcher + * + * @return array An array of parameters + */ + protected function getAttributes(Route $route, $name, array $attributes) + { + $attributes['_route'] = $name; + return $this->mergeDefaults($attributes, $route->getDefaults()); + } + /** * Handles specific route requirements. * From 8af010aad640d08e9d3a23a476db46011ec1039a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 Dec 2012 23:11:37 +0100 Subject: [PATCH 015/175] [Routing] added a warning about UrlMatcher::getAttributes() --- .../Component/Routing/Matcher/UrlMatcher.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index e945961a2e..98d7a1fa08 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -162,17 +162,22 @@ class UrlMatcher implements UrlMatcherInterface } /** - * Returns an array of values to use as request attributes + * Returns an array of values to use as request attributes. * - * @param Route $route The route we are matching against - * @param string $name The name of the route - * @param array $attributes An array of attributes from the matcher + * As this method requires the Route object, it is not available + * in matchers that do not have access to the matched Route instance + * (like the PHP and Apache matcher dumpers). + * + * @param Route $route The route we are matching against + * @param string $name The name of the route + * @param array $attributes An array of attributes from the matcher * * @return array An array of parameters */ protected function getAttributes(Route $route, $name, array $attributes) { $attributes['_route'] = $name; + return $this->mergeDefaults($attributes, $route->getDefaults()); } From 760aee0c1a5e0d4a08be7fb315b0ef2484f45c59 Mon Sep 17 00:00:00 2001 From: jamogon Date: Mon, 3 Dec 2012 23:30:58 +0100 Subject: [PATCH 016/175] Update src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php Remove duplicated semicolon --- .../Form/EventListener/TranslationCollectionFormListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php b/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php index 9011fb0007..3e07518d0c 100644 --- a/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php +++ b/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php @@ -90,7 +90,7 @@ class TranslationCollectionFormListener implements EventSubscriberInterface } } if(!$foundData) { - throw new UnexpectedTypeException($rootData, 'Propel i18n object');; + throw new UnexpectedTypeException($rootData, 'Propel i18n object'); } $newTranslation = new $this->i18nClass(); From d03281b400e8287803dcf3f804bf7b4209af7d68 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 4 Dec 2012 01:06:59 +0100 Subject: [PATCH 017/175] [Security] Move DigestDataTest.php inside the Security component --- .../Component/Security/Tests}/Http/Firewall/DigestDataTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {tests/Symfony/Tests/Component/Security => src/Symfony/Component/Security/Tests}/Http/Firewall/DigestDataTest.php (100%) diff --git a/tests/Symfony/Tests/Component/Security/Http/Firewall/DigestDataTest.php b/src/Symfony/Component/Security/Tests/Http/Firewall/DigestDataTest.php similarity index 100% rename from tests/Symfony/Tests/Component/Security/Http/Firewall/DigestDataTest.php rename to src/Symfony/Component/Security/Tests/Http/Firewall/DigestDataTest.php From acf1f866116dc30837fdb2ed671f7929a3d559f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Tue, 4 Dec 2012 11:28:54 +0100 Subject: [PATCH 018/175] [TwigBundle] Fixed tests --- .../DependencyInjection/TwigExtensionTest.php | 16 ++-- .../TwigBundle/Tests/TwigEngineTest.php | 92 ------------------- 2 files changed, 9 insertions(+), 99 deletions(-) delete mode 100644 src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 17fc9bcb35..f7ba5e987f 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -59,15 +59,17 @@ class TwigExtensionTest extends TestCase // Globals $calls = $container->getDefinition('twig')->getMethodCalls(); - $this->assertEquals('foo', $calls[0][1][0], '->load() registers services as Twig globals'); - $this->assertEquals(new Reference('bar'), $calls[0][1][1], '->load() registers services as Twig globals'); - $this->assertEquals('pi', $calls[1][1][0], '->load() registers variables as Twig globals'); - $this->assertEquals(3.14, $calls[1][1][1], '->load() registers variables as Twig globals'); + $this->assertEquals('app', $calls[0][1][0]); + $this->assertEquals(new Reference('templating.globals'), $calls[0][1][1]); + $this->assertEquals('foo', $calls[1][1][0], '->load() registers services as Twig globals'); + $this->assertEquals(new Reference('bar'), $calls[1][1][1], '->load() registers services as Twig globals'); + $this->assertEquals('pi', $calls[2][1][0], '->load() registers variables as Twig globals'); + $this->assertEquals(3.14, $calls[2][1][1], '->load() registers variables as Twig globals'); // Yaml and Php specific configs if (in_array($format, array('yml', 'php'))) { - $this->assertEquals('bad', $calls[2][1][0], '->load() registers variables as Twig globals'); - $this->assertEquals(array('key' => 'foo'), $calls[2][1][1], '->load() registers variables as Twig globals'); + $this->assertEquals('bad', $calls[3][1][0], '->load() registers variables as Twig globals'); + $this->assertEquals(array('key' => 'foo'), $calls[3][1][1], '->load() registers variables as Twig globals'); } // Twig options @@ -101,7 +103,7 @@ class TwigExtensionTest extends TestCase $calls = $container->getDefinition('twig')->getMethodCalls(); - foreach ($calls as $call) { + foreach (array_slice($calls, 1) as $call) { list($name, $value) = each($globals); $this->assertEquals($name, $call[1][0]); $this->assertSame($value, $call[1][1]); diff --git a/src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php b/src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php deleted file mode 100644 index 23889abd7a..0000000000 --- a/src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php +++ /dev/null @@ -1,92 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests; - -use Symfony\Bundle\TwigBundle\TwigEngine; -use Symfony\Component\DependencyInjection\Container; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Session; -use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage; -use Symfony\Component\Templating\TemplateNameParser; -use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables; - -class TwigEngineTest extends TestCase -{ - public function testEvaluateAddsAppGlobal() - { - $environment = $this->getTwigEnvironment(); - $container = $this->getContainer(); - $engine = new TwigEngine($environment, new TemplateNameParser(), $app = new GlobalVariables($container)); - - $template = $this->getMock('\Twig_TemplateInterface'); - - $environment->expects($this->once()) - ->method('loadTemplate') - ->will($this->returnValue($template)); - - $engine->render('name'); - - $request = $container->get('request'); - $globals = $environment->getGlobals(); - $this->assertSame($app, $globals['app']); - } - - public function testEvaluateWithoutAvailableRequest() - { - $environment = $this->getTwigEnvironment(); - $container = new Container(); - $engine = new TwigEngine($environment, new TemplateNameParser(), new GlobalVariables($container)); - - $template = $this->getMock('\Twig_TemplateInterface'); - - $environment->expects($this->once()) - ->method('loadTemplate') - ->will($this->returnValue($template)); - - $container->set('request', null); - - $engine->render('name'); - - $globals = $environment->getGlobals(); - $this->assertEmpty($globals['app']->getRequest()); - } - - /** - * Creates a Container with a Session-containing Request service. - * - * @return Container - */ - protected function getContainer() - { - $container = new Container(); - $request = new Request(); - $session = new Session(new ArraySessionStorage()); - - $request->setSession($session); - $container->set('request', $request); - - return $container; - } - - /** - * Creates a mock Twig_Environment object. - * - * @return \Twig_Environment - */ - protected function getTwigEnvironment() - { - return $this - ->getMockBuilder('\Twig_Environment') - ->setMethods(array('loadTemplate')) - ->getMock(); - } -} From cf8a6c00f305fcb8c47f3b2d48906d70ec7bba5a Mon Sep 17 00:00:00 2001 From: Felix Labrecque Date: Tue, 4 Dec 2012 10:43:26 -0500 Subject: [PATCH 019/175] Fix my code and also fix the test suite. --- .../Propel1/Tests/Fixtures/ColumnMap.php | 61 ++++++++++++ .../Tests/Fixtures/PropelColumnTypes.php | 96 +++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php create mode 100644 src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php new file mode 100644 index 0000000000..5e8d972b91 --- /dev/null +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\Propel1\Tests\Fixtures; + +class ColumnMap +{ + // Propel type of the column + protected $type; + + // The TableMap for this column + protected $table; + + // The name of the column + protected $columnName; + + public function __construct($name, $containingTable) + { + $this->columnName = $name; + $this->table = $containingTable; + } + + /** + * Set the Propel type of this column. + * + * @param string $type A string representing the Propel type (e.g. PropelColumnTypes::DATE). + * @return void + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * Get the Propel type of this column. + * + * @return string A string representing the Propel type (e.g. PropelColumnTypes::DATE). + */ + public function getType() + { + return $this->type; + } + + /** + * Get the PDO type of this column. + * + * @return int The PDO::PARMA_* value + */ + public function getPdoType() + { + return PropelColumnTypes::getPdoType($this->type); + } +} diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php new file mode 100644 index 0000000000..5fdef59060 --- /dev/null +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php @@ -0,0 +1,96 @@ + (Propel) + * @version $Revision$ + * @package propel.runtime.util + */ +class PropelColumnTypes +{ + + const + CHAR = "CHAR", + VARCHAR = "VARCHAR", + LONGVARCHAR = "LONGVARCHAR", + CLOB = "CLOB", + CLOB_EMU = "CLOB_EMU", + NUMERIC = "NUMERIC", + DECIMAL = "DECIMAL", + TINYINT = "TINYINT", + SMALLINT = "SMALLINT", + INTEGER = "INTEGER", + BIGINT = "BIGINT", + REAL = "REAL", + FLOAT = "FLOAT", + DOUBLE = "DOUBLE", + BINARY = "BINARY", + VARBINARY = "VARBINARY", + LONGVARBINARY = "LONGVARBINARY", + BLOB = "BLOB", + DATE = "DATE", + TIME = "TIME", + TIMESTAMP = "TIMESTAMP", + BU_DATE = "BU_DATE", + BU_TIMESTAMP = "BU_TIMESTAMP", + BOOLEAN = "BOOLEAN", + BOOLEAN_EMU = "BOOLEAN_EMU", + OBJECT = "OBJECT", + PHP_ARRAY = "ARRAY", + ENUM = "ENUM"; + + private static $propelToPdoMap = array( + self::CHAR => \PDO::PARAM_STR, + self::VARCHAR => \PDO::PARAM_STR, + self::LONGVARCHAR => \PDO::PARAM_STR, + self::CLOB => \PDO::PARAM_LOB, + self::CLOB_EMU => \PDO::PARAM_STR, + self::NUMERIC => \PDO::PARAM_STR, + self::DECIMAL => \PDO::PARAM_STR, + self::TINYINT => \PDO::PARAM_INT, + self::SMALLINT => \PDO::PARAM_INT, + self::INTEGER => \PDO::PARAM_INT, + self::BIGINT => \PDO::PARAM_STR, + self::REAL => \PDO::PARAM_STR, + self::FLOAT => \PDO::PARAM_STR, + self::DOUBLE => \PDO::PARAM_STR, + self::BINARY => \PDO::PARAM_STR, + self::VARBINARY => \PDO::PARAM_STR, + self::LONGVARBINARY => \PDO::PARAM_STR, + self::BLOB => \PDO::PARAM_LOB, + self::DATE => \PDO::PARAM_STR, + self::TIME => \PDO::PARAM_STR, + self::TIMESTAMP => \PDO::PARAM_STR, + self::BU_DATE => \PDO::PARAM_STR, + self::BU_TIMESTAMP => \PDO::PARAM_STR, + self::BOOLEAN => \PDO::PARAM_BOOL, + self::BOOLEAN_EMU => \PDO::PARAM_INT, + self::OBJECT => \PDO::PARAM_STR, + self::PHP_ARRAY => \PDO::PARAM_STR, + self::ENUM => \PDO::PARAM_INT, + ); + + /** + * Resturns the PDO type (PDO::PARAM_* constant) value for the Propel type provided. + * @param string $propelType + * @return int + */ + public static function getPdoType($propelType) + { + return self::$propelToPdoMap[$propelType]; + } + +} From 0e4419ba673f1f87a60aef9cef08ac77bacc9a51 Mon Sep 17 00:00:00 2001 From: Felix Labrecque Date: Tue, 4 Dec 2012 10:48:16 -0500 Subject: [PATCH 020/175] I found the error in my latest commit. This pass the test suite. --- .../Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php | 2 +- src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php | 4 +++- .../Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index 82d5e9d49d..684b385edc 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -374,6 +374,6 @@ class ModelChoiceList extends ObjectChoiceList */ private function isInteger($col) { - return $col->getType() === \PDO::PARAM_INT; + return $col->getPdoType() === \PDO::PARAM_INT; } } diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php index 75d2a4f731..b86ed421fd 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php @@ -31,7 +31,9 @@ class ItemQuery public function getPrimaryKeys() { - return array('id'); + $cm = new ColumnMap('id', $this); + $cm->setType('INTEGER'); + return array('id' => $cm); } /** diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php index 8c9677f33d..974e923dc9 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php @@ -22,6 +22,8 @@ class ReadOnlyItemQuery public function getPrimaryKeys() { - return array('id'); + $cm = new ColumnMap('id', $this); + $cm->setType('INTEGER'); + return array('id' => $cm); } } From 812516339531b8cf7f00a546835e1122ae6b4f57 Mon Sep 17 00:00:00 2001 From: woodspire Date: Tue, 4 Dec 2012 13:53:37 -0500 Subject: [PATCH 021/175] removed the TODO mention. Will keep the Propel code here so it can work with older version of Propel --- src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index 684b385edc..76ccaaa090 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -77,7 +77,6 @@ class ModelChoiceList extends ObjectChoiceList } if (1 === count($this->identifier)) { - // TODO this should be current($this->identifier)->isInteger() when propel ColumnMap contains the isInteger function if ($this->isInteger(current($this->identifier))) { $this->identifierAsIndex = true; } @@ -368,7 +367,6 @@ class ModelChoiceList extends ObjectChoiceList /** * Whether this column in an integer - * TODO we could add this function to propel ColumnMap class instead * * @return boolean */ From 6f8cd9daf073278e8f05505e810bf01f2a225403 Mon Sep 17 00:00:00 2001 From: woodspire Date: Tue, 4 Dec 2012 13:58:20 -0500 Subject: [PATCH 022/175] Removed the PropelColumnTypes.php copy Using the Propel class instead, like in Column class --- .../Propel1/Tests/Fixtures/ColumnMap.php | 2 +- .../Tests/Fixtures/PropelColumnTypes.php | 96 ------------------- 2 files changed, 1 insertion(+), 97 deletions(-) delete mode 100644 src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php index 5e8d972b91..8a4a604a53 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php @@ -56,6 +56,6 @@ class ColumnMap */ public function getPdoType() { - return PropelColumnTypes::getPdoType($this->type); + return \PropelColumnTypes::getPdoType($this->type); } } diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php deleted file mode 100644 index 5fdef59060..0000000000 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/PropelColumnTypes.php +++ /dev/null @@ -1,96 +0,0 @@ - (Propel) - * @version $Revision$ - * @package propel.runtime.util - */ -class PropelColumnTypes -{ - - const - CHAR = "CHAR", - VARCHAR = "VARCHAR", - LONGVARCHAR = "LONGVARCHAR", - CLOB = "CLOB", - CLOB_EMU = "CLOB_EMU", - NUMERIC = "NUMERIC", - DECIMAL = "DECIMAL", - TINYINT = "TINYINT", - SMALLINT = "SMALLINT", - INTEGER = "INTEGER", - BIGINT = "BIGINT", - REAL = "REAL", - FLOAT = "FLOAT", - DOUBLE = "DOUBLE", - BINARY = "BINARY", - VARBINARY = "VARBINARY", - LONGVARBINARY = "LONGVARBINARY", - BLOB = "BLOB", - DATE = "DATE", - TIME = "TIME", - TIMESTAMP = "TIMESTAMP", - BU_DATE = "BU_DATE", - BU_TIMESTAMP = "BU_TIMESTAMP", - BOOLEAN = "BOOLEAN", - BOOLEAN_EMU = "BOOLEAN_EMU", - OBJECT = "OBJECT", - PHP_ARRAY = "ARRAY", - ENUM = "ENUM"; - - private static $propelToPdoMap = array( - self::CHAR => \PDO::PARAM_STR, - self::VARCHAR => \PDO::PARAM_STR, - self::LONGVARCHAR => \PDO::PARAM_STR, - self::CLOB => \PDO::PARAM_LOB, - self::CLOB_EMU => \PDO::PARAM_STR, - self::NUMERIC => \PDO::PARAM_STR, - self::DECIMAL => \PDO::PARAM_STR, - self::TINYINT => \PDO::PARAM_INT, - self::SMALLINT => \PDO::PARAM_INT, - self::INTEGER => \PDO::PARAM_INT, - self::BIGINT => \PDO::PARAM_STR, - self::REAL => \PDO::PARAM_STR, - self::FLOAT => \PDO::PARAM_STR, - self::DOUBLE => \PDO::PARAM_STR, - self::BINARY => \PDO::PARAM_STR, - self::VARBINARY => \PDO::PARAM_STR, - self::LONGVARBINARY => \PDO::PARAM_STR, - self::BLOB => \PDO::PARAM_LOB, - self::DATE => \PDO::PARAM_STR, - self::TIME => \PDO::PARAM_STR, - self::TIMESTAMP => \PDO::PARAM_STR, - self::BU_DATE => \PDO::PARAM_STR, - self::BU_TIMESTAMP => \PDO::PARAM_STR, - self::BOOLEAN => \PDO::PARAM_BOOL, - self::BOOLEAN_EMU => \PDO::PARAM_INT, - self::OBJECT => \PDO::PARAM_STR, - self::PHP_ARRAY => \PDO::PARAM_STR, - self::ENUM => \PDO::PARAM_INT, - ); - - /** - * Resturns the PDO type (PDO::PARAM_* constant) value for the Propel type provided. - * @param string $propelType - * @return int - */ - public static function getPdoType($propelType) - { - return self::$propelToPdoMap[$propelType]; - } - -} From 500cc3c4d7edc4222cb169dd353d6487fecd0855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Tue, 4 Dec 2012 11:28:17 +0100 Subject: [PATCH 023/175] [Config] Fixed tests on Windows --- .../Tests/Component/Config/Resource/DirectoryResourceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php b/tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php index 8e2abaeed1..e8175e7786 100644 --- a/tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php +++ b/tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php @@ -38,7 +38,7 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $path) { - if (preg_match('#/\.\.?$#', $path->__toString())) { + if (preg_match('#[/\\\\]\.\.?$#', $path->__toString())) { continue; } if ($path->isDir()) { From 5fe58bffc5ea8bb4853a53c2c9d345801b9af941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Wed, 5 Dec 2012 13:49:46 +0100 Subject: [PATCH 024/175] [Locale] fixed tests --- phpunit.xml.dist | 4 ++ ...teTimeToLocalizedStringTransformerTest.php | 8 ++- .../Locale/Stub/StubIntlDateFormatterTest.php | 62 ++++++++++++------- .../Locale/Stub/StubNumberFormatterTest.php | 43 +++++++------ .../Tests/Component/Locale/TestCase.php | 8 +++ 5 files changed, 82 insertions(+), 43 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 147b39be32..c6628506c9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,6 +11,10 @@ syntaxCheck="false" bootstrap="tests/bootstrap.php" > + + + + ./tests/Symfony/ diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php index cf1a79321b..c0ae5ea143 100644 --- a/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php +++ b/tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php @@ -91,7 +91,9 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase { $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::LONG); - $this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime)); + $expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT'; + + $this->assertEquals($expected, $transformer->transform($this->dateTime)); } public function testTransformFullTime() @@ -102,7 +104,9 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase $transformer = new DateTimeToLocalizedStringTransformer('UTC', 'UTC', null, \IntlDateFormatter::FULL); - $this->assertEquals('03.02.2010 04:05:06 GMT+00:00', $transformer->transform($this->dateTime)); + $expected = $this->isLowerThanIcuVersion('4.8') ? '03.02.2010 04:05:06 GMT+00:00' : '03.02.2010 04:05:06 GMT'; + + $this->assertEquals($expected, $transformer->transform($this->dateTime)); } public function testTransformToDifferentLocale() diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index b3db625221..c99120998d 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -123,10 +123,8 @@ class StubIntlDateFormatterTest extends LocaleTestCase $formatData = array( /* general */ array('y-M-d', 0, '1970-1-1'), - array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00'), array("EEE, MMM d, ''yy", 0, "Thu, Jan 1, '70"), array('h:mm a', 0, '12:00 AM'), - array('K:mm a, z', 0, '0:00 AM, GMT+00:00'), array('yyyyy.MMMM.dd hh:mm aaa', 0, '01970.January.01 12:00 AM'), /* escaping */ @@ -287,26 +285,36 @@ class StubIntlDateFormatterTest extends LocaleTestCase array('s', 3601, '1'), array('s', 3630, '30'), array('s', 43200, '0'), // 12 hours - - /* timezone */ - array('z', 0, 'GMT+00:00'), - array('zz', 0, 'GMT+00:00'), - array('zzz', 0, 'GMT+00:00'), - array('zzzz', 0, 'GMT+00:00'), - array('zzzzz', 0, 'GMT+00:00'), ); + // Timezone + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + // general + $formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", 0, '1970.01.01 at 00:00:00 GMT+00:00'); + $formatData[] = array('K:mm a, z', 0, '0:00 AM, GMT+00:00'); + + // timezone + $formatData[] = array('z', 0, 'GMT+00:00'); + $formatData[] = array('zz', 0, 'GMT+00:00'); + $formatData[] = array('zzz', 0, 'GMT+00:00'); + $formatData[] = array('zzzz', 0, 'GMT+00:00'); + $formatData[] = array('zzzzz', 0, 'GMT+00:00'); + } + // As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances if ($this->isGreaterOrEqualThanPhpVersion('5.3.4')) { $dateTime = new \DateTime('@0'); /* general, DateTime */ $formatData[] = array('y-M-d', $dateTime, '1970-1-1'); - $formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00'); $formatData[] = array("EEE, MMM d, ''yy", $dateTime, "Thu, Jan 1, '70"); $formatData[] = array('h:mm a', $dateTime, '12:00 AM'); - $formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00'); $formatData[] = array('yyyyy.MMMM.dd hh:mm aaa', $dateTime, '01970.January.01 12:00 AM'); + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $formatData[] = array("yyyy.MM.dd 'at' HH:mm:ss zzz", $dateTime, '1970.01.01 at 00:00:00 GMT+00:00'); + $formatData[] = array('K:mm a, z', $dateTime, '0:00 AM, GMT+00:00'); + } } return $formatData; @@ -430,7 +438,9 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->skipIfIntlExtensionIsNotLoaded(); $formatter = $this->createIntlFormatter('zzzz'); $formatter->setTimeZoneId('Pacific/Fiji'); - $this->assertEquals('Fiji Time', $formatter->format(0)); + + $expected = $this->isGreaterOrEqualThanIcuVersion('49') ? 'Fiji Standard Time' : 'Fiji Time'; + $this->assertEquals($expected, $formatter->format(0)); } public function testFormatWithGmtTimezoneStub() @@ -464,7 +474,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase $this->skipIfIntlExtensionIsNotLoaded(); $this->skipIfICUVersionIsTooOld(); - $formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT); + $formatter = new \IntlDateFormatter('en', StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::SHORT, 'UTC'); $formatter->setPattern('yyyy-MM-dd HH:mm:ss'); $this->assertEquals( @@ -493,7 +503,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase } /** - * It seems IntlDateFormatter caches the timezone id when not explicitely set via constructor or by the + * It seems IntlDateFormatter caches the timezone id when not explicitly set via constructor or by the * setTimeZoneId() method. Since testFormatWithDefaultTimezoneIntl() runs using the default environment * time zone, this test would use it too if not running in a separated process. * @@ -561,17 +571,21 @@ class StubIntlDateFormatterTest extends LocaleTestCase public function dateAndTimeTypeProvider() { - return array( + $data = array( array(0, StubIntlDateFormatter::FULL, StubIntlDateFormatter::NONE, 'Thursday, January 1, 1970'), array(0, StubIntlDateFormatter::LONG, StubIntlDateFormatter::NONE, 'January 1, 1970'), array(0, StubIntlDateFormatter::MEDIUM, StubIntlDateFormatter::NONE, 'Jan 1, 1970'), array(0, StubIntlDateFormatter::SHORT, StubIntlDateFormatter::NONE, '1/1/70'), - - array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'), - array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'), array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::MEDIUM, '12:00:00 AM'), array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::SHORT, '12:00 AM'), ); + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::FULL, '12:00:00 AM GMT+00:00'); + $data[] = array(0, StubIntlDateFormatter::NONE, StubIntlDateFormatter::LONG, '12:00:00 AM GMT+00:00'); + } + + return $data; } public function testGetCalendar() @@ -847,10 +861,7 @@ class StubIntlDateFormatterTest extends LocaleTestCase public function parseErrorProvider() { - return array( - array('y-M-d', '1970/1/1'), - array('yy-M-d', '70/1/1'), - + $data = array( // 1 char month array('y-MMMMM-d', '1970-J-1'), array('y-MMMMM-d', '1970-S-1'), @@ -859,6 +870,13 @@ class StubIntlDateFormatterTest extends LocaleTestCase array('y-LLLLL-d', '1970-J-1'), array('y-LLLLL-d', '1970-S-1'), ); + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $data[] = array('y-M-d', '1970/1/1'); + $data[] = array('yy-M-d', '70/1/1'); + } + + return $data; } /** diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index bb9fc85991..7fc2402c3d 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -142,19 +142,11 @@ class StubNumberFormatterTest extends LocaleTestCase public function formatCurrencyWithCurrencyStyleProvider() { - return array( + $data = array( array(100, 'ALL', 'ALL100'), array(-100, 'ALL', '(ALL100)'), array(1000.12, 'ALL', 'ALL1,000'), - array(100, 'BRL', 'R$100.00'), - array(-100, 'BRL', '(R$100.00)'), - array(1000.12, 'BRL', 'R$1,000.12'), - - array(100, 'CRC', '₡100'), - array(-100, 'CRC', '(₡100)'), - array(1000.12, 'CRC', '₡1,000'), - array(100, 'JPY', '¥100'), array(-100, 'JPY', '(¥100)'), array(1000.12, 'JPY', '¥1,000'), @@ -162,16 +154,29 @@ class StubNumberFormatterTest extends LocaleTestCase array(100, 'EUR', '€100.00'), array(-100, 'EUR', '(€100.00)'), array(1000.12, 'EUR', '€1,000.12'), - - // Rounding checks - array(1000.121, 'BRL', 'R$1,000.12'), - array(1000.123, 'BRL', 'R$1,000.12'), - array(1000.125, 'BRL', 'R$1,000.12'), - array(1000.127, 'BRL', 'R$1,000.13'), - array(1000.129, 'BRL', 'R$1,000.13'), - array(11.50999, 'BRL', 'R$11.51'), - array(11.9999464, 'BRL', 'R$12.00') ); + + if (!$this->isIntlExtensionLoaded() || !$this->isSameAsIcuVersion('4.8')) { + // Rounding checks + $data[] = array(100, 'BRL', 'R$100.00'); + $data[] = array(-100, 'BRL', '(R$100.00)'); + $data[] = array(1000.12, 'BRL', 'R$1,000.12'); + $data[] = array(1000.121, 'BRL', 'R$1,000.12'); + $data[] = array(1000.123, 'BRL', 'R$1,000.12'); + $data[] = array(1000.125, 'BRL', 'R$1,000.12'); + $data[] = array(1000.127, 'BRL', 'R$1,000.13'); + $data[] = array(1000.129, 'BRL', 'R$1,000.13'); + $data[] = array(11.50999, 'BRL', 'R$11.51'); + $data[] = array(11.9999464, 'BRL', 'R$12.00'); + } + + if (!$this->isIntlExtensionLoaded() || $this->isLowerThanIcuVersion('4.8')) { + $data[] = array(100, 'CRC', '₡100'); + $data[] = array(-100, 'CRC', '(₡100)'); + $data[] = array(1000.12, 'CRC', '₡1,000'); + } + + return $data; } /** @@ -180,7 +185,7 @@ class StubNumberFormatterTest extends LocaleTestCase public function testFormatCurrencyWithCurrencyStyleSwissRoundingStub($value, $currency, $symbol, $expected) { $formatter = $this->getStubFormatterWithCurrencyStyle(); - $this->assertEquals(sprintf($expected, 'CHF'), $formatter->formatCurrency($value, $currency)); + $this->assertEquals(sprintf($expected, $symbol), $formatter->formatCurrency($value, $currency)); } /** diff --git a/tests/Symfony/Tests/Component/Locale/TestCase.php b/tests/Symfony/Tests/Component/Locale/TestCase.php index 8df87e447b..3ee1c60449 100644 --- a/tests/Symfony/Tests/Component/Locale/TestCase.php +++ b/tests/Symfony/Tests/Component/Locale/TestCase.php @@ -71,6 +71,14 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase return $icuVersion >= $version; } + protected function isSameAsIcuVersion($version) + { + $version = $this->normalizeIcuVersion($version); + $icuVersion = $this->normalizeIcuVersion($this->getIntlExtensionIcuVersion()); + + return $icuVersion === $version; + } + protected function isLowerThanIcuVersion($version) { $version = $this->normalizeIcuVersion($version); From 36d6c40bb19cd3c14ec247ad8b2a13160041f9ce Mon Sep 17 00:00:00 2001 From: woodspire Date: Wed, 5 Dec 2012 08:35:28 -0500 Subject: [PATCH 025/175] fix indentation problem --- .../Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index 76ccaaa090..e882571370 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -77,9 +77,9 @@ class ModelChoiceList extends ObjectChoiceList } if (1 === count($this->identifier)) { - if ($this->isInteger(current($this->identifier))) { - $this->identifierAsIndex = true; - } + if ($this->isInteger(current($this->identifier))) { + $this->identifierAsIndex = true; + } } parent::__construct($choices, $labelPath, array(), $groupPath); @@ -372,6 +372,6 @@ class ModelChoiceList extends ObjectChoiceList */ private function isInteger($col) { - return $col->getPdoType() === \PDO::PARAM_INT; + return $col->getPdoType() === PDO::PARAM_INT; } } From e5e3341a6db52eb8a1794ce34c6ad5f67ebaebe0 Mon Sep 17 00:00:00 2001 From: woodspire Date: Wed, 5 Dec 2012 08:37:06 -0500 Subject: [PATCH 026/175] oups. It seems that here, we need \PDO --- src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index e882571370..0a2585fe16 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -372,6 +372,6 @@ class ModelChoiceList extends ObjectChoiceList */ private function isInteger($col) { - return $col->getPdoType() === PDO::PARAM_INT; + return $col->getPdoType() === \PDO::PARAM_INT; } } From 6fb953645fce86f435db646ce05d788dc485ca85 Mon Sep 17 00:00:00 2001 From: woodspire Date: Wed, 5 Dec 2012 08:39:27 -0500 Subject: [PATCH 027/175] fix indentation problem --- src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php index 8a4a604a53..8440adc719 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php @@ -36,7 +36,7 @@ class ColumnMap */ public function setType($type) { - $this->type = $type; + $this->type = $type; } /** @@ -46,7 +46,7 @@ class ColumnMap */ public function getType() { - return $this->type; + return $this->type; } /** @@ -56,6 +56,6 @@ class ColumnMap */ public function getPdoType() { - return \PropelColumnTypes::getPdoType($this->type); + return \PropelColumnTypes::getPdoType($this->type); } } From 5e8d401008f38b98ea7235b95a4630ada0b898c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Je=CC=81ro=CC=82me=20Vieilledent?= Date: Thu, 22 Nov 2012 00:15:19 +0100 Subject: [PATCH 028/175] Implemented possibility to skip key normalization in config processing --- .../Component/Config/Definition/Processor.php | 12 ++++++++---- .../HttpKernel/DependencyInjection/Extension.php | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/Processor.php b/src/Symfony/Component/Config/Definition/Processor.php index 3b00c7e4c0..10aca917c5 100644 --- a/src/Symfony/Component/Config/Definition/Processor.php +++ b/src/Symfony/Component/Config/Definition/Processor.php @@ -23,12 +23,15 @@ class Processor * * @param NodeInterface $configTree The node tree describing the configuration * @param array $configs An array of configuration items to process + * @param bool $normalizeKeys Flag indicating if config key normalization is needed. True by default. * * @return array The processed configuration */ - public function process(NodeInterface $configTree, array $configs) + public function process(NodeInterface $configTree, array $configs, $normalizeKeys = true) { - $configs = self::normalizeKeys($configs); + if ($normalizeKeys) { + $configs = self::normalizeKeys($configs); + } $currentConfig = array(); foreach ($configs as $config) { @@ -44,12 +47,13 @@ class Processor * * @param ConfigurationInterface $configuration The configuration class * @param array $configs An array of configuration items to process + * @param bool $normalizeKeys Flag indicating if config key normalization is needed. True by default. * * @return array The processed configuration */ - public function processConfiguration(ConfigurationInterface $configuration, array $configs) + public function processConfiguration(ConfigurationInterface $configuration, array $configs, $normalizeKeys = true) { - return $this->process($configuration->getConfigTreeBuilder()->buildTree(), $configs); + return $this->process($configuration->getConfigTreeBuilder()->buildTree(), $configs, $normalizeKeys); } /** diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php index 5c8d5e69ad..418a4eb669 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php @@ -96,11 +96,11 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn return Container::underscore($classBaseName); } - final protected function processConfiguration(ConfigurationInterface $configuration, array $configs) + final protected function processConfiguration(ConfigurationInterface $configuration, array $configs, $normalizeKeys = true) { $processor = new Processor(); - return $processor->processConfiguration($configuration, $configs); + return $processor->processConfiguration($configuration, $configs, $normalizeKeys); } /** From ffd87591e1b9f86cd176379960acaa94392d1926 Mon Sep 17 00:00:00 2001 From: woodspire Date: Wed, 5 Dec 2012 15:30:04 -0500 Subject: [PATCH 029/175] fix some formatting issue --- .../Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php | 7 +++---- src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php | 1 + .../Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index 0a2585fe16..8f00c6596e 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -76,10 +76,9 @@ class ModelChoiceList extends ObjectChoiceList $choices = array(); } - if (1 === count($this->identifier)) { - if ($this->isInteger(current($this->identifier))) { - $this->identifierAsIndex = true; - } + if ( 1 === count($this->identifier) + && $this->isInteger(current($this->identifier))) { + $this->identifierAsIndex = true; } parent::__construct($choices, $labelPath, array(), $groupPath); diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php index b86ed421fd..20c52d63e5 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php @@ -33,6 +33,7 @@ class ItemQuery { $cm = new ColumnMap('id', $this); $cm->setType('INTEGER'); + return array('id' => $cm); } diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php index 974e923dc9..a356837e29 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php @@ -24,6 +24,7 @@ class ReadOnlyItemQuery { $cm = new ColumnMap('id', $this); $cm->setType('INTEGER'); + return array('id' => $cm); } } From a26a6904d8c3e5bf44b3e0d242af80aea4b9b495 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 5 Dec 2012 21:46:02 +0100 Subject: [PATCH 030/175] remove useless ColumnMap --- .../Propel1/Tests/Fixtures/ColumnMap.php | 61 ------------------- 1 file changed, 61 deletions(-) delete mode 100644 src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php deleted file mode 100644 index 8440adc719..0000000000 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ColumnMap.php +++ /dev/null @@ -1,61 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\Propel1\Tests\Fixtures; - -class ColumnMap -{ - // Propel type of the column - protected $type; - - // The TableMap for this column - protected $table; - - // The name of the column - protected $columnName; - - public function __construct($name, $containingTable) - { - $this->columnName = $name; - $this->table = $containingTable; - } - - /** - * Set the Propel type of this column. - * - * @param string $type A string representing the Propel type (e.g. PropelColumnTypes::DATE). - * @return void - */ - public function setType($type) - { - $this->type = $type; - } - - /** - * Get the Propel type of this column. - * - * @return string A string representing the Propel type (e.g. PropelColumnTypes::DATE). - */ - public function getType() - { - return $this->type; - } - - /** - * Get the PDO type of this column. - * - * @return int The PDO::PARMA_* value - */ - public function getPdoType() - { - return \PropelColumnTypes::getPdoType($this->type); - } -} From 86ab4b345af487de101946cabc8df14add8e8f06 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 5 Dec 2012 21:47:05 +0100 Subject: [PATCH 031/175] Add typehint to isInteger(), fix tests --- .../Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php | 10 ++++++---- .../Bridge/Propel1/Tests/Fixtures/ItemQuery.php | 2 +- .../Propel1/Tests/Fixtures/ReadOnlyItemQuery.php | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index 8f00c6596e..5d94040622 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -347,8 +347,8 @@ class ModelChoiceList extends ObjectChoiceList * be persisted or added to the idmodel map before. Otherwise an * exception is thrown. * - * @param object $model The model for which to get the identifier - * @throws FormException If the model does not exist + * @param object $model The model for which to get the identifier + * @throws FormException If the model does not exist */ private function getIdentifierValues($model) { @@ -367,10 +367,12 @@ class ModelChoiceList extends ObjectChoiceList /** * Whether this column in an integer * + * @param ColumnMap $column + * * @return boolean */ - private function isInteger($col) + private function isInteger(\ColumnMap $column) { - return $col->getPdoType() === \PDO::PARAM_INT; + return $column->getPdoType() === \PDO::PARAM_INT; } } diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php index 20c52d63e5..fe2d03e05f 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ItemQuery.php @@ -31,7 +31,7 @@ class ItemQuery public function getPrimaryKeys() { - $cm = new ColumnMap('id', $this); + $cm = new \ColumnMap('id', new \TableMap()); $cm->setType('INTEGER'); return array('id' => $cm); diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php index a356837e29..0e77c26fcf 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/ReadOnlyItemQuery.php @@ -22,7 +22,7 @@ class ReadOnlyItemQuery public function getPrimaryKeys() { - $cm = new ColumnMap('id', $this); + $cm = new \ColumnMap('id', new \TableMap()); $cm->setType('INTEGER'); return array('id' => $cm); From a3a832c2c171ffbe0abe6b648ad41980a16e1895 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 5 Dec 2012 21:49:32 +0100 Subject: [PATCH 032/175] Fix CS in the whole Propel1 bridge --- .../Propel1/DataCollector/PropelDataCollector.php | 12 ++++++------ .../Propel1/Form/ChoiceList/ModelChoiceList.php | 6 +++--- .../TranslationCollectionFormListener.php | 2 +- src/Symfony/Bridge/Propel1/Logger/PropelLogger.php | 2 +- .../Propel1/Tests/Fixtures/TranslatableItem.php | 3 +-- .../Propel1/Tests/Fixtures/TranslatableItemI18n.php | 7 ++----- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Bridge/Propel1/DataCollector/PropelDataCollector.php b/src/Symfony/Bridge/Propel1/DataCollector/PropelDataCollector.php index 644705f05c..bbb15fb9a0 100644 --- a/src/Symfony/Bridge/Propel1/DataCollector/PropelDataCollector.php +++ b/src/Symfony/Bridge/Propel1/DataCollector/PropelDataCollector.php @@ -63,7 +63,7 @@ class PropelDataCollector extends DataCollector /** * Returns the collector name. * - * @return string The collector name. + * @return string The collector name. */ public function getName() { @@ -73,7 +73,7 @@ class PropelDataCollector extends DataCollector /** * Returns queries. * - * @return array Queries + * @return array Queries */ public function getQueries() { @@ -83,7 +83,7 @@ class PropelDataCollector extends DataCollector /** * Returns the query count. * - * @return int The query count + * @return int The query count */ public function getQueryCount() { @@ -93,7 +93,7 @@ class PropelDataCollector extends DataCollector /** * Returns the total time of queries. * - * @return float The total time of queries + * @return float The total time of queries */ public function getTime() { @@ -108,7 +108,7 @@ class PropelDataCollector extends DataCollector /** * Creates an array of Build objects. * - * @return array An array of Build objects + * @return array An array of Build objects */ private function buildQueries() { @@ -138,7 +138,7 @@ class PropelDataCollector extends DataCollector /** * Count queries. * - * @return int The number of queries. + * @return int The number of queries. */ private function countQueries() { diff --git a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php index 5d94040622..ed46134c52 100644 --- a/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php +++ b/src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php @@ -76,8 +76,7 @@ class ModelChoiceList extends ObjectChoiceList $choices = array(); } - if ( 1 === count($this->identifier) - && $this->isInteger(current($this->identifier))) { + if (1 === count($this->identifier) && $this->isInteger(current($this->identifier))) { $this->identifierAsIndex = true; } @@ -347,7 +346,8 @@ class ModelChoiceList extends ObjectChoiceList * be persisted or added to the idmodel map before. Otherwise an * exception is thrown. * - * @param object $model The model for which to get the identifier + * @param object $model The model for which to get the identifier + * * @throws FormException If the model does not exist */ private function getIdentifierValues($model) diff --git a/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php b/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php index 3e07518d0c..ae39700736 100644 --- a/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php +++ b/src/Symfony/Bridge/Propel1/Form/EventListener/TranslationCollectionFormListener.php @@ -89,7 +89,7 @@ class TranslationCollectionFormListener implements EventSubscriberInterface break; } } - if(!$foundData) { + if (!$foundData) { throw new UnexpectedTypeException($rootData, 'Propel i18n object'); } diff --git a/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php b/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php index 8e38f2418e..1fd7dedf90 100644 --- a/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php +++ b/src/Symfony/Bridge/Propel1/Logger/PropelLogger.php @@ -161,7 +161,7 @@ class PropelLogger /** * Returns queries. * - * @return array Queries + * @return array Queries */ public function getQueries() { diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItem.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItem.php index 95ac0e1526..c69fe45299 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItem.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItem.php @@ -112,8 +112,7 @@ class TranslatableItem implements \Persistent public function addTranslatableItemI18n(TranslatableItemI18n $i) { - if(!in_array($i, $this->currentTranslations)) - { + if (!in_array($i, $this->currentTranslations)) { $this->currentTranslations[$i->getLocale()] = $i; $i->setItem($this); } diff --git a/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItemI18n.php b/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItemI18n.php index c9eb690a43..1253b26c26 100644 --- a/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItemI18n.php +++ b/src/Symfony/Bridge/Propel1/Tests/Fixtures/TranslatableItemI18n.php @@ -13,8 +13,8 @@ namespace Symfony\Bridge\Propel1\Tests\Fixtures; use PropelPDO; -class TranslatableItemI18n implements \Persistent { - +class TranslatableItemI18n implements \Persistent +{ private $id; private $locale; @@ -100,7 +100,6 @@ class TranslatableItemI18n implements \Persistent { public function getLocale() { - return $this->locale; } @@ -122,7 +121,6 @@ class TranslatableItemI18n implements \Persistent { public function getValue() { - return $this->value; } @@ -134,7 +132,6 @@ class TranslatableItemI18n implements \Persistent { public function getValue2() { - return $this->value2; } } From 4878ec08e6e6dc08f79c1870a753ec23a7401b44 Mon Sep 17 00:00:00 2001 From: Colin Frei Date: Sat, 1 Dec 2012 12:25:00 +0100 Subject: [PATCH 033/175] [HttpKernel] [WebProfilerBundle] Better handling of deprecated methods --- .../Resources/config/debug.xml | 7 +++ .../views/Collector/logger.html.twig | 31 +++++++++---- .../DataCollector/LoggerDataCollector.php | 22 +++++++++- .../HttpKernel/Debug/ErrorHandler.php | 18 ++++++++ .../DeprecationLoggerListener.php | 44 +++++++++++++++++++ .../DataCollector/LoggerDataCollectorTest.php | 19 ++++++-- .../Tests/Debug/ErrorHandlerTest.php | 22 ++++++++++ .../Loader/schema/routing/routing-1.0.xsd | 38 ++++++++++------ .../RememberMe/AbstractRememberMeServices.php | 6 +++ ...PersistentTokenBasedRememberMeServices.php | 1 - 10 files changed, 180 insertions(+), 28 deletions(-) create mode 100644 src/Symfony/Component/HttpKernel/EventListener/DeprecationLoggerListener.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml index a1c332a6ab..7d10cc70b9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml @@ -9,6 +9,7 @@ Symfony\Component\Stopwatch\Stopwatch %kernel.cache_dir%/%kernel.container_class%.xml Symfony\Component\HttpKernel\Controller\TraceableControllerResolver + Symfony\Component\HttpKernel\EventListener\DeprecationLoggerListener @@ -26,5 +27,11 @@ + + + + + + diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig index 65d93a64d2..36a3fb0be2 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig @@ -1,16 +1,30 @@ {% extends '@WebProfiler/Profiler/layout.html.twig' %} {% block toolbar %} - {% if collector.counterrors %} + {% if collector.counterrors or collector.countdeprecations %} {% set icon %} Logs - {{ collector.counterrors }} + {% if collector.counterrors %} + {% set statusColor = "red" %} + {% else %} + {% set statusColor = "yellow" %} + {% endif %} + {% set errorCount = collector.counterrors + collector.countdeprecations %} + {{ errorCount }} {% endset %} {% set text %} -
- Exception - {{ collector.counterrors }} -
+ {% if collector.counterrors %} +
+ Exception + {{ collector.counterrors }} +
+ {% endif %} + {% if collector.countdeprecations %} +
+ Deprecated Calls + {{ collector.countdeprecations }} +
+ {% endif %} {% endset %} {% include '@WebProfiler/Profiler/toolbar_item.html.twig' with { 'link': profiler_url } %} {% endif %} @@ -20,9 +34,10 @@ Logger Logs - {% if collector.counterrors %} + {% if collector.counterrors or collector.countdeprecations %} + {% set errorCount = collector.counterrors + collector.countdeprecations %} - {{ collector.counterrors }} + {{ errorCount }} {% endif %} diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php index 97f7165303..629b451f70 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php @@ -38,8 +38,9 @@ class LoggerDataCollector extends DataCollector { if (null !== $this->logger) { $this->data = array( - 'error_count' => $this->logger->countErrors(), - 'logs' => $this->sanitizeLogs($this->logger->getLogs()), + 'error_count' => $this->logger->countErrors(), + 'logs' => $this->sanitizeLogs($this->logger->getLogs()), + 'deprecation_count' => $this->computeDeprecationCount() ); } } @@ -66,6 +67,11 @@ class LoggerDataCollector extends DataCollector return isset($this->data['logs']) ? $this->data['logs'] : array(); } + public function countDeprecations() + { + return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0; + } + /** * {@inheritdoc} */ @@ -103,4 +109,16 @@ class LoggerDataCollector extends DataCollector return $context; } + + private function computeDeprecationCount() + { + $count = 0; + foreach ($this->logger->getLogs() as $log) { + if (isset($log['context']['type']) && 'deprecation' === $log['context']['type']) { + $count++; + } + } + + return $count; + } } diff --git a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php index 605c08626c..d4bed00f43 100644 --- a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php +++ b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php @@ -11,6 +11,8 @@ namespace Symfony\Component\HttpKernel\Debug; +use Symfony\Component\HttpKernel\Log\LoggerInterface; + /** * ErrorHandler. * @@ -32,6 +34,9 @@ class ErrorHandler private $level; + /** @var LoggerInterface */ + private static $logger; + /** * Register the error handler. * @@ -54,6 +59,11 @@ class ErrorHandler $this->level = null === $level ? error_reporting() : $level; } + public static function setLogger(LoggerInterface $logger) + { + self::$logger = $logger; + } + /** * @throws \ErrorException When error_reporting returns error */ @@ -63,6 +73,14 @@ class ErrorHandler return false; } + if ($level & E_USER_DEPRECATED || $level & E_DEPRECATED) { + if (null !== self::$logger) { + self::$logger->warn($message, array('type' => 'deprecation', 'file' => $file, 'line' => $line)); + } + + return true; + } + if (error_reporting() & $level && $this->level & $level) { throw new \ErrorException(sprintf('%s: %s in %s line %d', isset($this->levels[$level]) ? $this->levels[$level] : $level, $message, $file, $line), 0, $level, $file, $line); } diff --git a/src/Symfony/Component/HttpKernel/EventListener/DeprecationLoggerListener.php b/src/Symfony/Component/HttpKernel/EventListener/DeprecationLoggerListener.php new file mode 100644 index 0000000000..a40e866155 --- /dev/null +++ b/src/Symfony/Component/HttpKernel/EventListener/DeprecationLoggerListener.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\EventListener; + +use Symfony\Component\HttpKernel\Log\LoggerInterface; +use Symfony\Component\HttpKernel\Debug\ErrorHandler; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\KernelEvents; + +/** + * Injects the logger into the ErrorHandler, so that it can log deprecation errors. + * + * @author Colin Frei + */ +class DeprecationLoggerListener implements EventSubscriberInterface +{ + private $logger; + + public function __construct(LoggerInterface $logger = null) + { + $this->logger = $logger; + } + + public function injectLogger() + { + if (null !== $this->logger) { + ErrorHandler::setLogger($this->logger); + } + } + + public static function getSubscribedEvents() + { + return array(KernelEvents::REQUEST => 'injectLogger'); + } +} diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php index a4b853c3ed..c4ec7634a4 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php @@ -27,18 +27,19 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase /** * @dataProvider getCollectTestData */ - public function testCollect($nb, $logs, $expected) + public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount) { $logger = $this->getMock('Symfony\Component\HttpKernel\Log\DebugLoggerInterface'); $logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb)); - $logger->expects($this->once())->method('getLogs')->will($this->returnValue($logs)); + $logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs)); $c = new LoggerDataCollector($logger); $c->collect(new Request(), new Response()); $this->assertSame('logger', $c->getName()); $this->assertSame($nb, $c->countErrors()); - $this->assertSame($expected ? $expected : $logs, $c->getLogs()); + $this->assertSame($expectedLogs ? $expectedLogs : $logs, $c->getLogs()); + $this->assertSame($expectedDeprecationCount, $c->countDeprecations()); } public function getCollectTestData() @@ -48,16 +49,28 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase 1, array(array('message' => 'foo', 'context' => array())), null, + 0 ), array( 1, array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')))), array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'))), + 0 ), array( 1, array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()))), array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'))), + 0 + ), + array( + 1, + array( + array('message' => 'foo', 'context' => array('type' => 'deprecation')), + array('message' => 'foo2', 'context' => array('type' => 'deprecation')) + ), + null, + 2 ), ); } diff --git a/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php b/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php index 0eb2d79d4c..df1d23b53d 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php @@ -57,5 +57,27 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase } restore_error_handler(); + + $handler = ErrorHandler::register(E_USER_DEPRECATED); + $this->assertTrue($handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, 'foo')); + + restore_error_handler(); + + $handler = ErrorHandler::register(E_DEPRECATED); + $this->assertTrue($handler->handle(E_DEPRECATED, 'foo', 'foo.php', 12, 'foo')); + + restore_error_handler(); + + $logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface'); + $logger->expects($this->once())->method('warn')->with( + $this->equalTo('foo'), + $this->equalTo(array('type' => 'deprecation', 'file' => 'foo.php', 'line' => '12')) + ); + + $handler = ErrorHandler::register(E_USER_DEPRECATED); + $handler->setLogger($logger); + $handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, 'foo'); + + restore_error_handler(); } } diff --git a/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd b/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd index e1a97654d6..bf502e8208 100644 --- a/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd +++ b/src/Symfony/Component/Routing/Loader/schema/routing/routing-1.0.xsd @@ -5,33 +5,43 @@ targetNamespace="http://symfony.com/schema/routing" elementFormDefault="qualified"> + + + + - + - - - - - - + + + + + + + - - + + + + + - - - - - + diff --git a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php index e7a78ce6f0..1d6a109f07 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/AbstractRememberMeServices.php @@ -195,6 +195,12 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface $this->logger->debug('Remember-me was requested; setting cookie.'); } + // Remove attribute from request that sets a NULL cookie. + // It was set by $this->cancelCookie() + // (cancelCookie does other things too for some RememberMeServices + // so we should still call it at the start of this method) + $request->attributes->remove(self::COOKIE_ATTR_NAME); + $this->onLoginSuccess($request, $response, $token); } diff --git a/src/Symfony/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServices.php index 2ad47f8c5e..9f4013d1b2 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServices.php @@ -133,7 +133,6 @@ class PersistentTokenBasedRememberMeServices extends AbstractRememberMeServices ) ); - $request->attributes->remove(self::COOKIE_ATTR_NAME); $response->headers->setCookie( new Cookie( $this->options['name'], From abe244f0c97845e254d6e8fd4a5364130ee8606a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 6 Dec 2012 09:55:04 +0100 Subject: [PATCH 034/175] [TwigBundle] Fixed tests on windows --- .../TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index 45ac7799a8..e778a16212 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -135,7 +135,7 @@ class TwigExtensionTest extends TestCase array('namespaced_path1', 'namespace'), array('namespaced_path2', 'namespace'), array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'), - array(realpath(__DIR__.'/../../Resources/views'), 'Twig'), + array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'), array(__DIR__.'/Fixtures/Resources/views'), ), $paths); } From 6236c1835c289be4f1966cb8bee77cacfff17c22 Mon Sep 17 00:00:00 2001 From: Sebastian Krebs Date: Wed, 21 Nov 2012 21:00:39 +0100 Subject: [PATCH 035/175] [FrameworkBundle] Added caching to TemplateController --- .../Controller/TemplateController.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php index fd6f1aaf78..4357e76ad4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php @@ -25,11 +25,28 @@ class TemplateController extends ContainerAware * Renders a template. * * @param string $template The template name + * @param int|null $maxAge Max age for client caching + * @param int|null $sharedAge Max age for shared (proxy) caching + * @param Boolean|null $private Whether or not caching should apply for client caches only * * @return Response A Response instance */ - public function templateAction($template) + public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null) { - return $this->container->get('templating')->renderResponse($template); + /** @var $response \Symfony\Component\HttpFoundation\Response */ + $response = $this->container->get('templating')->renderResponse($template); + if ($maxAge) { + $response->setMaxAge($maxAge); + } + if ($sharedAge) { + $response->setSharedMaxAge($sharedAge); + } + + if ($private) { + $response->setPrivate(); + } else if ($private === false || (is_null($private) && ($maxAge || $sharedAge))) { + $response->setPublic($private); + } + return $response; } } From aee033699bd3aeeaba12d5ac1192b4f9d176c786 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 6 Dec 2012 09:58:41 +0100 Subject: [PATCH 036/175] fixed CS --- .../Controller/TemplateController.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php index 4357e76ad4..105d14a8fe 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/TemplateController.php @@ -24,10 +24,10 @@ class TemplateController extends ContainerAware /** * Renders a template. * - * @param string $template The template name - * @param int|null $maxAge Max age for client caching - * @param int|null $sharedAge Max age for shared (proxy) caching - * @param Boolean|null $private Whether or not caching should apply for client caches only + * @param string $template The template name + * @param int|null $maxAge Max age for client caching + * @param int|null $sharedAge Max age for shared (proxy) caching + * @param Boolean|null $private Whether or not caching should apply for client caches only * * @return Response A Response instance */ @@ -35,18 +35,21 @@ class TemplateController extends ContainerAware { /** @var $response \Symfony\Component\HttpFoundation\Response */ $response = $this->container->get('templating')->renderResponse($template); + if ($maxAge) { $response->setMaxAge($maxAge); } + if ($sharedAge) { $response->setSharedMaxAge($sharedAge); } if ($private) { $response->setPrivate(); - } else if ($private === false || (is_null($private) && ($maxAge || $sharedAge))) { + } elseif ($private === false || (null === $private && ($maxAge || $sharedAge))) { $response->setPublic($private); } + return $response; } } From 10e5f3b3dff836fdb69b1c3e5de7a2ee4d2d4aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 6 Dec 2012 09:03:32 +0100 Subject: [PATCH 037/175] Removed useless branch alias for dev-master in composer.json --- composer.json | 7 +------ src/Symfony/Bridge/Doctrine/composer.json | 7 +------ src/Symfony/Bridge/Monolog/composer.json | 7 +------ src/Symfony/Bridge/Propel1/composer.json | 7 +------ src/Symfony/Bridge/Swiftmailer/composer.json | 7 +------ src/Symfony/Bridge/Twig/composer.json | 7 +------ src/Symfony/Bundle/FrameworkBundle/composer.json | 7 +------ src/Symfony/Bundle/SecurityBundle/composer.json | 7 +------ src/Symfony/Bundle/TwigBundle/composer.json | 7 +------ src/Symfony/Bundle/WebProfilerBundle/composer.json | 7 +------ src/Symfony/Component/BrowserKit/composer.json | 7 +------ src/Symfony/Component/ClassLoader/composer.json | 7 +------ src/Symfony/Component/Config/composer.json | 7 +------ src/Symfony/Component/Console/composer.json | 7 +------ src/Symfony/Component/CssSelector/composer.json | 7 +------ src/Symfony/Component/DependencyInjection/composer.json | 7 +------ src/Symfony/Component/DomCrawler/composer.json | 7 +------ src/Symfony/Component/EventDispatcher/composer.json | 7 +------ src/Symfony/Component/Filesystem/composer.json | 7 +------ src/Symfony/Component/Finder/composer.json | 7 +------ src/Symfony/Component/Form/composer.json | 7 +------ src/Symfony/Component/HttpFoundation/composer.json | 7 +------ src/Symfony/Component/HttpKernel/composer.json | 7 +------ src/Symfony/Component/Locale/composer.json | 7 +------ src/Symfony/Component/OptionsResolver/composer.json | 7 +------ src/Symfony/Component/Process/composer.json | 7 +------ src/Symfony/Component/Routing/composer.json | 7 +------ src/Symfony/Component/Security/composer.json | 7 +------ src/Symfony/Component/Serializer/composer.json | 7 +------ src/Symfony/Component/Templating/composer.json | 7 +------ src/Symfony/Component/Translation/composer.json | 7 +------ src/Symfony/Component/Validator/composer.json | 7 +------ src/Symfony/Component/Yaml/composer.json | 7 +------ 33 files changed, 33 insertions(+), 198 deletions(-) diff --git a/composer.json b/composer.json index c80d3253ee..057917bf00 100644 --- a/composer.json +++ b/composer.json @@ -67,10 +67,5 @@ "SessionHandlerInterface": "src/Symfony/Component/HttpFoundation/Resources/stubs" } }, - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 7f28419f5b..37a7a6e66a 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -30,10 +30,5 @@ "psr-0": { "Symfony\\Bridge\\Doctrine": "" } }, "target-dir": "Symfony/Bridge/Doctrine", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bridge/Monolog/composer.json b/src/Symfony/Bridge/Monolog/composer.json index 558b990d1e..fa1c718c31 100644 --- a/src/Symfony/Bridge/Monolog/composer.json +++ b/src/Symfony/Bridge/Monolog/composer.json @@ -24,10 +24,5 @@ "psr-0": { "Symfony\\Bridge\\Monolog": "" } }, "target-dir": "Symfony/Bridge/Monolog", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bridge/Propel1/composer.json b/src/Symfony/Bridge/Propel1/composer.json index 678e78be31..696174ab26 100644 --- a/src/Symfony/Bridge/Propel1/composer.json +++ b/src/Symfony/Bridge/Propel1/composer.json @@ -26,10 +26,5 @@ "psr-0": { "Symfony\\Bridge\\Propel1": "" } }, "target-dir": "Symfony/Bridge/Propel1", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bridge/Swiftmailer/composer.json b/src/Symfony/Bridge/Swiftmailer/composer.json index b0c5e134af..194e72621a 100644 --- a/src/Symfony/Bridge/Swiftmailer/composer.json +++ b/src/Symfony/Bridge/Swiftmailer/composer.json @@ -26,10 +26,5 @@ "psr-0": { "Symfony\\Bridge\\Swiftmailer": "" } }, "target-dir": "Symfony/Bridge/Swiftmailer", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 8d2f0eaab4..04942e2f06 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -39,10 +39,5 @@ "psr-0": { "Symfony\\Bridge\\Twig": "" } }, "target-dir": "Symfony/Bridge/Twig", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index d45f4d286d..75faafe3a0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -40,10 +40,5 @@ "psr-0": { "Symfony\\Bundle\\FrameworkBundle": "" } }, "target-dir": "Symfony/Bundle/FrameworkBundle", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 68d60fcec4..80e7c8d50d 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -23,10 +23,5 @@ "psr-0": { "Symfony\\Bundle\\SecurityBundle": "" } }, "target-dir": "Symfony/Bundle/SecurityBundle", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bundle/TwigBundle/composer.json b/src/Symfony/Bundle/TwigBundle/composer.json index 530fd774cc..d72ea9b0b7 100644 --- a/src/Symfony/Bundle/TwigBundle/composer.json +++ b/src/Symfony/Bundle/TwigBundle/composer.json @@ -23,10 +23,5 @@ "psr-0": { "Symfony\\Bundle\\TwigBundle": "" } }, "target-dir": "Symfony/Bundle/TwigBundle", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Bundle/WebProfilerBundle/composer.json b/src/Symfony/Bundle/WebProfilerBundle/composer.json index b2eabd3987..8f62eeee54 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/composer.json +++ b/src/Symfony/Bundle/WebProfilerBundle/composer.json @@ -23,10 +23,5 @@ "psr-0": { "Symfony\\Bundle\\WebProfilerBundle": "" } }, "target-dir": "Symfony/Bundle/WebProfilerBundle", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/BrowserKit/composer.json b/src/Symfony/Component/BrowserKit/composer.json index 73ad7b58ec..30ce92fa29 100644 --- a/src/Symfony/Component/BrowserKit/composer.json +++ b/src/Symfony/Component/BrowserKit/composer.json @@ -30,10 +30,5 @@ "psr-0": { "Symfony\\Component\\BrowserKit": "" } }, "target-dir": "Symfony/Component/BrowserKit", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/ClassLoader/composer.json b/src/Symfony/Component/ClassLoader/composer.json index ccd9ba9bc7..b8fa026092 100644 --- a/src/Symfony/Component/ClassLoader/composer.json +++ b/src/Symfony/Component/ClassLoader/composer.json @@ -26,10 +26,5 @@ "psr-0": { "Symfony\\Component\\ClassLoader": "" } }, "target-dir": "Symfony/Component/ClassLoader", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Config/composer.json b/src/Symfony/Component/Config/composer.json index 7d809454ab..f76ca99ff7 100644 --- a/src/Symfony/Component/Config/composer.json +++ b/src/Symfony/Component/Config/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Config": "" } }, "target-dir": "Symfony/Component/Config", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 4488bf6092..415ee7fe71 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Console": "" } }, "target-dir": "Symfony/Component/Console", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/CssSelector/composer.json b/src/Symfony/Component/CssSelector/composer.json index 285fade6f3..b2982ae7c7 100644 --- a/src/Symfony/Component/CssSelector/composer.json +++ b/src/Symfony/Component/CssSelector/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\CssSelector": "" } }, "target-dir": "Symfony/Component/CssSelector", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/DependencyInjection/composer.json b/src/Symfony/Component/DependencyInjection/composer.json index de7ad5dd19..26e7606a6b 100644 --- a/src/Symfony/Component/DependencyInjection/composer.json +++ b/src/Symfony/Component/DependencyInjection/composer.json @@ -30,10 +30,5 @@ "psr-0": { "Symfony\\Component\\DependencyInjection": "" } }, "target-dir": "Symfony/Component/DependencyInjection", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/DomCrawler/composer.json b/src/Symfony/Component/DomCrawler/composer.json index 1cf401ffbd..693be84f79 100644 --- a/src/Symfony/Component/DomCrawler/composer.json +++ b/src/Symfony/Component/DomCrawler/composer.json @@ -28,10 +28,5 @@ "psr-0": { "Symfony\\Component\\DomCrawler": "" } }, "target-dir": "Symfony/Component/DomCrawler", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/EventDispatcher/composer.json b/src/Symfony/Component/EventDispatcher/composer.json index 159a920ab8..2b89a2865f 100644 --- a/src/Symfony/Component/EventDispatcher/composer.json +++ b/src/Symfony/Component/EventDispatcher/composer.json @@ -29,10 +29,5 @@ "psr-0": { "Symfony\\Component\\EventDispatcher": "" } }, "target-dir": "Symfony/Component/EventDispatcher", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Filesystem/composer.json b/src/Symfony/Component/Filesystem/composer.json index 82325ce29c..3ed97f1669 100644 --- a/src/Symfony/Component/Filesystem/composer.json +++ b/src/Symfony/Component/Filesystem/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Filesystem": "" } }, "target-dir": "Symfony/Component/Filesystem", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Finder/composer.json b/src/Symfony/Component/Finder/composer.json index aeac80eaf5..0de630922b 100644 --- a/src/Symfony/Component/Finder/composer.json +++ b/src/Symfony/Component/Finder/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Finder": "" } }, "target-dir": "Symfony/Component/Finder", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index 1cc51ef63b..83f69cda74 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -33,10 +33,5 @@ "psr-0": { "Symfony\\Component\\Form": "" } }, "target-dir": "Symfony/Component/Form", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/HttpFoundation/composer.json b/src/Symfony/Component/HttpFoundation/composer.json index 91c23c2487..e9f54948b6 100644 --- a/src/Symfony/Component/HttpFoundation/composer.json +++ b/src/Symfony/Component/HttpFoundation/composer.json @@ -25,10 +25,5 @@ } }, "target-dir": "Symfony/Component/HttpFoundation", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 9071a373da..f61d92493f 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -42,10 +42,5 @@ "psr-0": { "Symfony\\Component\\HttpKernel": "" } }, "target-dir": "Symfony/Component/HttpKernel", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Locale/composer.json b/src/Symfony/Component/Locale/composer.json index ff051d6561..b6a6e70567 100644 --- a/src/Symfony/Component/Locale/composer.json +++ b/src/Symfony/Component/Locale/composer.json @@ -25,10 +25,5 @@ "psr-0": { "Symfony\\Component\\Locale": "" } }, "target-dir": "Symfony/Component/Locale", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/OptionsResolver/composer.json b/src/Symfony/Component/OptionsResolver/composer.json index 22a39a23e2..a43d9ac041 100644 --- a/src/Symfony/Component/OptionsResolver/composer.json +++ b/src/Symfony/Component/OptionsResolver/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\OptionsResolver": "" } }, "target-dir": "Symfony/Component/OptionsResolver", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Process/composer.json b/src/Symfony/Component/Process/composer.json index a9f85f1af8..a20a4517bd 100644 --- a/src/Symfony/Component/Process/composer.json +++ b/src/Symfony/Component/Process/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Process": "" } }, "target-dir": "Symfony/Component/Process", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Routing/composer.json b/src/Symfony/Component/Routing/composer.json index ae2e764b1e..70f46dac93 100644 --- a/src/Symfony/Component/Routing/composer.json +++ b/src/Symfony/Component/Routing/composer.json @@ -33,10 +33,5 @@ "psr-0": { "Symfony\\Component\\Routing": "" } }, "target-dir": "Symfony/Component/Routing", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Security/composer.json b/src/Symfony/Component/Security/composer.json index 0cf0a30337..3240140c17 100644 --- a/src/Symfony/Component/Security/composer.json +++ b/src/Symfony/Component/Security/composer.json @@ -40,10 +40,5 @@ "psr-0": { "Symfony\\Component\\Security": "" } }, "target-dir": "Symfony/Component/Security", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Serializer/composer.json b/src/Symfony/Component/Serializer/composer.json index 1c8feb3050..68c4623fcf 100644 --- a/src/Symfony/Component/Serializer/composer.json +++ b/src/Symfony/Component/Serializer/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Serializer": "" } }, "target-dir": "Symfony/Component/Serializer", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Templating/composer.json b/src/Symfony/Component/Templating/composer.json index 43b701b824..9b1b46e719 100644 --- a/src/Symfony/Component/Templating/composer.json +++ b/src/Symfony/Component/Templating/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Templating": "" } }, "target-dir": "Symfony/Component/Templating", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Translation/composer.json b/src/Symfony/Component/Translation/composer.json index e65d5c779f..04d2e60f0e 100644 --- a/src/Symfony/Component/Translation/composer.json +++ b/src/Symfony/Component/Translation/composer.json @@ -30,10 +30,5 @@ "psr-0": { "Symfony\\Component\\Translation": "" } }, "target-dir": "Symfony/Component/Translation", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index 7dcb5a7ef8..0f4a3ae94f 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -32,10 +32,5 @@ "psr-0": { "Symfony\\Component\\Validator": "" } }, "target-dir": "Symfony/Component/Validator", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } diff --git a/src/Symfony/Component/Yaml/composer.json b/src/Symfony/Component/Yaml/composer.json index 88460ce34b..dfabb51881 100644 --- a/src/Symfony/Component/Yaml/composer.json +++ b/src/Symfony/Component/Yaml/composer.json @@ -22,10 +22,5 @@ "psr-0": { "Symfony\\Component\\Yaml": "" } }, "target-dir": "Symfony/Component/Yaml", - "minimum-stability": "dev", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - } + "minimum-stability": "dev" } From d902e9d839fdb72abaab40dbe42c7764a99b52fa Mon Sep 17 00:00:00 2001 From: "Mario A. Alvarez Garcia" Date: Thu, 6 Dec 2012 06:52:20 -0500 Subject: [PATCH 038/175] [FrameworkBundle] Added hostnamePattern to the router:debug command --- .../Command/RouterDebugCommand.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 161438674a..18aeaa9af0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -92,9 +92,7 @@ EOF ? implode(', ', $requirements['_method']) : $requirements['_method'] ) : 'ANY'; - $hostname = '' !== $route->getHostnamePattern() - ? $route->getHostnamePattern() : 'ANY'; - + $hostname = '' !== $route->getHostnamePattern() ? $route->getHostnamePattern() : 'ANY'; $maxName = max($maxName, strlen($name)); $maxMethod = max($maxMethod, strlen($method)); $maxHostname = max($maxHostname, strlen($hostname)); @@ -111,8 +109,7 @@ EOF ? implode(', ', $requirements['_method']) : $requirements['_method'] ) : 'ANY'; - $hostname = '' !== $route->getHostnamePattern() - ? $route->getHostnamePattern() : 'ANY'; + $hostname = '' !== $route->getHostnamePattern() ? $route->getHostnamePattern() : 'ANY'; $output->writeln(sprintf($format, $name, $method, $hostname, $route->getPattern())); } } @@ -127,10 +124,13 @@ EOF throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name)); } + $hostname = '' !== $route->getHostnamePattern() ? $route->getHostnamePattern() : 'ANY'; + $output->writeln($this->getHelper('formatter')->formatSection('router', sprintf('Route "%s"', $name))); $output->writeln(sprintf('Name %s', $name)); $output->writeln(sprintf('Pattern %s', $route->getPattern())); + $output->writeln(sprintf('HostnamePattern %s', $hostname)); $output->writeln(sprintf('Class %s', get_class($route))); $defaults = ''; @@ -139,7 +139,7 @@ EOF foreach ($d as $name => $value) { $defaults .= ($defaults ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value); } - $output->writeln(sprintf('Defaults %s', $defaults)); + $output->writeln(sprintf('Defaults %s', $defaults)); $requirements = ''; $r = $route->getRequirements(); @@ -147,7 +147,8 @@ EOF foreach ($r as $name => $value) { $requirements .= ($requirements ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value); } - $output->writeln(sprintf('Requirements %s', $requirements)); + $requirements = '' !== $requirements ? $route->getHostnamePattern() : 'NONE'; + $output->writeln(sprintf('Requirements %s', $requirements)); $options = ''; $o = $route->getOptions(); @@ -155,8 +156,8 @@ EOF foreach ($o as $name => $value) { $options .= ($options ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value); } - $output->writeln(sprintf('Options %s', $options)); - $output->write('Regex '); + $output->writeln(sprintf('Options %s', $options)); + $output->write('Regex '); $output->writeln(preg_replace('/^ /', '', preg_replace('/^/m', ' ', $route->compile()->getRegex())), OutputInterface::OUTPUT_RAW); } From 99321cbe247266fc44da648b69e2c515853c60e6 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 6 Dec 2012 11:23:39 +0100 Subject: [PATCH 039/175] [DoctrineBridge] Fixed: Exception is thrown if the entity class is not known to Doctrine --- .../Bridge/Doctrine/Form/Type/DoctrineType.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index 14d88e3403..5ac205a1d7 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine\Form\Type; use Doctrine\Common\Persistence\ManagerRegistry; +use Symfony\Component\Form\Exception\FormException; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList; @@ -130,7 +131,17 @@ abstract class DoctrineType extends AbstractType return $registry->getManager($em); } - return $registry->getManagerForClass($options['class']); + $em = $registry->getManagerForClass($options['class']); + + if (null === $em) { + throw new FormException(sprintf( + 'Class "%s" seems not to be a managed Doctrine entity. ' . + 'Did you forget to map it?', + $options['class'] + )); + } + + return $em; }; $resolver->setDefaults(array( From db2ee54bdad6103359bfd8a00cde28abe3d3332f Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 6 Dec 2012 11:27:06 +0100 Subject: [PATCH 040/175] [DoctrineBridge] Improved exception message --- .../Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php index 78594ed8ba..2e385a343f 100644 --- a/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php +++ b/src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php @@ -392,7 +392,10 @@ class EntityChoiceList extends ObjectChoiceList private function getIdentifierValues($entity) { if (!$this->em->contains($entity)) { - throw new FormException('Entities passed to the choice field must be managed'); + throw new FormException( + 'Entities passed to the choice field must be managed. Maybe ' . + 'persist them in the entity manager?' + ); } $this->em->initializeObject($entity); From b604eb7b52d3c7ed8828b7fe10f3e172d1451a16 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 6 Dec 2012 13:32:30 +0100 Subject: [PATCH 041/175] [DoctrineBridge] Improved performance of the EntityType when used with the "query_builder" option --- src/Symfony/Bridge/Doctrine/CHANGELOG.md | 5 +++ .../Bridge/Doctrine/Form/Type/EntityType.php | 45 +++++++++++++++---- .../Form/Type/EntityTypePerformanceTest.php | 21 +++++++++ 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/CHANGELOG.md b/src/Symfony/Bridge/Doctrine/CHANGELOG.md index 6369ea3634..8e3f148448 100644 --- a/src/Symfony/Bridge/Doctrine/CHANGELOG.md +++ b/src/Symfony/Bridge/Doctrine/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +2.1.5 +----- + + * fixed caching of choice lists when EntityType is used with the "query_builder" option + 2.1.0 ----- diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php index 51b47be4dc..c9ffb95e9b 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php @@ -11,26 +11,53 @@ namespace Symfony\Bridge\Doctrine\Form\Type; -use Doctrine\Common\Persistence\ObjectManager; +use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; +use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\QueryBuilder; class EntityType extends DoctrineType { + /** + * @var array + */ + private $loaderCache = array(); + /** * Return the default loader object. * - * @param ObjectManager $manager - * @param mixed $queryBuilder - * @param string $class + * @param ObjectManager $manager + * @param QueryBuilder|\Closure $queryBuilder + * @param string $class + * * @return ORMQueryBuilderLoader + * + * @throws UnexpectedTypeException If the passed $queryBuilder is no \Closure + * and no QueryBuilder or if the closure + * does not return a QueryBuilder. */ public function getLoader(ObjectManager $manager, $queryBuilder, $class) { - return new ORMQueryBuilderLoader( - $queryBuilder, - $manager, - $class - ); + if ($queryBuilder instanceof \Closure) { + $queryBuilder = $queryBuilder($manager->getRepository($class)); + + if (!$queryBuilder instanceof QueryBuilder) { + throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder'); + } + } elseif (!$queryBuilder instanceof QueryBuilder) { + throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder or \Closure'); + } + + // It is important to return the same loader for identical queries, + // otherwise the caching mechanism in DoctrineType does not work + // (which expects identical loaders for the cache to work) + $hash = md5($queryBuilder->getQuery()->getDQL()); + + if (!isset($this->loaderCache[$hash])) { + $this->loaderCache[$hash] = new ORMQueryBuilderLoader($queryBuilder); + } + + return $this->loaderCache[$hash]; } public function getName() diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php index ea068c24f3..e73dd11be0 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Form\Type; use Symfony\Component\Form\Tests\FormPerformanceTestCase; +use Doctrine\ORM\EntityRepository; use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIdentEntity; use Doctrine\ORM\Tools\SchemaTool; use Symfony\Bridge\Doctrine\Tests\DoctrineOrmTestCase; @@ -36,6 +37,9 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase $manager->expects($this->any()) ->method('getManager') ->will($this->returnValue($this->em)); + $manager->expects($this->any()) + ->method('getManagerForClass') + ->will($this->returnValue($this->em)); return array( new CoreExtension(), @@ -109,4 +113,21 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase $form->createView(); } } + + public function testCollapsedEntityFieldWithQueryBuilder() + { + $this->setMaxRunningTime(1); + + for ($i = 0; $i < 20; ++$i) { + $form = $this->factory->create('entity', null, array( + 'class' => self::ENTITY_CLASS, + 'query_builder' => function (EntityRepository $repo) { + return $repo->createQueryBuilder('e')->addOrderBy('e.id', 'DESC'); + } + )); + + // force loading of the choice list + $form->createView(); + } + } } From d0057d0e643da62fd05eed01d319ba2df72bcc84 Mon Sep 17 00:00:00 2001 From: Leevi Graham Date: Mon, 29 Oct 2012 18:23:42 +1100 Subject: [PATCH 042/175] Added failure_path_parameter to mirror target_path_parameter --- .../Security/Factory/AbstractFactory.php | 1 + .../Tests/Functional/app/CsrfFormLogin/config.yml | 1 + .../DefaultAuthenticationFailureHandler.php | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php index 20f62c6f18..6d3e191131 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php @@ -43,6 +43,7 @@ abstract class AbstractFactory implements SecurityFactoryInterface 'failure_path' => null, 'failure_forward' => false, 'login_path' => '/login', + 'failure_path_parameter' => '_failure_path', ); public function create(ContainerBuilder $container, $id, $config, $userProviderId, $defaultEntryPointId) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml index 1f1fa85d0a..e0347e1dc4 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/CsrfFormLogin/config.yml @@ -33,6 +33,7 @@ security: check_path: /login_check default_target_path: /profile target_path_parameter: "user_login[_target_path]" + failure_path_parameter: "user_login[_failure_path]" username_parameter: "user_login[username]" password_parameter: "user_login[password]" csrf_parameter: "user_login[_token]" diff --git a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationFailureHandler.php b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationFailureHandler.php index 61d77a8ba8..d54374557b 100644 --- a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationFailureHandler.php +++ b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationFailureHandler.php @@ -50,9 +50,10 @@ class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandle $this->logger = $logger; $this->options = array_merge(array( - 'failure_path' => null, - 'failure_forward' => false, - 'login_path' => '/login', + 'failure_path' => null, + 'failure_forward' => false, + 'login_path' => '/login', + 'failure_path_parameter' => '_failure_path' ), $options); } @@ -61,6 +62,10 @@ class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandle */ public function onAuthenticationFailure(Request $request, AuthenticationException $exception) { + if ($failureUrl = $request->get($this->options['failure_path_parameter'], null, true)) { + $this->options['failure_path'] = $failureUrl; + } + if (null === $this->options['failure_path']) { $this->options['failure_path'] = $this->options['login_path']; } From 63b00598fe108fe7928c6f4db48e9909d13ba68f Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 28 Oct 2012 16:19:50 +0100 Subject: [PATCH 043/175] [Process] Add ability to reset arguments on ProcessBuilder --- src/Symfony/Component/Process/CHANGELOG.md | 1 + src/Symfony/Component/Process/ProcessBuilder.php | 12 ++++++++++++ .../Component/Process/Tests/ProcessBuilderTest.php | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/Symfony/Component/Process/CHANGELOG.md b/src/Symfony/Component/Process/CHANGELOG.md index f0752ec8e8..7fa5b72d50 100644 --- a/src/Symfony/Component/Process/CHANGELOG.md +++ b/src/Symfony/Component/Process/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 2.2.0 ----- + * added ProcessBuilder::setArguments() to reset the arguments on a builder * added a way to retrieve the standard and error output incrementally * added Process:restart() diff --git a/src/Symfony/Component/Process/ProcessBuilder.php b/src/Symfony/Component/Process/ProcessBuilder.php index 2a88ea00d4..ce3a041f16 100644 --- a/src/Symfony/Component/Process/ProcessBuilder.php +++ b/src/Symfony/Component/Process/ProcessBuilder.php @@ -56,6 +56,18 @@ class ProcessBuilder return $this; } + /** + * @param array $arguments + * + * @return ProcessBuilder + */ + public function setArguments(array $arguments) + { + $this->arguments = $arguments; + + return $this; + } + public function setWorkingDirectory($cwd) { $this->cwd = $cwd; diff --git a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php index 4f6157e46e..469208c99f 100644 --- a/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessBuilderTest.php @@ -105,4 +105,14 @@ class ProcessBuilderTest extends \PHPUnit_Framework_TestCase $this->assertNull($p->getValue($pb)); } + + public function testShouldSetArguments() + { + $pb = new ProcessBuilder(array('initial')); + $pb->setArguments(array('second')); + + $proc = $pb->getProcess(); + + $this->assertContains("second", $proc->getCommandLine()); + } } From cf630690bea92cf79a22dda32b899ee96731daaa Mon Sep 17 00:00:00 2001 From: "Mario A. Alvarez Garcia" Date: Thu, 6 Dec 2012 08:14:56 -0500 Subject: [PATCH 044/175] Fixed copy/paste mistake --- .../Bundle/FrameworkBundle/Command/RouterDebugCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 18aeaa9af0..fa3e681b89 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -147,7 +147,7 @@ EOF foreach ($r as $name => $value) { $requirements .= ($requirements ? "\n".str_repeat(' ', 13) : '').$name.': '.$this->formatValue($value); } - $requirements = '' !== $requirements ? $route->getHostnamePattern() : 'NONE'; + $requirements = '' !== $requirements ? $requirements : 'NONE'; $output->writeln(sprintf('Requirements %s', $requirements)); $options = ''; From 57e9d28795e683f6242bfe574eb767a4ac10eb6f Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 6 Dec 2012 13:09:44 +0100 Subject: [PATCH 045/175] [DI] Add a base class for extension --- .../DependencyInjection/CHANGELOG.md | 6 + .../Extension/Extension.php | 107 ++++++++++++++++++ .../DependencyInjection/Extension.php | 93 +-------------- 3 files changed, 116 insertions(+), 90 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Extension/Extension.php diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 8f5d6b32c8..7a17f93f46 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +2.2.0 +----- + + * added an Extension base class with sensible defaults to be used in conjunction + with the Config component. + 2.1.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Extension/Extension.php b/src/Symfony/Component/DependencyInjection/Extension/Extension.php new file mode 100644 index 0000000000..e5c51a7b58 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Extension/Extension.php @@ -0,0 +1,107 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Extension; + +use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Config\Definition\ConfigurationInterface; + +/** + * Provides useful features shared by many extensions. + * + * @author Fabien Potencier + */ +abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface +{ + /** + * Returns the base path for the XSD files. + * + * @return string The XSD base path + */ + public function getXsdValidationBasePath() + { + return false; + } + + /** + * Returns the namespace to be used for this extension (XML namespace). + * + * @return string The XML namespace + */ + public function getNamespace() + { + return 'http://example.org/schema/dic/'.$this->getAlias(); + } + + /** + * Returns the recommended alias to use in XML. + * + * This alias is also the mandatory prefix to use when using YAML. + * + * This convention is to remove the "Extension" postfix from the class + * name and then lowercase and underscore the result. So: + * + * AcmeHelloExtension + * + * becomes + * + * acme_hello + * + * This can be overridden in a sub-class to specify the alias manually. + * + * @return string The alias + * + * @throws \BadMethodCallException When the extension name does not follow conventions + */ + public function getAlias() + { + $className = get_class($this); + if (substr($className, -9) != 'Extension') { + throw new \BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.'); + } + $classBaseName = substr(strrchr($className, '\\'), 1, -9); + + return Container::underscore($classBaseName); + } + + final protected function processConfiguration(ConfigurationInterface $configuration, array $configs) + { + $processor = new Processor(); + + return $processor->processConfiguration($configuration, $configs); + } + + /** + * {@inheritDoc} + */ + public function getConfiguration(array $config, ContainerBuilder $container) + { + $reflected = new \ReflectionClass($this); + $namespace = $reflected->getNamespaceName(); + + $class = $namespace . '\\Configuration'; + if (class_exists($class)) { + $r = new \ReflectionClass($class); + $container->addResource(new FileResource($r->getFileName())); + + if (!method_exists($class, '__construct')) { + $configuration = new $class(); + + return $configuration; + } + } + + return null; + } +} diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php index e03ed88b50..2ca0f13284 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php @@ -11,20 +11,14 @@ namespace Symfony\Component\HttpKernel\DependencyInjection; -use Symfony\Component\Config\Definition\Processor; -use Symfony\Component\Config\Resource\FileResource; -use Symfony\Component\Config\Definition\ConfigurationInterface; -use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; -use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\Extension\Extension as BaseExtension; /** - * Provides useful features shared by many extensions. + * Allow adding classes to the class cache. * * @author Fabien Potencier */ -abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface +abstract class Extension extends BaseExtension { private $classes = array(); @@ -47,85 +41,4 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn { $this->classes = array_merge($this->classes, $classes); } - - /** - * Returns the base path for the XSD files. - * - * @return string The XSD base path - */ - public function getXsdValidationBasePath() - { - return false; - } - - /** - * Returns the namespace to be used for this extension (XML namespace). - * - * @return string The XML namespace - */ - public function getNamespace() - { - return 'http://example.org/schema/dic/'.$this->getAlias(); - } - - /** - * Returns the recommended alias to use in XML. - * - * This alias is also the mandatory prefix to use when using YAML. - * - * This convention is to remove the "Extension" postfix from the class - * name and then lowercase and underscore the result. So: - * - * AcmeHelloExtension - * - * becomes - * - * acme_hello - * - * This can be overridden in a sub-class to specify the alias manually. - * - * @return string The alias - * - * @throws \BadMethodCallException When the extension name does not follow conventions - */ - public function getAlias() - { - $className = get_class($this); - if (substr($className, -9) != 'Extension') { - throw new \BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.'); - } - $classBaseName = substr(strrchr($className, '\\'), 1, -9); - - return Container::underscore($classBaseName); - } - - final protected function processConfiguration(ConfigurationInterface $configuration, array $configs, $normalizeKeys = true) - { - $processor = new Processor(); - - return $processor->processConfiguration($configuration, $configs, $normalizeKeys); - } - - /** - * {@inheritDoc} - */ - public function getConfiguration(array $config, ContainerBuilder $container) - { - $reflected = new \ReflectionClass($this); - $namespace = $reflected->getNamespaceName(); - - $class = $namespace . '\\Configuration'; - if (class_exists($class)) { - $r = new \ReflectionClass($class); - $container->addResource(new FileResource($r->getFileName())); - - if (!method_exists($class, '__construct')) { - $configuration = new $class(); - - return $configuration; - } - } - - return null; - } } From 577ee800039e4327d229cc96b72d088f7dc47b06 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 13 Nov 2012 17:48:13 +0100 Subject: [PATCH 046/175] [HttpFoundation] Move IP check methods to a HttpUtils class for reuse --- .../Component/HttpFoundation/CHANGELOG.md | 1 + .../Component/HttpFoundation/IpUtils.php | 111 ++++++++++++++++++ .../HttpFoundation/RequestMatcher.php | 87 +------------- .../HttpFoundation/Tests/IpUtilsTest.php | 71 +++++++++++ .../Tests/RequestMatcherTest.php | 73 ------------ 5 files changed, 184 insertions(+), 159 deletions(-) create mode 100644 src/Symfony/Component/HttpFoundation/IpUtils.php create mode 100644 src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php diff --git a/src/Symfony/Component/HttpFoundation/CHANGELOG.md b/src/Symfony/Component/HttpFoundation/CHANGELOG.md index 4b7d0c64ac..13ed8dd7c9 100644 --- a/src/Symfony/Component/HttpFoundation/CHANGELOG.md +++ b/src/Symfony/Component/HttpFoundation/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 2.2.0 ----- + * added a IpUtils class to check if an IP belongs to a CIDR * added Request::getRealMethod() to get the "real" HTTP method (getMethod() returns the "intended" HTTP method) * disabled _method request parameter support by default (call Request::enableHttpMethodParameterOverride() to enable it) * Request::splitHttpAcceptHeader() method is deprecated and will be removed in 2.3 diff --git a/src/Symfony/Component/HttpFoundation/IpUtils.php b/src/Symfony/Component/HttpFoundation/IpUtils.php new file mode 100644 index 0000000000..2e3e1aa746 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/IpUtils.php @@ -0,0 +1,111 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation; + +/** + * Http utility functions. + * + * @author Fabien Potencier + */ +class IpUtils +{ + /** + * This class should not be instantiated + */ + private function __construct() {} + + /** + * Validates an IPv4 or IPv6 address. + * + * @param string $requestIp + * @param string $ip + * + * @return boolean Whether the IP is valid + */ + public static function checkIp($requestIp, $ip) + { + if (false !== strpos($requestIp, ':')) { + return self::checkIp6($requestIp, $ip); + } + + return self::checkIp4($requestIp, $ip); + } + + /** + * Validates an IPv4 address. + * + * @param string $requestIp + * @param string $ip + * + * @return boolean Whether the IP is valid + */ + public static function checkIp4($requestIp, $ip) + { + if (false !== strpos($ip, '/')) { + list($address, $netmask) = explode('/', $ip, 2); + + if ($netmask < 1 || $netmask > 32) { + return false; + } + } else { + $address = $ip; + $netmask = 32; + } + + return 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask); + } + + /** + * Validates an IPv6 address. + * + * @author David Soria Parra + * @see https://github.com/dsp/v6tools + * + * @param string $requestIp + * @param string $ip + * + * @return boolean Whether the IP is valid + * + * @throws \RuntimeException When IPV6 support is not enabled + */ + public static function checkIp6($requestIp, $ip) + { + if (!((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'))) { + throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".'); + } + + if (false !== strpos($ip, '/')) { + list($address, $netmask) = explode('/', $ip, 2); + + if ($netmask < 1 || $netmask > 128) { + return false; + } + } else { + $address = $ip; + $netmask = 128; + } + + $bytesAddr = unpack("n*", inet_pton($address)); + $bytesTest = unpack("n*", inet_pton($requestIp)); + + for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) { + $left = $netmask - 16 * ($i-1); + $left = ($left <= 16) ? $left : 16; + $mask = ~(0xffff >> $left) & 0xffff; + if (($bytesAddr[$i] & $mask) != ($bytesTest[$i] & $mask)) { + return false; + } + } + + return true; + } +} diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index 7371d17242..536cc7b075 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/RequestMatcher.php @@ -143,96 +143,11 @@ class RequestMatcher implements RequestMatcherInterface return false; } - if (null !== $this->ip && !$this->checkIp($request->getClientIp(), $this->ip)) { + if (null !== $this->ip && !IpUtils::checkIp($request->getClientIp(), $this->ip)) { return false; } return true; } - - /** - * Validates an IP address. - * - * @param string $requestIp - * @param string $ip - * - * @return boolean True valid, false if not. - */ - protected function checkIp($requestIp, $ip) - { - // IPv6 address - if (false !== strpos($requestIp, ':')) { - return $this->checkIp6($requestIp, $ip); - } else { - return $this->checkIp4($requestIp, $ip); - } - } - - /** - * Validates an IPv4 address. - * - * @param string $requestIp - * @param string $ip - * - * @return boolean True valid, false if not. - */ - protected function checkIp4($requestIp, $ip) - { - if (false !== strpos($ip, '/')) { - list($address, $netmask) = explode('/', $ip, 2); - - if ($netmask < 1 || $netmask > 32) { - return false; - } - } else { - $address = $ip; - $netmask = 32; - } - - return 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask); - } - - /** - * Validates an IPv6 address. - * - * @author David Soria Parra - * @see https://github.com/dsp/v6tools - * - * @param string $requestIp - * @param string $ip - * - * @return boolean True valid, false if not. - */ - protected function checkIp6($requestIp, $ip) - { - if (!((extension_loaded('sockets') && defined('AF_INET6')) || @inet_pton('::1'))) { - throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".'); - } - - if (false !== strpos($ip, '/')) { - list($address, $netmask) = explode('/', $ip, 2); - - if ($netmask < 1 || $netmask > 128) { - return false; - } - } else { - $address = $ip; - $netmask = 128; - } - - $bytesAddr = unpack("n*", inet_pton($address)); - $bytesTest = unpack("n*", inet_pton($requestIp)); - - for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) { - $left = $netmask - 16 * ($i-1); - $left = ($left <= 16) ? $left : 16; - $mask = ~(0xffff >> $left) & 0xffff; - if (($bytesAddr[$i] & $mask) != ($bytesTest[$i] & $mask)) { - return false; - } - } - - return true; - } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php new file mode 100644 index 0000000000..5b94bd2bd0 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php @@ -0,0 +1,71 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\Tests; + +use Symfony\Component\HttpFoundation\IpUtils; + +class IpUtilsTest extends \PHPUnit_Framework_TestCase +{ + /** + * @dataProvider testIpv4Provider + */ + public function testIpv4($matches, $remoteAddr, $cidr) + { + $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); + } + + public function testIpv4Provider() + { + return array( + array(true, '192.168.1.1', '192.168.1.1'), + array(true, '192.168.1.1', '192.168.1.1/1'), + array(true, '192.168.1.1', '192.168.1.0/24'), + array(false, '192.168.1.1', '1.2.3.4/1'), + array(false, '192.168.1.1', '192.168.1/33'), + ); + } + + /** + * @dataProvider testIpv6Provider + */ + public function testIpv6($matches, $remoteAddr, $cidr) + { + if (!defined('AF_INET6')) { + $this->markTestSkipped('Only works when PHP is compiled without the option "disable-ipv6".'); + } + + $this->assertSame($matches, IpUtils::checkIp($remoteAddr, $cidr)); + } + + public function testIpv6Provider() + { + return array( + array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), + array(false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), + array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'), + array(true, '0:0:0:0:0:0:0:1', '::1'), + array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'), + ); + } + + /** + * @expectedException \RuntimeException + */ + public function testAnIpv6WithOptionDisabledIpv6() + { + if (defined('AF_INET6')) { + $this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".'); + } + + IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'); + } +} diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php index 0e7b9eff66..0e1a0f5caf 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestMatcherTest.php @@ -16,78 +16,6 @@ use Symfony\Component\HttpFoundation\Request; class RequestMatcherTest extends \PHPUnit_Framework_TestCase { - /** - * @dataProvider testIpv4Provider - */ - public function testIpv4($matches, $remoteAddr, $cidr) - { - $request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => $remoteAddr)); - - $matcher = new RequestMatcher(); - $matcher->matchIp($cidr); - - $this->assertEquals($matches, $matcher->matches($request)); - } - - public function testIpv4Provider() - { - return array( - array(true, '192.168.1.1', '192.168.1.1'), - array(true, '192.168.1.1', '192.168.1.1/1'), - array(true, '192.168.1.1', '192.168.1.0/24'), - array(false, '192.168.1.1', '1.2.3.4/1'), - array(false, '192.168.1.1', '192.168.1/33'), - ); - } - - /** - * @dataProvider testIpv6Provider - */ - public function testIpv6($matches, $remoteAddr, $cidr) - { - if (!defined('AF_INET6')) { - $this->markTestSkipped('Only works when PHP is compiled without the option "disable-ipv6".'); - } - - $request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => $remoteAddr)); - - $matcher = new RequestMatcher(); - $matcher->matchIp($cidr); - - $this->assertEquals($matches, $matcher->matches($request)); - } - - public function testIpv6Provider() - { - return array( - array(true, '2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), - array(false, '2a00:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65'), - array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'), - array(true, '0:0:0:0:0:0:0:1', '::1'), - array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'), - ); - } - - public function testAnIpv6WithOptionDisabledIpv6() - { - if (defined('AF_INET6')) { - $this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".'); - } - - $request = Request::create('', 'get', array(), array(), array(), array('REMOTE_ADDR' => '2a01:198:603:0:396e:4789:8e99:890f')); - - $matcher = new RequestMatcher(); - $matcher->matchIp('2a01:198:603:0::/65'); - - try { - $matcher->matches($request); - - $this->fail('An expected RuntimeException has not been raised.'); - } catch (\Exception $e) { - $this->assertInstanceOf('\RuntimeException', $e); - } - } - /** * @dataProvider testMethodFixtures */ @@ -200,4 +128,3 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase $this->assertFalse($matcher->matches($request)); } } - From 459a09fbdfa9eb9d839df74942d2f6ec3a07dd69 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 7 Dec 2012 10:03:28 +0100 Subject: [PATCH 047/175] [WebProfilerBundle] "View all" is "View last 10" --- .../WebProfilerBundle/Resources/views/Profiler/layout.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig index c189ee9d01..0fa73359ec 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig @@ -13,7 +13,7 @@
{% if profile %}
- View all + View last 10 Profile for: {{ profile.method|upper }} {% if profile.method|upper in ['GET', 'HEAD'] %} From 048979993e94f74946fc7ed6b7ac612db2c0a01e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 6 Dec 2012 13:50:59 +0100 Subject: [PATCH 048/175] [HttpFoundation] added a check for the host header value --- .../Component/HttpFoundation/Request.php | 24 ++++++++++++------- .../Component/HttpFoundation/RequestTest.php | 14 ++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 03c7e03a5f..f9c9673b8c 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -696,6 +696,8 @@ class Request * * @return string * + * @throws \UnexpectedValueException when the host name is invalid + * * @api */ public function getHost() @@ -703,19 +705,23 @@ class Request if (self::$trustProxy && $host = $this->headers->get('X_FORWARDED_HOST')) { $elements = explode(',', $host); - $host = trim($elements[count($elements) - 1]); - } else { - if (!$host = $this->headers->get('HOST')) { - if (!$host = $this->server->get('SERVER_NAME')) { - $host = $this->server->get('SERVER_ADDR', ''); - } + $host = $elements[count($elements) - 1]; + } elseif (!$host = $this->headers->get('HOST')) { + if (!$host = $this->server->get('SERVER_NAME')) { + $host = $this->server->get('SERVER_ADDR', ''); } } - // Remove port number from host - $host = preg_replace('/:\d+$/', '', $host); + // Trim and remove port number from host + $host = trim(preg_replace('/:\d+$/', '', $host)); - return trim($host); + // as the host can come from the user (HTTP_HOST and depending on the configuration, SERVER_NAME too can come from the user) + // check that it does not contain forbidden characters (see RFC 952 and RFC 2181) + if ($host && !preg_match('/^\[?(?:[a-zA-Z0-9-:\]_]+\.?)+$/', $host)) { + throw new \UnexpectedValueException('Invalid Host'); + } + + return $host; } /** diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php index 43e083aadd..d006a4a811 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php @@ -417,9 +417,6 @@ class RequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals('foo=1&foo=2', $request->getQueryString(), '->getQueryString() allows repeated parameters'); } - /** - * @covers Symfony\Component\HttpFoundation\Request::getHost - */ public function testGetHost() { $request = new Request(); @@ -458,6 +455,17 @@ class RequestTest extends \PHPUnit_Framework_TestCase $request->initialize(array(), array(), array(), array(), array(), array('SERVER_NAME' => 'www.exemple.com', 'HTTP_HOST' => 'www.host.com')); $this->assertEquals('www.host.com', $request->getHost(), '->getHost() value from Host header has priority over SERVER_NAME '); + + } + + /** + * @expectedException RuntimeException + */ + public function testGetHostWithFakeHttpHostValue() + { + $request = new Request(); + $request->initialize(array(), array(), array(), array(), array(), array('HTTP_HOST' => 'www.host.com?query=string')); + $request->getHost(); } /** From 447ff915df4dc896bb5e2f7dc069c9516ffe92d6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 7 Dec 2012 10:25:02 +0100 Subject: [PATCH 049/175] [HttpFoundation] changed UploadedFile::move() to use move_uploaded_file() when possible (closes #5878, closes #6185) --- .../Component/HttpFoundation/File/File.php | 23 ++++++++++++------- .../HttpFoundation/File/UploadedFile.php | 17 ++++++++++++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index 43b8c0d265..de4fb9d17b 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -523,6 +523,20 @@ class File extends \SplFileInfo * @api */ public function move($directory, $name = null) + { + $target = $this->getTargetFile($directory, $name); + + if (!@rename($this->getPathname(), $target)) { + $error = error_get_last(); + throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message']))); + } + + @chmod($target, 0666 & ~umask()); + + return $target; + } + + protected function getTargetFile($directory, $name = null) { if (!is_dir($directory)) { if (false === @mkdir($directory, 0777, true)) { @@ -534,14 +548,7 @@ class File extends \SplFileInfo $target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name)); - if (!@rename($this->getPathname(), $target)) { - $error = error_get_last(); - throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message']))); - } - - chmod($target, 0666); - - return new File($target); + return new File($target, false); } /** diff --git a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php index 7b337da9ff..0830a8a06c 100644 --- a/src/Symfony/Component/HttpFoundation/File/UploadedFile.php +++ b/src/Symfony/Component/HttpFoundation/File/UploadedFile.php @@ -189,8 +189,21 @@ class UploadedFile extends File */ public function move($directory, $name = null) { - if ($this->isValid() && ($this->test || is_uploaded_file($this->getPathname()))) { - return parent::move($directory, $name); + if ($this->isValid()) { + if ($this->test) { + return parent::move($directory, $name); + } elseif (is_uploaded_file($this->getPathname())) { + $target = $this->getTargetFile($directory, $name); + + if (!@move_uploaded_file($this->getPathname(), $target)) { + $error = error_get_last(); + throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags($error['message']))); + } + + @chmod($target, 0666 & ~umask()); + + return $target; + } } throw new FileException(sprintf('The file "%s" has not been uploaded via Http', $this->getPathname())); From aad8136cd1bd90312f4c41affd473c25c6a56932 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 7 Dec 2012 10:39:50 +0100 Subject: [PATCH 050/175] [HttpFoundation] fixed a small regression --- src/Symfony/Component/HttpFoundation/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 01284cf724..546d0ffbd9 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -813,7 +813,7 @@ class Request } // Trim and remove port number from host - $host = trim(preg_replace('/:\d+$/', '', $host)); + $host = preg_replace('/:\d+$/', '', trim($host)); // as the host can come from the user (HTTP_HOST and depending on the configuration, SERVER_NAME too can come from the user) // check that it does not contain forbidden characters (see RFC 952 and RFC 2181) From d7a1154154baa9eed6b7dead55e453bfb47f677a Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Thu, 20 Sep 2012 23:20:53 +0200 Subject: [PATCH 051/175] make it possible for bundles extensions to prepend settings into the application configuration of any Bundle --- .../DependencyInjection/CHANGELOG.md | 6 +++++ .../MergeExtensionConfigurationPass.php | 6 +++++ .../Compiler/PrependExtensionInterface.php | 24 +++++++++++++++++++ .../DependencyInjection/ContainerBuilder.php | 15 ++++++++++++ .../Tests/ContainerBuilderTest.php | 22 +++++++++++++++++ src/Symfony/Component/HttpKernel/.gitignore | 3 ++- 6 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/DependencyInjection/Compiler/PrependExtensionInterface.php diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 8f5d6b32c8..b159ddba20 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +2.2.0 +----- + + * added PrependExtensionInterface (to be able to allow extensions to prepend + application configuration settings for any Bundle) + 2.1.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php b/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php index a9beb5b9e2..d2c98314e2 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/MergeExtensionConfigurationPass.php @@ -29,6 +29,12 @@ class MergeExtensionConfigurationPass implements CompilerPassInterface $definitions = $container->getDefinitions(); $aliases = $container->getAliases(); + foreach ($container->getExtensions() as $extension) { + if ($extension instanceof PrependExtensionInterface) { + $extension->prepend($container); + } + } + foreach ($container->getExtensions() as $name => $extension) { if (!$config = $container->getExtensionConfig($name)) { // this extension was not called diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PrependExtensionInterface.php b/src/Symfony/Component/DependencyInjection/Compiler/PrependExtensionInterface.php new file mode 100644 index 0000000000..bba1b6cd46 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Compiler/PrependExtensionInterface.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\ContainerBuilder; + +interface PrependExtensionInterface +{ + /** + * Allow an extension to prepend the extension configurations. + * + * @param ContainerBuilder $container + */ + public function prepend(ContainerBuilder $container); +} diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 30514cc55d..44200ac061 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -465,6 +465,21 @@ class ContainerBuilder extends Container implements TaggedContainerInterface return $this->extensionConfigs[$name]; } + /** + * Prepends a config array to the configs of the given extension. + * + * @param string $name The name of the extension + * @param array $config The config to set + */ + public function prependExtensionConfig($name, array $config) + { + if (!isset($this->extensionConfigs[$name])) { + $this->extensionConfigs[$name] = array(); + } + + array_unshift($this->extensionConfigs[$name], $config); + } + /** * Compiles the container. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index c9e6b07847..66658efdeb 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -548,6 +548,28 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase $container->compile(); $container->setDefinition('a', new Definition()); } + + /** + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::getExtensionConfig + * @covers Symfony\Component\DependencyInjection\ContainerBuilder::prependExtensionConfig + */ + public function testExtensionConfig() + { + $container = new ContainerBuilder(); + + $configs = $container->getExtensionConfig('foo'); + $this->assertEmpty($configs); + + $first = array('foo' => 'bar'); + $container->prependExtensionConfig('foo', $first); + $configs = $container->getExtensionConfig('foo'); + $this->assertEquals(array($first), $configs); + + $second = array('ding' => 'dong'); + $container->prependExtensionConfig('foo', $second); + $configs = $container->getExtensionConfig('foo'); + $this->assertEquals(array($second, $first), $configs); + } } class FooClass {} diff --git a/src/Symfony/Component/HttpKernel/.gitignore b/src/Symfony/Component/HttpKernel/.gitignore index 44de97a36a..38c15605ed 100644 --- a/src/Symfony/Component/HttpKernel/.gitignore +++ b/src/Symfony/Component/HttpKernel/.gitignore @@ -1,4 +1,5 @@ vendor/ composer.lock phpunit.xml - +Tests/ProjectContainer.php +Tests/classes.map \ No newline at end of file From e4586007dc6d16adea62f1d475ffc00c906fd7cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Fri, 7 Dec 2012 11:34:49 +0100 Subject: [PATCH 052/175] [DependencyInjection] Add deleted argument in Extension::processConfiguration --- .../Component/DependencyInjection/Extension/Extension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Extension/Extension.php b/src/Symfony/Component/DependencyInjection/Extension/Extension.php index e5c51a7b58..b821ea68db 100644 --- a/src/Symfony/Component/DependencyInjection/Extension/Extension.php +++ b/src/Symfony/Component/DependencyInjection/Extension/Extension.php @@ -75,11 +75,11 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn return Container::underscore($classBaseName); } - final protected function processConfiguration(ConfigurationInterface $configuration, array $configs) + final protected function processConfiguration(ConfigurationInterface $configuration, array $configs, $normalizeKeys = true) { $processor = new Processor(); - return $processor->processConfiguration($configuration, $configs); + return $processor->processConfiguration($configuration, $configs, $normalizeKeys); } /** From 6e7e08f8c41faf3ffb3945a1d6a8e264cac4436f Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 6 Dec 2012 19:50:36 +0100 Subject: [PATCH 053/175] [Form] Fixed the default value of "format" in DateType to DateType::DEFAULT_FORMAT if "widget" is not "single_text" --- .../Form/Extension/Core/Type/DateType.php | 6 +- .../Form/Tests/AbstractLayoutTest.php | 64 +++++++++---------- .../Extension/Core/Type/DateTypeTest.php | 6 +- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 52a681f269..010d19da14 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -180,6 +180,10 @@ class DateType extends AbstractType ); }; + $format = function (Options $options) { + return $options['widget'] === 'single_text' ? self::HTML5_FORMAT : self::DEFAULT_FORMAT; + }; + // BC until Symfony 2.3 $modelTimezone = function (Options $options) { return $options['data_timezone']; @@ -196,7 +200,7 @@ class DateType extends AbstractType 'days' => range(1, 31), 'widget' => 'choice', 'input' => 'datetime', - 'format' => self::HTML5_FORMAT, + 'format' => $format, 'model_timezone' => $modelTimezone, 'view_timezone' => $viewTimezone, // Deprecated timezone options diff --git a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php index 527d73a7f5..1f296a81df 100644 --- a/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractLayoutTest.php @@ -809,14 +809,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase [@id="name_date"] [ ./select - [@id="name_date_year"] - [./option[@value="2011"][@selected="selected"]] - /following-sibling::select [@id="name_date_month"] [./option[@value="2"][@selected="selected"]] /following-sibling::select [@id="name_date_day"] [./option[@value="3"][@selected="selected"]] + /following-sibling::select + [@id="name_date_year"] + [./option[@value="2011"][@selected="selected"]] ] /following-sibling::div [@id="name_time"] @@ -849,14 +849,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase [@id="name_date"] [ ./select - [@id="name_date_year"] - [./option[@value=""][.="[trans]Change&Me[/trans]"]] - /following-sibling::select [@id="name_date_month"] [./option[@value=""][.="[trans]Change&Me[/trans]"]] /following-sibling::select [@id="name_date_day"] [./option[@value=""][.="[trans]Change&Me[/trans]"]] + /following-sibling::select + [@id="name_date_year"] + [./option[@value=""][.="[trans]Change&Me[/trans]"]] ] /following-sibling::div [@id="name_time"] @@ -889,14 +889,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase [@id="name_date"] [ ./select - [@id="name_date_year"] - [./option[@value="2011"][@selected="selected"]] - /following-sibling::select [@id="name_date_month"] [./option[@value="2"][@selected="selected"]] /following-sibling::select [@id="name_date_day"] [./option[@value="3"][@selected="selected"]] + /following-sibling::select + [@id="name_date_year"] + [./option[@value="2011"][@selected="selected"]] ] /following-sibling::div [@id="name_time"] @@ -928,14 +928,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase [@id="name_date"] [ ./select - [@id="name_date_year"] - [./option[@value="2011"][@selected="selected"]] - /following-sibling::select [@id="name_date_month"] [./option[@value="2"][@selected="selected"]] /following-sibling::select [@id="name_date_day"] [./option[@value="3"][@selected="selected"]] + /following-sibling::select + [@id="name_date_year"] + [./option[@value="2011"][@selected="selected"]] ] /following-sibling::div [@id="name_time"] @@ -1031,14 +1031,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase '/div [ ./select - [@id="name_year"] - [./option[@value="2011"][@selected="selected"]] - /following-sibling::select [@id="name_month"] [./option[@value="2"][@selected="selected"]] /following-sibling::select [@id="name_day"] [./option[@value="3"][@selected="selected"]] + /following-sibling::select + [@id="name_year"] + [./option[@value="2011"][@selected="selected"]] ] [count(./select)=3] ' @@ -1058,14 +1058,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase '/div [ ./select - [@id="name_year"] - [./option[@value=""][.="[trans]Change&Me[/trans]"]] - /following-sibling::select [@id="name_month"] [./option[@value=""][.="[trans]Change&Me[/trans]"]] /following-sibling::select [@id="name_day"] [./option[@value=""][.="[trans]Change&Me[/trans]"]] + /following-sibling::select + [@id="name_year"] + [./option[@value=""][.="[trans]Change&Me[/trans]"]] ] [count(./select)=3] ' @@ -1085,14 +1085,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase '/div [ ./select - [@id="name_year"] - [./option[@value=""][.="[trans]Change&Me[/trans]"]] - /following-sibling::select [@id="name_month"] [./option[@value="1"]] /following-sibling::select [@id="name_day"] [./option[@value="1"]] + /following-sibling::select + [@id="name_year"] + [./option[@value=""][.="[trans]Change&Me[/trans]"]] ] [count(./select)=3] ' @@ -1110,10 +1110,6 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase '/div [ ./input - [@id="name_year"] - [@type="text"] - [@value="2011"] - /following-sibling::input [@id="name_month"] [@type="text"] [@value="2"] @@ -1121,6 +1117,10 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase [@id="name_day"] [@type="text"] [@value="3"] + /following-sibling::input + [@id="name_year"] + [@type="text"] + [@value="2011"] ] [count(./input)=3] ' @@ -1164,14 +1164,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase '/div [ ./select - [@id="name_year"] - [./option[@value="2000"][@selected="selected"]] - /following-sibling::select [@id="name_month"] [./option[@value="2"][@selected="selected"]] /following-sibling::select [@id="name_day"] [./option[@value="3"][@selected="selected"]] + /following-sibling::select + [@id="name_year"] + [./option[@value="2000"][@selected="selected"]] ] [count(./select)=3] ' @@ -1190,10 +1190,6 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase '/div [ ./select - [@id="name_year"] - [./option[@value=""][.="[trans][/trans]"]] - [./option[@value="1950"][@selected="selected"]] - /following-sibling::select [@id="name_month"] [./option[@value=""][.="[trans][/trans]"]] [./option[@value="1"][@selected="selected"]] @@ -1201,6 +1197,10 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase [@id="name_day"] [./option[@value=""][.="[trans][/trans]"]] [./option[@value="1"][@selected="selected"]] + /following-sibling::select + [@id="name_year"] + [./option[@value=""][.="[trans][/trans]"]] + [./option[@value="1950"][@selected="selected"]] ] [count(./select)=3] ' diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index 13b9d06207..fdff501668 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -510,18 +510,18 @@ class DateTypeTest extends LocalizedTestCase $form = $this->factory->create('date'); $view = $form->createView(); - $this->assertSame('{{ year }}-{{ month }}-{{ day }}', $view->vars['date_pattern']); + $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']); } public function testPassDatePatternToViewDifferentFormat() { $form = $this->factory->create('date', null, array( - 'format' => \IntlDateFormatter::MEDIUM, + 'format' => \IntlDateFormatter::LONG, )); $view = $form->createView(); - $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']); + $this->assertSame('{{ day }}. {{ month }} {{ year }}', $view->vars['date_pattern']); } public function testPassDatePatternToViewDifferentPattern() From ca5d9acb19459c605c66c60e6b79e8ef5e57bbd9 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 6 Dec 2012 19:23:55 +0100 Subject: [PATCH 054/175] [DoctrineBridge] Fixed caching in DoctrineType when "choices" or "preferred_choices" is passed --- .../Doctrine/Form/Type/DoctrineType.php | 8 ++-- .../Form/Type/EntityTypePerformanceTest.php | 45 ++++++++++++++++++- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index 5ac205a1d7..0cdfe03cd0 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -77,16 +77,16 @@ abstract class DoctrineType extends AbstractType // A second parameter ($key) is passed, so we cannot use // spl_object_hash() directly (which strictly requires // one parameter) - array_walk_recursive($choiceHashes, function ($value) { - return spl_object_hash($value); + array_walk_recursive($choiceHashes, function (&$value) { + $value = spl_object_hash($value); }); } $preferredChoiceHashes = $options['preferred_choices']; if (is_array($preferredChoiceHashes)) { - array_walk_recursive($preferredChoiceHashes, function ($value) { - return spl_object_hash($value); + array_walk_recursive($preferredChoiceHashes, function (&$value) { + $value = spl_object_hash($value); }); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php index e73dd11be0..8c3ee842d5 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php @@ -104,7 +104,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase { $this->setMaxRunningTime(1); - for ($i = 0; $i < 20; ++$i) { + for ($i = 0; $i < 40; ++$i) { $form = $this->factory->create('entity', null, array( 'class' => self::ENTITY_CLASS, )); @@ -114,11 +114,14 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase } } + /** + * @group benchmark + */ public function testCollapsedEntityFieldWithQueryBuilder() { $this->setMaxRunningTime(1); - for ($i = 0; $i < 20; ++$i) { + for ($i = 0; $i < 40; ++$i) { $form = $this->factory->create('entity', null, array( 'class' => self::ENTITY_CLASS, 'query_builder' => function (EntityRepository $repo) { @@ -130,4 +133,42 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase $form->createView(); } } + + /** + * @group benchmark + */ + public function testCollapsedEntityFieldWithChoices() + { + $choices = $this->em->createQuery('SELECT c FROM ' . self::ENTITY_CLASS . ' c')->getResult(); + $this->setMaxRunningTime(1); + + for ($i = 0; $i < 40; ++$i) { + $form = $this->factory->create('entity', null, array( + 'class' => self::ENTITY_CLASS, + 'choices' => $choices, + )); + + // force loading of the choice list + $form->createView(); + } + } + + /** + * @group benchmark + */ + public function testCollapsedEntityFieldWithPreferredChoices() + { + $choices = $this->em->createQuery('SELECT c FROM ' . self::ENTITY_CLASS . ' c')->getResult(); + $this->setMaxRunningTime(1); + + for ($i = 0; $i < 40; ++$i) { + $form = $this->factory->create('entity', null, array( + 'class' => self::ENTITY_CLASS, + 'preferred_choices' => $choices, + )); + + // force loading of the choice list + $form->createView(); + } + } } From 8bb3208ab819bb414538245c334cd0e488784309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Fri, 7 Dec 2012 14:24:02 +0100 Subject: [PATCH 055/175] [Config] Loader::import must return imported data --- src/Symfony/Component/Config/Loader/Loader.php | 4 +++- .../Symfony/Tests/Component/Config/Loader/LoaderTest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Config/Loader/Loader.php b/src/Symfony/Component/Config/Loader/Loader.php index 125ec4e58c..6763f836c9 100644 --- a/src/Symfony/Component/Config/Loader/Loader.php +++ b/src/Symfony/Component/Config/Loader/Loader.php @@ -47,10 +47,12 @@ abstract class Loader implements LoaderInterface * * @param mixed $resource A Resource * @param string $type The resource type + * + * @return mixed */ public function import($resource, $type = null) { - $this->resolve($resource)->load($resource, $type); + return $this->resolve($resource)->load($resource, $type); } /** diff --git a/tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php b/tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php index cd2ace0095..cc997c0c4d 100644 --- a/tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php +++ b/tests/Symfony/Tests/Component/Config/Loader/LoaderTest.php @@ -55,6 +55,15 @@ class LoaderTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Symfony\Component\Config\Exception\FileLoaderLoadException', $e, '->resolve() throws a FileLoaderLoadException if the resource cannot be loaded'); } } + + public function testImport() + { + $loader = $this->getMock('Symfony\Component\Config\Loader\Loader', array('supports', 'load')); + $loader->expects($this->once())->method('supports')->will($this->returnValue(true)); + $loader->expects($this->once())->method('load')->will($this->returnValue('yes')); + + $this->assertEquals('yes', $loader->import('foo')); + } } class ProjectLoader1 extends Loader From f48b22a44ea171404471f4371d5f0242705c5f80 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sun, 2 Dec 2012 19:25:07 +0100 Subject: [PATCH 056/175] Added configuration pass that adds Twig Loaders - Added compiler class which picks up any services tagged "twig.loader" - If there is one loader registered we set the alias to this loader - If there is more than one we set the alias to a chain loader and all the loaders to it - If there is no loaders we throw an Exception --- src/Symfony/Bundle/TwigBundle/CHANGELOG.md | 1 + .../Compiler/TwigLoaderPass.php | 53 +++++++++++ .../TwigBundle/Resources/config/twig.xml | 4 + .../Compiler/TwigLoaderPassTest.php | 87 +++++++++++++++++++ src/Symfony/Bundle/TwigBundle/TwigBundle.php | 2 + 5 files changed, 147 insertions(+) create mode 100644 src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php create mode 100644 src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php diff --git a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md index 3ddc5d809a..01834ca16c 100644 --- a/src/Symfony/Bundle/TwigBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/TwigBundle/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 2.2.0 ----- + * added support for multiple loaders via the "twig.loader" tag. * added automatic registration of namespaced paths for registered bundles * added support for namespaced paths diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php new file mode 100644 index 0000000000..3d0775990f --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Exception\LogicException; + +/** + * If there are any tagged loaders replace + * default filesystem loader with chain loader + * + * Add tagged loaders to chain loader + * + * @author Daniel Leech + */ +class TwigLoaderPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (false === $container->hasDefinition('twig')) { + return; + } + + // register additional template loaders + $loaderIds = $container->findTaggedServiceIds('twig.loader'); + + if (count($loaderIds) === 0) { + throw new LogicException('No twig loaders found. You need to tag at least one loader with "twig.loader"'); + } + + if (count($loaderIds) === 1) { + $container->setAlias('twig.loader', key($loaderIds)); + } else { + $chainLoader = $container->getDefinition('twig.loader.chain'); + foreach (array_keys($loaderIds) as $id) { + $chainLoader->addMethodCall('addLoader', array(new Reference($id))); + }; + $container->setAlias('twig.loader', 'twig.loader.chain'); + } + } +} + diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 35016810ff..1f310af134 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -7,6 +7,7 @@ Twig_Environment Symfony\Bundle\TwigBundle\Loader\FilesystemLoader + Twig_Loader_Chain Symfony\Bundle\TwigBundle\TwigEngine Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer Symfony\Bridge\Twig\Extension\TranslationExtension @@ -41,8 +42,11 @@ + + + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php new file mode 100644 index 0000000000..1f7d90e981 --- /dev/null +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php @@ -0,0 +1,87 @@ +builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); + $this->chainLoader = new Definition('loader'); + $this->pass = new TwigLoaderPass(); + } + + public function testMapperPassWithOneTaggedLoaders() + { + $serviceIds = array( + 'test_loader_1' => array( + ), + ); + + $this->builder->expects($this->once()) + ->method('hasDefinition') + ->with('twig') + ->will($this->returnValue(true)); + $this->builder->expects($this->once()) + ->method('findTaggedServiceIds') + ->with('twig.loader') + ->will($this->returnValue($serviceIds)); + $this->builder->expects($this->once()) + ->method('setAlias') + ->with('twig.loader', 'test_loader_1'); + + $this->pass->process($this->builder); + } + + public function testMapperPassWithTwoTaggedLoaders() + { + $serviceIds = array( + 'test_loader_1' => array( + ), + 'test_loader_2' => array( + ), + ); + + $this->builder->expects($this->once()) + ->method('hasDefinition') + ->with('twig') + ->will($this->returnValue(true)); + $this->builder->expects($this->once()) + ->method('findTaggedServiceIds') + ->with('twig.loader') + ->will($this->returnValue($serviceIds)); + $this->builder->expects($this->once()) + ->method('getDefinition') + ->with('twig.loader.chain') + ->will($this->returnValue($this->chainLoader)); + $this->builder->expects($this->once()) + ->method('setAlias') + ->with('twig.loader', 'twig.loader.chain'); + + $this->pass->process($this->builder); + $calls = $this->chainLoader->getMethodCalls(); + $this->assertEquals(2, count($calls)); + $this->assertEquals('addLoader', $calls[0][0]); + } + + /** + * @expectedException Symfony\Component\DependencyInjection\Exception\LogicException + */ + public function testMapperPassWithZeroTaggedLoaders() + { + $this->builder->expects($this->once()) + ->method('hasDefinition') + ->with('twig') + ->will($this->returnValue(true)); + $this->builder->expects($this->once()) + ->method('findTaggedServiceIds') + ->with('twig.loader') + ->will($this->returnValue(array())); + + $this->pass->process($this->builder); + } +} diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index a67756c0b1..88a172caab 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\TwigBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass; +use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass; use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExceptionListenerPass; /** @@ -28,6 +29,7 @@ class TwigBundle extends Bundle parent::build($container); $container->addCompilerPass(new TwigEnvironmentPass()); + $container->addCompilerPass(new TwigLoaderPass()); $container->addCompilerPass(new ExceptionListenerPass()); } } From 76e5bce8014b5627de25b394b0298a9a27317e4a Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Fri, 7 Dec 2012 22:24:45 +0100 Subject: [PATCH 057/175] no need to set the compiled route to null when cloning --- src/Symfony/Component/Routing/Route.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index 38fc3f494a..281dedff13 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -76,11 +76,6 @@ class Route implements \Serializable $this->setHostnamePattern($hostnamePattern); } - public function __clone() - { - $this->compiled = null; - } - public function serialize() { return serialize(array( From a37e5e323bac072103527c59b6e1f87fc73f4984 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sun, 9 Dec 2012 23:59:18 +0100 Subject: [PATCH 058/175] [Form] Fix const inside an anonymous function --- src/Symfony/Component/Form/Extension/Core/Type/DateType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 010d19da14..c659a77f04 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -181,7 +181,7 @@ class DateType extends AbstractType }; $format = function (Options $options) { - return $options['widget'] === 'single_text' ? self::HTML5_FORMAT : self::DEFAULT_FORMAT; + return $options['widget'] === 'single_text' ? DateType::HTML5_FORMAT : DateType::DEFAULT_FORMAT; }; // BC until Symfony 2.3 From cc0be8edf26fdf5e53ed981a2b859408e8eceea8 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 10 Dec 2012 09:25:50 +0100 Subject: [PATCH 059/175] [Finder] fluid, calling in() not required after append() --- src/Symfony/Component/Finder/Finder.php | 10 ++++++-- .../Component/Finder/Tests/FinderTest.php | 24 ++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index cbaa9acaa3..e2219e7128 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -615,8 +615,8 @@ class Finder implements \IteratorAggregate, \Countable */ public function getIterator() { - if (0 === count($this->dirs)) { - throw new \LogicException('You must call the in() method before iterating over a Finder.'); + if (0 === count($this->dirs) && 0 === count($this->iterators)) { + throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.'); } if (1 === count($this->dirs) && 0 === count($this->iterators)) { @@ -641,6 +641,10 @@ class Finder implements \IteratorAggregate, \Countable * The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array. * * @param mixed $iterator + * + * @return Finder The finder + * + * @throws \InvalidArgumentException When the given argument is not iterable. */ public function append($iterator) { @@ -657,6 +661,8 @@ class Finder implements \IteratorAggregate, \Countable } else { throw new \InvalidArgumentException('Finder::append() method wrong argument type.'); } + + return $this; } /** diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index 9b8384b5cc..5d6025494e 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -408,7 +408,8 @@ class FinderTest extends Iterator\RealIteratorTestCase $finder1 = $this->buildFinder($adapter); $finder1->directories()->in(self::$tmpDir); - $finder->append($finder1); + $finder = $finder->append($finder1); + $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator()); } @@ -426,6 +427,27 @@ class FinderTest extends Iterator\RealIteratorTestCase $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator()); } + /** + * @dataProvider getAdaptersTestData + */ + public function testAppendReturnsAFinder($adapter) + { + $this->assertInstanceOf('Symfony\\Component\\Finder\\Finder', $this->buildFinder($adapter)->append(array())); + } + + /** + * @dataProvider getAdaptersTestData + */ + public function testAppendDoesNotRequireIn($adapter) + { + $finder = $this->buildFinder($adapter); + $finder->in(self::$tmpDir.DIRECTORY_SEPARATOR.'foo'); + + $finder1 = Finder::create()->append($finder); + + $this->assertIterator(iterator_to_array($finder->getIterator()), $finder1->getIterator()); + } + public function testCountDirectories() { $finder = new Finder(); From 9e4681963d71168560fd5f1a48542422005ea69d Mon Sep 17 00:00:00 2001 From: Patrick Allaert Date: Mon, 10 Dec 2012 10:07:46 +0100 Subject: [PATCH 060/175] Fixed: HeaderBag::parseCacheControl() not parsing quoted zero correctly When having a Cache-Control header like: max-age="0" isset($match[2]) is true but $match[2] containing: "0", it is evaluated as false and 'true' will be set to "max-age" entry instead of "0". --- src/Symfony/Component/HttpFoundation/HeaderBag.php | 2 +- .../Component/HttpFoundation/Tests/HeaderBagTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/HeaderBag.php b/src/Symfony/Component/HttpFoundation/HeaderBag.php index f26899d007..2360e55bb4 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/HeaderBag.php @@ -317,7 +317,7 @@ class HeaderBag implements \IteratorAggregate, \Countable $cacheControl = array(); preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - $cacheControl[strtolower($match[1])] = isset($match[2]) && $match[2] ? $match[2] : (isset($match[3]) ? $match[3] : true); + $cacheControl[strtolower($match[1])] = isset($match[3]) ? $match[3] : (isset($match[2]) ? $match[2] : true); } return $cacheControl; diff --git a/src/Symfony/Component/HttpFoundation/Tests/HeaderBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/HeaderBagTest.php index bafccb2eba..67e6040d12 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/HeaderBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/HeaderBagTest.php @@ -125,6 +125,13 @@ class HeaderBagTest extends \PHPUnit_Framework_TestCase $this->assertEquals('max-age=10, public, s-maxage=100', $bag->get('cache-control')); } + public function testCacheControlDirectiveParsingQuotedZero() + { + $bag = new HeaderBag(array('cache-control' => 'max-age="0"')); + $this->assertTrue($bag->hasCacheControlDirective('max-age')); + $this->assertEquals(0, $bag->getCacheControlDirective('max-age')); + } + public function testCacheControlDirectiveOverrideWithReplace() { $bag = new HeaderBag(array('cache-control' => 'private, max-age=100')); From 9cf1d142b298002fab4c16c9802790583cc2122f Mon Sep 17 00:00:00 2001 From: Denis Gorbachev Date: Sat, 8 Dec 2012 17:22:45 +0400 Subject: [PATCH 061/175] Fixed a typo --- src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php index 3e7fff9c8e..87900a1242 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php @@ -78,7 +78,7 @@ class Controller extends ContainerAware * @param string $view The view name * @param array $parameters An array of parameters to pass to the view * - * @return string The renderer view + * @return string The rendered view */ public function renderView($view, array $parameters = array()) { From a1734ddf72d9bd85df7bf334fdb1126f9e24b19e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 10 Dec 2012 13:46:43 +0100 Subject: [PATCH 062/175] Revert "merged branch gajdaw/finder_splfileinfo_fpassthu (PR #4751)" (closes #6224) This reverts commit 5608c0c3ee21e6aade3170d6c580bf7ad452a143, reversing changes made to 38c30b71bd2d32ac31920996480d1706402118f2. Conflicts: src/Symfony/Component/Finder/SplFileInfo.php --- src/Symfony/Component/Finder/SplFileInfo.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Finder/SplFileInfo.php b/src/Symfony/Component/Finder/SplFileInfo.php index ee3d8ecf43..e9d4f7b72f 100644 --- a/src/Symfony/Component/Finder/SplFileInfo.php +++ b/src/Symfony/Component/Finder/SplFileInfo.php @@ -62,10 +62,14 @@ class SplFileInfo extends \SplFileInfo */ public function getContents() { - $file = new \SplFileObject($this->getRealpath(), 'rb'); - ob_start(); - $file->fpassthru(); + $level = error_reporting(0); + $content = file_get_contents($this->getRealpath()); + error_reporting($level); + if (false === $content) { + $error = error_get_last(); + throw new \RuntimeException($error['message']); + } - return ob_get_clean(); + return $content; } } From c68dd37c0edcd133e095bafeeb4bdbbbd688ac3b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 10 Dec 2012 14:50:56 +0100 Subject: [PATCH 063/175] removed the Travis icon (as this is not stable enough -- many false positive, closes #6186) --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 6a2856aefe..9e49f11a73 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ README ====== -[![Build Status](https://secure.travis-ci.org/symfony/symfony.png?branch=2.0)](http://travis-ci.org/symfony/symfony) - What is Symfony2? ----------------- From e62b5f78afeecf2896ea1bbfc773b56fee7e1c38 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 10 Dec 2012 09:50:12 +0100 Subject: [PATCH 064/175] [Finder] cleanup, fixes, improvements --- .../Finder/Adapter/AbstractAdapter.php | 29 +++++ .../Finder/Adapter/AbstractFindAdapter.php | 104 ++++++++---------- .../Finder/Adapter/AdapterInterface.php | 10 +- .../Finder/Adapter/BsdFindAdapter.php | 25 +++-- .../Finder/Adapter/GnuFindAdapter.php | 26 +++-- .../Component/Finder/Adapter/PhpAdapter.php | 8 +- src/Symfony/Component/Finder/Finder.php | 41 ++++--- .../Finder/Tests/FakeAdapter/DummyAdapter.php | 8 +- .../Tests/FakeAdapter/FailingAdapter.php | 8 +- .../Finder/Tests/FakeAdapter/NamedAdapter.php | 8 +- .../Tests/FakeAdapter/UnsupportedAdapter.php | 8 +- .../Component/Finder/Tests/FinderTest.php | 90 ++++++++------- 12 files changed, 198 insertions(+), 167 deletions(-) diff --git a/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php b/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php index 38ac2835fd..839a601638 100644 --- a/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/AbstractAdapter.php @@ -34,6 +34,22 @@ abstract class AbstractAdapter implements AdapterInterface protected $paths = array(); protected $notPaths = array(); + private static $areSupported = array(); + + /** + * {@inheritDoc} + */ + public function isSupported() + { + $name = $this->getName(); + + if (!array_key_exists($name, self::$areSupported)) { + self::$areSupported[$name] = $this->canBeUsed(); + } + + return self::$areSupported[$name]; + } + /** * {@inheritdoc} */ @@ -193,4 +209,17 @@ abstract class AbstractAdapter implements AdapterInterface return $this; } + + /** + * Returns whether the adapter is supported in the current environment. + * + * This method should be implemented in all adapters. Do not implement + * isSupported in the adapters as the generic implementation provides a cache + * layer. + * + * @see isSupported + * + * @return Boolean Whether the adapter is supported + */ + abstract protected function canBeUsed(); } diff --git a/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php b/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php index 9cde873a64..d60fbaa222 100644 --- a/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php @@ -59,11 +59,11 @@ abstract class AbstractFindAdapter extends AbstractAdapter $find->add('-follow'); } - $find->add('-mindepth')->add($this->minDepth+1); + $find->add('-mindepth')->add($this->minDepth + 1); // warning! INF < INF => true ; INF == INF => false ; INF === INF => true // https://bugs.php.net/bug.php?id=9118 if (INF !== $this->maxDepth) { - $find->add('-maxdepth')->add($this->maxDepth+1); + $find->add('-maxdepth')->add($this->maxDepth + 1); } if (Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES === $this->mode) { @@ -118,13 +118,14 @@ abstract class AbstractFindAdapter extends AbstractAdapter /** * {@inheritdoc} */ - public function isSupported() + protected function canBeUsed() { return $this->shell->testCommand('find'); } /** * @param Command $command + * @param string $dir * * @return Command */ @@ -140,7 +141,7 @@ abstract class AbstractFindAdapter extends AbstractAdapter /** * @param Command $command * @param string[] $names - * @param bool $not + * @param Boolean $not */ private function buildNamesFiltering(Command $command, array $names, $not = false) { @@ -183,7 +184,8 @@ abstract class AbstractFindAdapter extends AbstractAdapter * @param Command $command * @param string $dir * @param string[] $paths - * @param bool $not + * @param Boolean $not + * * @return void */ private function buildPathsFiltering(Command $command, $dir, array $paths, $not = false) @@ -226,33 +228,23 @@ abstract class AbstractFindAdapter extends AbstractAdapter foreach ($sizes as $i => $size) { $command->add($i > 0 ? '-and' : null); - if ('<=' === $size->getOperator()) { - $command->add('-size -'.($size->getTarget()+1).'c'); - continue; + switch ($size->getOperator()) { + case '<=': + $command->add('-size -' . ($size->getTarget() + 1) . 'c'); + break; + case '>=': + $command->add('-size +'. ($size->getTarget() - 1) . 'c'); + break; + case '>': + $command->add('-size +' . $size->getTarget() . 'c'); + break; + case '!=': + $command->add('-size -' . $size->getTarget() . 'c'); + $command->add('-size +' . $size->getTarget() . 'c'); + case '<': + default: + $command->add('-size -' . $size->getTarget() . 'c'); } - - if ('<' === $size->getOperator()) { - $command->add('-size -'.$size->getTarget().'c'); - continue; - } - - if ('>=' === $size->getOperator()) { - $command->add('-size +'.($size->getTarget()-1).'c'); - continue; - } - - if ('>' === $size->getOperator()) { - $command->add('-size +'.$size->getTarget().'c'); - continue; - } - - if ('!=' === $size->getOperator()) { - $command->add('-size -'.$size->getTarget().'c'); - $command->add('-size +'.$size->getTarget().'c'); - continue; - } - - $command->add('-size '.$size->getTarget().'c'); } } @@ -265,7 +257,7 @@ abstract class AbstractFindAdapter extends AbstractAdapter foreach ($dates as $i => $date) { $command->add($i > 0 ? '-and' : null); - $mins = (int) round((time()-$date->getTarget())/60); + $mins = (int) round((time()-$date->getTarget()) / 60); if (0 > $mins) { // mtime is in the future @@ -274,39 +266,30 @@ abstract class AbstractFindAdapter extends AbstractAdapter return; } - if ('<=' === $date->getOperator()) { - $command->add('-mmin +'.($mins-1)); - continue; + switch ($date->getOperator()) { + case '<=': + $command->add('-mmin +' . ($mins - 1)); + break; + case '>=': + $command->add('-mmin -' . ($mins + 1)); + break; + case '>': + $command->add('-mmin -' . $mins); + break; + case '!=': + $command->add('-mmin +' . $mins.' -or -mmin -' . $mins); + break; + case '<': + default: + $command->add('-mmin +' . $mins); } - - if ('<' === $date->getOperator()) { - $command->add('-mmin +'.$mins); - continue; - } - - if ('>=' === $date->getOperator()) { - $command->add('-mmin -'.($mins+1)); - continue; - } - - if ('>' === $date->getOperator()) { - $command->add('-mmin -'.$mins); - continue; - } - - if ('!=' === $date->getOperator()) { - $command->add('-mmin +'.$mins.' -or -mmin -'.$mins); - continue; - } - - $command->add('-mmin '.$mins); } } /** * @param Command $command * @param array $contains - * @param bool $not + * @param Boolean $not */ private function buildContentFiltering(Command $command, array $contains, $not = false) { @@ -323,8 +306,9 @@ abstract class AbstractFindAdapter extends AbstractAdapter } /** - * @param \Symfony\Component\Finder\Shell\Command $command - * @param string $sort + * @param Command $command + * @param string $sort + * * @throws \InvalidArgumentException */ private function buildSorting(Command $command, $sort) diff --git a/src/Symfony/Component/Finder/Adapter/AdapterInterface.php b/src/Symfony/Component/Finder/Adapter/AdapterInterface.php index 829297b3ec..f28ffb3189 100644 --- a/src/Symfony/Component/Finder/Adapter/AdapterInterface.php +++ b/src/Symfony/Component/Finder/Adapter/AdapterInterface.php @@ -17,14 +17,14 @@ namespace Symfony\Component\Finder\Adapter; interface AdapterInterface { /** - * @param bool $followLinks + * @param Boolean $followLinks * * @return AdapterInterface Current instance */ public function setFollowLinks($followLinks); /** - * @param int $mode + * @param integer $mode * * @return AdapterInterface Current instance */ @@ -94,14 +94,14 @@ interface AdapterInterface public function setFilters(array $filters); /** - * @param \Closure|int $sort + * @param \Closure|integer $sort * * @return AdapterInterface Current instance */ public function setSort($sort); /** - * @param array $path + * @param array $paths * * @return AdapterInterface Current instance */ @@ -124,7 +124,7 @@ interface AdapterInterface /** * Tests adapter support for current platform. * - * @return bool + * @return Boolean */ public function isSupported(); diff --git a/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php b/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php index 12f2f69768..53adc1f4e6 100644 --- a/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/BsdFindAdapter.php @@ -22,14 +22,6 @@ use Symfony\Component\Finder\Shell\Command; */ class BsdFindAdapter extends AbstractFindAdapter { - /** - * {@inheritdoc} - */ - public function isSupported() - { - return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::isSupported(); - } - /** * {@inheritdoc} */ @@ -38,12 +30,25 @@ class BsdFindAdapter extends AbstractFindAdapter return 'bsd_find'; } + /** + * {@inheritdoc} + */ + protected function canBeUsed() + { + return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed(); + } + /** * {@inheritdoc} */ protected function buildFormatSorting(Command $command, $format) { - $command->get('find')->add('-print0 | xargs -0 stat -f')->arg($format.' %h/%f\\n') - ->add('| sort | cut')->arg('-d ')->arg('-f2-'); + $command + ->get('find') + ->add('-print0 | xargs -0 stat -f') + ->arg($format.' %h/%f\\n') + ->add('| sort | cut') + ->arg('-d ') + ->arg('-f2-'); } } diff --git a/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php b/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php index bd903581d2..ac741745ff 100644 --- a/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/GnuFindAdapter.php @@ -22,14 +22,6 @@ use Symfony\Component\Finder\Shell\Command; */ class GnuFindAdapter extends AbstractFindAdapter { - /** - * {@inheritdoc} - */ - public function isSupported() - { - return $this->shell->getType() === Shell::TYPE_UNIX && parent::isSupported(); - } - /** * {@inheritdoc} */ @@ -43,8 +35,22 @@ class GnuFindAdapter extends AbstractFindAdapter */ protected function buildFormatSorting(Command $command, $format) { - $command->get('find')->add('-printf')->arg($format.' %h/%f\\n') - ->add('| sort | cut')->arg('-d ')->arg('-f2-'); + $command + ->get('find') + ->add('-printf') + ->arg($format.' %h/%f\\n') + ->add('| sort | cut') + ->arg('-d ') + ->arg('-f2-') + ; + } + + /** + * {@inheritdoc} + */ + protected function canBeUsed() + { + return $this->shell->getType() === Shell::TYPE_UNIX && parent::canBeUsed(); } /** diff --git a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php index 3607165f9b..dfc842f6b5 100644 --- a/src/Symfony/Component/Finder/Adapter/PhpAdapter.php +++ b/src/Symfony/Component/Finder/Adapter/PhpAdapter.php @@ -83,16 +83,16 @@ class PhpAdapter extends AbstractAdapter /** * {@inheritdoc} */ - public function isSupported() + public function getName() { - return true; + return 'php'; } /** * {@inheritdoc} */ - public function getName() + protected function canBeUsed() { - return 'php'; + return true; } } diff --git a/src/Symfony/Component/Finder/Finder.php b/src/Symfony/Component/Finder/Finder.php index cbaa9acaa3..88d2198e15 100644 --- a/src/Symfony/Component/Finder/Finder.php +++ b/src/Symfony/Component/Finder/Finder.php @@ -65,9 +65,11 @@ class Finder implements \IteratorAggregate, \Countable { $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES; - $this->addAdapter(new GnuFindAdapter()); - $this->addAdapter(new BsdFindAdapter()); - $this->addAdapter(new PhpAdapter(), -50); + $this + ->addAdapter(new GnuFindAdapter()) + ->addAdapter(new BsdFindAdapter()) + ->addAdapter(new PhpAdapter(), -50) + ; } /** @@ -86,7 +88,7 @@ class Finder implements \IteratorAggregate, \Countable * Registers a finder engine implementation. * * @param AdapterInterface $adapter An adapter instance - * @param int $priority Highest is selected first + * @param integer $priority Highest is selected first * * @return Finder The current Finder instance */ @@ -418,9 +420,20 @@ class Finder implements \IteratorAggregate, \Countable return $this; } + /** + * Adds VCS patterns. + * + * @see ignoreVCS + * + * @param string|string[] $pattern VCS patterns to ignore + */ public static function addVCSPattern($pattern) { - self::$vcsPatterns[] = $pattern; + foreach ((array) $pattern as $p) { + self::$vcsPatterns[] = $p; + } + + self::$vcsPatterns = array_unique(self::$vcsPatterns); } /** @@ -685,6 +698,8 @@ class Finder implements \IteratorAggregate, \Countable * @param $dir * * @return \Iterator + * + * @throws \RuntimeException When none of the adapters are supported */ private function searchInDirectory($dir) { @@ -697,16 +712,12 @@ class Finder implements \IteratorAggregate, \Countable } foreach ($this->adapters as $adapter) { - if (!$adapter['adapter']->isSupported()) { - continue; - } - - try { - return $this - ->buildAdapter($adapter['adapter']) - ->searchInDirectory($dir); - } catch(ExceptionInterface $e) { - continue; + if ($adapter['adapter']->isSupported()) { + try { + return $this + ->buildAdapter($adapter['adapter']) + ->searchInDirectory($dir); + } catch(ExceptionInterface $e) {} } } diff --git a/src/Symfony/Component/Finder/Tests/FakeAdapter/DummyAdapter.php b/src/Symfony/Component/Finder/Tests/FakeAdapter/DummyAdapter.php index c7143bfd76..0cbae14b88 100644 --- a/src/Symfony/Component/Finder/Tests/FakeAdapter/DummyAdapter.php +++ b/src/Symfony/Component/Finder/Tests/FakeAdapter/DummyAdapter.php @@ -42,16 +42,16 @@ class DummyAdapter extends AbstractAdapter /** * {@inheritdoc} */ - public function isSupported() + public function getName() { - return true; + return 'yes'; } /** * {@inheritdoc} */ - public function getName() + protected function canBeUsed() { - return 'yes'; + return true; } } diff --git a/src/Symfony/Component/Finder/Tests/FakeAdapter/FailingAdapter.php b/src/Symfony/Component/Finder/Tests/FakeAdapter/FailingAdapter.php index 00fc022fdf..6e6ed24b61 100644 --- a/src/Symfony/Component/Finder/Tests/FakeAdapter/FailingAdapter.php +++ b/src/Symfony/Component/Finder/Tests/FakeAdapter/FailingAdapter.php @@ -30,16 +30,16 @@ class FailingAdapter extends AbstractAdapter /** * {@inheritdoc} */ - public function isSupported() + public function getName() { - return true; + return 'failing'; } /** * {@inheritdoc} */ - function getName() + protected function canBeUsed() { - return 'failing'; + return true; } } diff --git a/src/Symfony/Component/Finder/Tests/FakeAdapter/NamedAdapter.php b/src/Symfony/Component/Finder/Tests/FakeAdapter/NamedAdapter.php index 2321195e94..5a260b0dfc 100644 --- a/src/Symfony/Component/Finder/Tests/FakeAdapter/NamedAdapter.php +++ b/src/Symfony/Component/Finder/Tests/FakeAdapter/NamedAdapter.php @@ -42,16 +42,16 @@ class NamedAdapter extends AbstractAdapter /** * {@inheritdoc} */ - public function isSupported() + public function getName() { - return true; + return $this->name; } /** * {@inheritdoc} */ - function getName() + protected function canBeUsed() { - return $this->name; + return true; } } diff --git a/src/Symfony/Component/Finder/Tests/FakeAdapter/UnsupportedAdapter.php b/src/Symfony/Component/Finder/Tests/FakeAdapter/UnsupportedAdapter.php index d02a13e032..1f91b98a60 100644 --- a/src/Symfony/Component/Finder/Tests/FakeAdapter/UnsupportedAdapter.php +++ b/src/Symfony/Component/Finder/Tests/FakeAdapter/UnsupportedAdapter.php @@ -29,16 +29,16 @@ class UnsupportedAdapter extends AbstractAdapter /** * {@inheritdoc} */ - public function isSupported() + public function getName() { - return false; + return 'unsupported'; } /** * {@inheritdoc} */ - function getName() + protected function canBeUsed() { - return 'unsupported'; + return false; } } diff --git a/src/Symfony/Component/Finder/Tests/FinderTest.php b/src/Symfony/Component/Finder/Tests/FinderTest.php index 9b8384b5cc..21604d896e 100644 --- a/src/Symfony/Component/Finder/Tests/FinderTest.php +++ b/src/Symfony/Component/Finder/Tests/FinderTest.php @@ -356,9 +356,7 @@ class FinderTest extends Iterator\RealIteratorTestCase */ public function testRelativePath($adapter) { - $finder = $this->buildFinder($adapter); - - $finder->in(self::$tmpDir); + $finder = $this->buildFinder($adapter)->in(self::$tmpDir); $paths = array(); @@ -379,9 +377,7 @@ class FinderTest extends Iterator\RealIteratorTestCase */ public function testRelativePathname($adapter) { - $finder = $this->buildFinder($adapter); - - $finder->in(self::$tmpDir)->sortByName(); + $finder = $this->buildFinder($adapter)->in(self::$tmpDir)->sortByName(); $paths = array(); @@ -428,8 +424,7 @@ class FinderTest extends Iterator\RealIteratorTestCase public function testCountDirectories() { - $finder = new Finder(); - $directory = $finder->directories()->in(self::$tmpDir); + $directory = Finder::create()->directories()->in(self::$tmpDir); $i = 0; foreach ($directory as $dir) { @@ -441,8 +436,7 @@ class FinderTest extends Iterator\RealIteratorTestCase public function testCountFiles() { - $finder = new Finder(); - $files = $finder->files()->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'); + $files = Finder::create()->files()->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures'); $i = 0; foreach ($files as $file) { @@ -452,17 +446,13 @@ class FinderTest extends Iterator\RealIteratorTestCase $this->assertCount($i, $files); } + /** + * @expectedException \LogicException + */ public function testCountWithoutIn() { - $finder = new Finder(); - $finder->files(); - - try { - count($finder); - $this->fail('Countable makes use of the getIterator command'); - } catch (\Exception $e) { - $this->assertInstanceOf('LogicException', $e, '->getIterator() throws \LogicException when no logic has been entered'); - } + $finder = Finder::create()->files(); + count($finder); } protected function toAbsolute($files) @@ -619,37 +609,10 @@ class FinderTest extends Iterator\RealIteratorTestCase return $this->buildTestData($tests); } - private function buildFinder(Adapter\AdapterInterface $adapter) - { - return Finder::create() - ->removeAdapters() - ->addAdapter($adapter); - } - - private function getValidAdapters() - { - return array_filter( - array(new Adapter\GnuFindAdapter(), new Adapter\PhpAdapter()), - function (Adapter\AdapterInterface $adapter) { return $adapter->isSupported(); } - ); - } - - private function buildTestData(array $tests) - { - $data = array(); - foreach ($this->getValidAdapters() as $adapter) { - foreach ($tests as $test) { - $data[] = array_merge(array($adapter), $test); - } - } - - return $data; - } - /** * @dataProvider getTestPathData */ - public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noMatchPatterns, $expected) + public function testPath(Adapter\AdapterInterface $adapter, $matchPatterns, $noMatchPatterns, array $expected) { $finder = $this->buildFinder($adapter); $finder->in(__DIR__.DIRECTORY_SEPARATOR.'Fixtures') @@ -700,4 +663,37 @@ class FinderTest extends Iterator\RealIteratorTestCase return $this->buildTestData($tests); } + + private function buildTestData(array $tests) + { + $data = array(); + foreach ($this->getValidAdapters() as $adapter) { + foreach ($tests as $test) { + $data[] = array_merge(array($adapter), $test); + } + } + + return $data; + } + + private function buildFinder(Adapter\AdapterInterface $adapter) + { + return Finder::create() + ->removeAdapters() + ->addAdapter($adapter); + } + + private function getValidAdapters() + { + return array_filter( + array( + new Adapter\BsdFindAdapter(), + new Adapter\GnuFindAdapter(), + new Adapter\PhpAdapter() + ), + function (Adapter\AdapterInterface $adapter) { + return $adapter->isSupported(); + } + ); + } } From 5d98fb124863bd008f74ca166cee6381d95ba1b1 Mon Sep 17 00:00:00 2001 From: Bilal Amarni Date: Mon, 10 Dec 2012 18:52:47 +0100 Subject: [PATCH 065/175] [HttpKernel] ExceptionHandler is actually displaying PHP errors Since even fatal errors are catched and turned into exceptions by ErrorHandler, all PHP errors can nicely be displayed by ExceptionHandler. There is no need to set display_errors to true anymore then. Partially fixes #6254 on github. --- .../Component/HttpKernel/Debug/ExceptionHandler.php | 3 --- src/Symfony/Component/HttpKernel/Kernel.php | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php b/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php index 79d7d66dcc..88ef3d7615 100644 --- a/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php @@ -234,9 +234,6 @@ EOF; img { border: 0; } #sf-resetcontent { width:970px; margin:0 auto; } $css - .xdebug-error { - display: none; - } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 046d0c8a6a..a34ddbb6d0 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -95,17 +95,18 @@ abstract class Kernel implements KernelInterface, TerminableInterface public function init() { + ini_set('display_errors', 0); + if ($this->debug) { - ini_set('display_errors', 1); error_reporting(-1); DebugClassLoader::enable(); ErrorHandler::register($this->errorReportingLevel); if ('cli' !== php_sapi_name()) { ExceptionHandler::register(); + } else { + ini_set('display_errors', 1); } - } else { - ini_set('display_errors', 0); } } From bae5cffe7e4e496a4839077d5de859d45be57a07 Mon Sep 17 00:00:00 2001 From: Martin Ledgard Date: Mon, 10 Dec 2012 19:38:43 +0000 Subject: [PATCH 066/175] fix date in changelog --- CHANGELOG-2.1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index cf59cb7070..03074c23db 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -7,7 +7,7 @@ in 2.1 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v2.1.0...v2.1.1 -* 2.1.4 (2012-12-29) +* 2.1.4 (2012-11-29) * e5536f0: replaced magic strings by proper constants * 6a3ba52: fixed the logic in Request::isSecure() (if the information comes from a source that we trust, don't check other ones) From 4e909bd016b549b7b2a368e48c4f34200e62c89d Mon Sep 17 00:00:00 2001 From: kaywalker Date: Thu, 30 Aug 2012 19:08:45 +0300 Subject: [PATCH 067/175] Fix to allow null values in labels array --- .../Extension/Core/ChoiceList/ChoiceList.php | 2 +- .../Extension/Core/ChoiceList/ChoiceListTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php index fcccfdd0bd..4fbca4b451 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php @@ -261,7 +261,7 @@ class ChoiceList implements ChoiceListInterface { // Add choices to the nested buckets foreach ($choices as $group => $choice) { - if (!isset($labels[$group])) { + if (!array_key_exists($group, $labels)) { throw new \InvalidArgumentException('The structures of the choices and labels array do not match.'); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php index 86533e8af8..7e967924d3 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php @@ -184,4 +184,20 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase array('A') ); } + + /** + * test for pull request: https://github.com/symfony/symfony/pull/5394 + */ + public function testLabelsContainingNull() + { + $this->list = new ChoiceList( + array($this->obj1, $this->obj2), + array('A', null) + ); + + $this->assertEquals( + array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', null)), + $this->list->getRemainingViews() + ); + } } From f853fc39062027a4efa54a38501e057b8c09fd28 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 09:06:32 +0100 Subject: [PATCH 068/175] removed unneeded comment --- .../Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php index 7e967924d3..63eae9bf7f 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php @@ -185,9 +185,6 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase ); } - /** - * test for pull request: https://github.com/symfony/symfony/pull/5394 - */ public function testLabelsContainingNull() { $this->list = new ChoiceList( From 36e455680549bfe9fa5b1282e95bb9b36f2220be Mon Sep 17 00:00:00 2001 From: BenjaminBeck Date: Mon, 3 Sep 2012 12:17:03 +0300 Subject: [PATCH 069/175] [Form] Option for not displaying a label by setting label to false. [Form] Fixed formatting & translation .. --- .../Twig/Resources/views/Form/form_div_layout.html.twig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 0e562e4142..840fdcda99 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -227,10 +227,12 @@ {% if required %} {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} {% endif %} - {% if label is empty %} - {% set label = name|humanize %} + {% if label is not sameas(false) %} + {% if label is empty %} + {% set label = name|humanize %} + {% endif %} + {{ label|trans({}, translation_domain) }} {% endif %} - {{ label|trans({}, translation_domain) }} {% endspaceless %} {% endblock form_label %} From 120547c8bcdc530f00508c0ab3abb3a6e04a2cc6 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 11 Dec 2012 09:29:21 +0100 Subject: [PATCH 070/175] [Form][TwigBridge] Don't set label attributes if is marked as not to be rendered [Form][FrameworkBundle] Add option to disable rendering of label for fields --- .../Resources/views/Form/form_div_layout.html.twig | 12 ++++++------ .../Resources/views/Form/form_label.html.php | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 840fdcda99..177e6f1e47 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -221,13 +221,13 @@ {% block form_label %} {% spaceless %} - {% if not compound %} - {% set label_attr = label_attr|merge({'for': id}) %} - {% endif %} - {% if required %} - {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} - {% endif %} {% if label is not sameas(false) %} + {% if not compound %} + {% set label_attr = label_attr|merge({'for': id}) %} + {% endif %} + {% if required %} + {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %} + {% endif %} {% if label is empty %} {% set label = name|humanize %} {% endif %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php index 48dd147a60..4ed04cc392 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_label.html.php @@ -1,4 +1,6 @@ + humanize($name); } ?> + From e3ef9368df1f5e1097772833c37722e715f92b42 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 09:31:58 +0100 Subject: [PATCH 071/175] [FrameworkBundle] tweaked previous merge --- .../DependencyInjection/Compiler/TwigLoaderPass.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php index 3d0775990f..075177d5eb 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/TwigLoaderPass.php @@ -17,10 +17,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Exception\LogicException; /** - * If there are any tagged loaders replace - * default filesystem loader with chain loader - * - * Add tagged loaders to chain loader + * Adds services tagged twig.loader as Twig loaders * * @author Daniel Leech */ @@ -45,9 +42,8 @@ class TwigLoaderPass implements CompilerPassInterface $chainLoader = $container->getDefinition('twig.loader.chain'); foreach (array_keys($loaderIds) as $id) { $chainLoader->addMethodCall('addLoader', array(new Reference($id))); - }; + } $container->setAlias('twig.loader', 'twig.loader.chain'); } } } - From d5426f0a7609d97f5fa52a77be79a1280bddd460 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Tue, 11 Dec 2012 09:37:25 +0100 Subject: [PATCH 072/175] [Form] Add tests to prove that label is not rendered when is marked as false --- .../Form/Tests/AbstractDivLayoutTest.php | 17 +++++++++++++++++ .../Form/Tests/AbstractTableLayoutTest.php | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php index 576d7890da..ac9b18b065 100644 --- a/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractDivLayoutTest.php @@ -526,6 +526,23 @@ abstract class AbstractDivLayoutTest extends AbstractLayoutTest ); } + public function testLabelIsNotRenderedWhenSetToFalse() + { + $form = $this->factory->createNamed('name', 'text', null, array( + 'label' => false + )); + $html = $this->renderRow($form->createView()); + + $this->assertMatchesXpath($html, +'/div + [ + ./input[@id="name"] + ] + [count(//label)=0] +' + ); + } + /** * @dataProvider themeBlockInheritanceProvider */ diff --git a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php index c21c712c5c..efa957fb0b 100644 --- a/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php +++ b/src/Symfony/Component/Form/Tests/AbstractTableLayoutTest.php @@ -39,6 +39,25 @@ abstract class AbstractTableLayoutTest extends AbstractLayoutTest ); } + public function testLabelIsNotRenderedWhenSetToFalse() + { + $form = $this->factory->createNamed('name', 'text', null, array( + 'label' => false + )); + $html = $this->renderRow($form->createView()); + + $this->assertMatchesXpath($html, +'/tr + [ + ./td + [count(//label)=0] + /following-sibling::td + [./input[@id="name"]] + ] +' + ); + } + public function testRepeatedRow() { $form = $this->factory->createNamed('name', 'repeated'); From 1ab492394c540f5ff857fec2a94eea78a4a54252 Mon Sep 17 00:00:00 2001 From: Florin Patan Date: Sat, 17 Nov 2012 12:57:00 +0200 Subject: [PATCH 073/175] Improved Cache-Control header when no-cache is sent --- .../Component/HttpFoundation/Response.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 2d19dd63aa..4d8992a7c3 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -245,6 +245,12 @@ class Response $this->setProtocolVersion('1.1'); } + // Check if we need to send extra expire info headers + if ('1.0' == $this->getProtocolVersion() && 'no-cache' == $this->headers->get('Cache-Control')) { + $this->headers->set('pragma', 'no-cache'); + $this->headers->set('expires', -1); + } + return $this; } @@ -686,8 +692,14 @@ class Response return $age; } - if (null !== $this->getExpires()) { - return $this->getExpires()->format('U') - $this->getDate()->format('U'); + $expiry = $this->getExpires(); + + if (!$expiry instanceof \DateTime && (-1 == $expiry || 0 === $expiry)) { + return $expiry; + } + + if (null !== $expiry) { + return $expiry->format('U') - $this->getDate()->format('U'); } return null; From 47dfb9cb6a44526dd882614f05df8242eb2d9ce2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 10:29:04 +0100 Subject: [PATCH 074/175] [HttpFoundation] added some tests for the previous merge and removed dead code (closes #6037) --- .../Component/HttpFoundation/Response.php | 10 ++-------- .../HttpFoundation/Tests/ResponseTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 4d8992a7c3..7428b9a9c3 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -692,14 +692,8 @@ class Response return $age; } - $expiry = $this->getExpires(); - - if (!$expiry instanceof \DateTime && (-1 == $expiry || 0 === $expiry)) { - return $expiry; - } - - if (null !== $expiry) { - return $expiry->format('U') - $this->getDate()->format('U'); + if (null !== $this->getExpires()) { + return $this->getExpires()->format('U') - $this->getDate()->format('U'); } return null; diff --git a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php index c14dc4b83d..4fc93c33ef 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php @@ -351,6 +351,23 @@ class ResponseTest extends \PHPUnit_Framework_TestCase $this->assertEquals('', $response->getContent()); } + public function testPrepareSetsPragmaOnHttp10Only() + { + $request = Request::create('/', 'GET'); + $request->server->set('SERVER_PROTOCOL', 'HTTP/1.0'); + + $response = new Response('foo'); + $response->prepare($request); + $this->assertEquals('no-cache', $response->headers->get('pragma')); + $this->assertEquals('-1', $response->headers->get('expires')); + + $request->server->set('SERVER_PROTOCOL', 'HTTP/1.1'); + $response = new Response('foo'); + $response->prepare($request); + $this->assertFalse($response->headers->has('pragma')); + $this->assertFalse($response->headers->has('expires')); + } + public function testSetCache() { $response = new Response(); From d6a402a28357e2018cedc1fae24f94309569edad Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 10:40:14 +0100 Subject: [PATCH 075/175] [Security] fixed path info encoding (closes #6040, closes #5695) --- src/Symfony/Component/Security/Http/HttpUtils.php | 2 +- src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/HttpUtils.php b/src/Symfony/Component/Security/Http/HttpUtils.php index 1c87e770a1..76cfc6af09 100644 --- a/src/Symfony/Component/Security/Http/HttpUtils.php +++ b/src/Symfony/Component/Security/Http/HttpUtils.php @@ -106,7 +106,7 @@ class HttpUtils } } - return $path === $request->getPathInfo(); + return $path === rawurldecode($request->getPathInfo()); } /** diff --git a/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php b/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php index a30051fdd0..fc1b754db9 100644 --- a/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php +++ b/src/Symfony/Component/Security/Tests/Http/HttpUtilsTest.php @@ -97,6 +97,11 @@ class HttpUtilsTest extends \PHPUnit_Framework_TestCase $this->assertTrue($utils->checkRequestPath($this->getRequest(), '/')); $this->assertFalse($utils->checkRequestPath($this->getRequest(), '/foo')); + $this->assertTrue($utils->checkRequestPath($this->getRequest('/foo%20bar'), '/foo bar')); + // Plus must not decoded to space + $this->assertTrue($utils->checkRequestPath($this->getRequest('/foo+bar'), '/foo+bar')); + // Checking unicode + $this->assertTrue($utils->checkRequestPath($this->getRequest(urlencode('/вход')), '/вход')); $urlMatcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface'); $urlMatcher From 7428bf9aa4a1ce4869d4f957fd098c0ce30a520e Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 7 Dec 2012 12:47:14 +0100 Subject: [PATCH 076/175] [WebProfilerBundle] Some eye candy for deprecated calls --- .../views/Collector/logger.html.twig | 74 +++++++++++++++---- .../views/Profiler/profiler.css.twig | 4 + .../DataCollector/LoggerDataCollector.php | 3 +- .../HttpKernel/Debug/ErrorHandler.php | 15 +++- .../HttpKernel/Debug/ExceptionHandler.php | 8 +- .../DataCollector/LoggerDataCollectorTest.php | 5 +- .../Tests/Debug/ErrorHandlerTest.php | 23 +++++- 7 files changed, 102 insertions(+), 30 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig index 36a3fb0be2..7a8fa53b5f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig @@ -1,16 +1,18 @@ {% extends '@WebProfiler/Profiler/layout.html.twig' %} +{% import _self as logger %} + {% block toolbar %} {% if collector.counterrors or collector.countdeprecations %} {% set icon %} Logs {% if collector.counterrors %} - {% set statusColor = "red" %} + {% set status_color = "red" %} {% else %} - {% set statusColor = "yellow" %} + {% set status_color = "yellow" %} {% endif %} - {% set errorCount = collector.counterrors + collector.countdeprecations %} - {{ errorCount }} + {% set error_count = collector.counterrors + collector.countdeprecations %} + {{ error_count }} {% endset %} {% set text %} {% if collector.counterrors %} @@ -35,9 +37,9 @@ Logger Logs {% if collector.counterrors or collector.countdeprecations %} - {% set errorCount = collector.counterrors + collector.countdeprecations %} + {% set error_count = collector.counterrors + collector.countdeprecations %} - {{ errorCount }} + {{ error_count }} {% endif %} @@ -56,7 +58,19 @@ @@ -70,15 +84,9 @@ {% if collector.logs %}
    - {% for log in collector.logs if log.priority >= priority %} + {% for log in collector.logs if priority >= 0 and log.priority >= priority or priority < 0 and log.context.type|default(0) == priority %}
  • - {{ log.priorityName }} - {{ log.message }} - {% if log.context is defined and log.context is not empty %} -
    - - Context: {{ log.context|yaml_encode }} - - {% endif %} + {{ logger.display_message(loop.index, log) }}
  • {% else %}
  • No logs available for this priority.
  • @@ -90,3 +98,39 @@

    {% endif %} {% endblock %} + + +{% macro display_message(log_index, log) %} + {% if constant('Symfony\\Component\\HttpKernel\\Debug\\ErrorHandler::TYPE_DEPRECATION') == log.context.type|default(0) %} + DEPRECATION - Deprecated call in {{ log.context.file|format_file(log.context.line) }}. + {% set id = 'sf-call-stack-' ~ log_index %} + + + + + + {% for index, call in log.context.stack if index > 0 %} + {% if index == 1 %} + ' : '' }} + {% endfor %} + {% else %} + {{ log.priorityName }} - {{ log.message }} + {% endif %} +{% endmacro %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig index 6b8c045527..6f5cde5dc5 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig @@ -273,6 +273,10 @@ ul.alt li.warning { background-color: #ffcc00; margin-bottom: 1px; } +ul.sf-call-stack li { + text-size: small; + padding: 0 0 0 20px; +} td.main, td.menu { text-align: left; margin: 0; diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php index 629b451f70..f08720e807 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\DataCollector; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Debug\ErrorHandler; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; @@ -114,7 +115,7 @@ class LoggerDataCollector extends DataCollector { $count = 0; foreach ($this->logger->getLogs() as $log) { - if (isset($log['context']['type']) && 'deprecation' === $log['context']['type']) { + if (isset($log['context']['type']) && ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) { $count++; } } diff --git a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php index f81ea58bf7..50eadfe0a5 100644 --- a/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php +++ b/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php @@ -21,6 +21,8 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface; */ class ErrorHandler { + const TYPE_DEPRECATION = -100; + private $levels = array( E_WARNING => 'Warning', E_NOTICE => 'Notice', @@ -82,9 +84,18 @@ class ErrorHandler return false; } - if ($level & E_USER_DEPRECATED || $level & E_DEPRECATED) { + if ($level & (E_USER_DEPRECATED | E_DEPRECATED)) { if (null !== self::$logger) { - self::$logger->warn($message, array('type' => 'deprecation', 'file' => $file, 'line' => $line)); + $deprecation = array( + 'type' => self::TYPE_DEPRECATION, + 'file' => $file, + 'line' => $line, + 'stack' => version_compare(PHP_VERSION, '5.4', '<') + ? array_slice(debug_backtrace(false), 0, 10) + : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10) + ); + + self::$logger->warn($message, $deprecation); } return true; diff --git a/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php b/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php index 79d7d66dcc..5fdf0e96e8 100644 --- a/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php @@ -91,7 +91,6 @@ class ExceptionHandler */ public function getContent(FlattenException $exception) { - $title = ''; switch ($exception->getStatusCode()) { case 404: $title = 'Sorry, the page you are looking for could not be found.'; @@ -103,13 +102,10 @@ class ExceptionHandler $content = ''; if ($this->debug) { try { - $message = nl2br($exception->getMessage()); - $class = $this->abbrClass($exception->getClass()); $count = count($exception->getAllPrevious()); - $content = ''; + $total = $count + 1; foreach ($exception->toArray() as $position => $e) { $ind = $count - $position + 1; - $total = $count + 1; $class = $this->abbrClass($e['class']); $message = nl2br($e['message']); $content .= sprintf(<< $trace) { + foreach ($e['trace'] as $trace) { $content .= '
  • '; if ($trace['function']) { $content .= sprintf('at %s%s%s(%s)', $this->abbrClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args'])); diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php index c4ec7634a4..ea82d9d315 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\DataCollector; use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector; +use Symfony\Component\HttpKernel\Debug\ErrorHandler; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -66,8 +67,8 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase array( 1, array( - array('message' => 'foo', 'context' => array('type' => 'deprecation')), - array('message' => 'foo2', 'context' => array('type' => 'deprecation')) + array('message' => 'foo', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION)), + array('message' => 'foo2', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION)) ), null, 2 diff --git a/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php b/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php index 491a0a7106..fdd02eaaf5 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Debug/ErrorHandlerTest.php @@ -68,10 +68,25 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase restore_error_handler(); $logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface'); - $logger->expects($this->once())->method('warn')->with( - $this->equalTo('foo'), - $this->equalTo(array('type' => 'deprecation', 'file' => 'foo.php', 'line' => '12')) - ); + + $that = $this; + $warnArgCheck = function($message, $context) use ($that) { + $that->assertEquals('foo', $message); + $that->assertArrayHasKey('file', $context); + $that->assertEquals($context['file'], 'foo.php'); + $that->assertArrayHasKey('line', $context); + $that->assertEquals($context['line'], 12); + $that->assertArrayHasKey('type', $context); + $that->assertEquals($context['type'], ErrorHandler::TYPE_DEPRECATION); + $that->assertArrayHasKey('stack', $context); + $that->assertInternalType('array', $context['stack']); + }; + + $logger + ->expects($this->once()) + ->method('warn') + ->will($this->returnCallback($warnArgCheck)) + ; $handler = ErrorHandler::register(E_USER_DEPRECATED); $handler->setLogger($logger); From a7cd5f54ef03aa35354ee3cbbc0875469f67cb7d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 11:27:06 +0100 Subject: [PATCH 077/175] fixed CS --- src/Symfony/Bridge/Twig/Extension/FormExtension.php | 1 - .../FrameworkBundle/Resources/views/Form/attributes.html.php | 1 - .../Resources/views/Form/form_widget.html.php | 1 - .../Bundle/FrameworkBundle/Templating/Helper/FormHelper.php | 1 - src/Symfony/Component/CssSelector/Node/FunctionNode.php | 2 -- src/Symfony/Component/Form/Form.php | 5 ----- src/Symfony/Component/HttpFoundation/RequestMatcher.php | 1 - .../HttpFoundation/SessionStorage/PdoSessionStorage.php | 1 + .../Component/Security/Http/Firewall/ContextListener.php | 1 + .../Symfony/Tests/Bridge/Doctrine/Logger/DbalLoggerTest.php | 1 - .../Tests/Component/HttpFoundation/RequestMatcherTest.php | 1 - 11 files changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index 995d823d16..c4d92eb44f 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -212,7 +212,6 @@ class FormExtension extends \Twig_Extension { $mainTemplate = in_array($section, array('widget', 'row')); if ($mainTemplate && $view->isRendered()) { - return ''; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php index 2b3c84d066..c81bd67e70 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/attributes.html.php @@ -5,4 +5,3 @@ name="escape($full_name) ?>" maxlength="escape($max_length) ?>" pattern="escape($pattern) ?>" $v) { printf('%s="%s" ', $view->escape($k), $view->escape($v)); } ?> - diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget.html.php index 77fa483c3f..e07e637b3f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_widget.html.php @@ -2,4 +2,3 @@ renderBlock('field_rows') ?> rest($form) ?>
- diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index 5fac49f519..24dca9867f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -193,7 +193,6 @@ class FormHelper extends Helper { $mainTemplate = in_array($section, array('row', 'widget')); if ($mainTemplate && $view->isRendered()) { - return ''; } diff --git a/src/Symfony/Component/CssSelector/Node/FunctionNode.php b/src/Symfony/Component/CssSelector/Node/FunctionNode.php index b392b27d07..d645c20aa1 100644 --- a/src/Symfony/Component/CssSelector/Node/FunctionNode.php +++ b/src/Symfony/Component/CssSelector/Node/FunctionNode.php @@ -209,7 +209,6 @@ class FunctionNode implements NodeInterface $xpath->addCondition(sprintf('contains(string(.), %s)', XPathExpr::xpathLiteral($expr))); // FIXME: Currently case insensitive matching doesn't seem to be happening - return $xpath; } @@ -264,7 +263,6 @@ class FunctionNode implements NodeInterface if (false === strpos($s, 'n')) { // Just a b - return array(0, intval((string) $s)); } diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index 3815386a39..4b36063c71 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -266,7 +266,6 @@ class Form implements \IteratorAggregate, FormInterface public function isRequired() { if (null === $this->parent || $this->parent->isRequired()) { - return $this->required; } @@ -287,7 +286,6 @@ class Form implements \IteratorAggregate, FormInterface public function isReadOnly() { if (null === $this->parent || !$this->parent->isReadOnly()) { - return $this->readOnly; } @@ -661,7 +659,6 @@ class Form implements \IteratorAggregate, FormInterface { foreach ($this->children as $child) { if (!$child->isEmpty()) { - return false; } } @@ -687,7 +684,6 @@ class Form implements \IteratorAggregate, FormInterface if (!$this->readOnly) { foreach ($this->children as $child) { if (!$child->isValid()) { - return false; } } @@ -822,7 +818,6 @@ class Form implements \IteratorAggregate, FormInterface public function get($name) { if (isset($this->children[$name])) { - return $this->children[$name]; } diff --git a/src/Symfony/Component/HttpFoundation/RequestMatcher.php b/src/Symfony/Component/HttpFoundation/RequestMatcher.php index 1c159f6a3d..6bc7d23fce 100644 --- a/src/Symfony/Component/HttpFoundation/RequestMatcher.php +++ b/src/Symfony/Component/HttpFoundation/RequestMatcher.php @@ -237,4 +237,3 @@ class RequestMatcher implements RequestMatcherInterface return true; } } - diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php index 8c0bd106ab..0fcaa4c41c 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php @@ -182,6 +182,7 @@ class PdoSessionStorage extends NativeSessionStorage if (count($sessionRows) == 1) { $session = is_resource($sessionRows[0][0]) ? stream_get_contents($sessionRows[0][0]) : $sessionRows[0][0]; + return base64_decode($session); } diff --git a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php index 6f267cfd92..0bf5cff135 100644 --- a/src/Symfony/Component/Security/Http/Firewall/ContextListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/ContextListener.php @@ -66,6 +66,7 @@ class ContextListener implements ListenerInterface if (null === $session || null === $token = $session->get('_security_'.$this->contextKey)) { $this->context->setToken(null); + return; } diff --git a/tests/Symfony/Tests/Bridge/Doctrine/Logger/DbalLoggerTest.php b/tests/Symfony/Tests/Bridge/Doctrine/Logger/DbalLoggerTest.php index 0359bc7eca..7b6037830a 100644 --- a/tests/Symfony/Tests/Bridge/Doctrine/Logger/DbalLoggerTest.php +++ b/tests/Symfony/Tests/Bridge/Doctrine/Logger/DbalLoggerTest.php @@ -11,7 +11,6 @@ namespace Symfony\Tests\Bridge\Doctrine\Logger; - class DbalLoggerTest extends \PHPUnit_Framework_TestCase { public function testLogNonUtf8() diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php index db2405c679..43b42441a4 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestMatcherTest.php @@ -199,4 +199,3 @@ class RequestMatcherTest extends \PHPUnit_Framework_TestCase $this->assertFalse($matcher->matches($request)); } } - From 7f3be5c49d11ddc226c070b2507a4302ed544237 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 11:40:22 +0100 Subject: [PATCH 078/175] fixed CS --- .../Tests/Form/DoctrineOrmTypeGuesserTest.php | 2 +- .../Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php | 1 - .../Config/Definition/Builder/EnumNodeDefinition.php | 4 ++-- .../Component/Console/Tests/ApplicationTest.php | 1 - .../Console/Tests/Formatter/OutputFormatterTest.php | 1 - src/Symfony/Component/Filesystem/Filesystem.php | 6 +++--- .../DataTransformer/DateTimeToRfc3339Transformer.php | 1 - .../Component/Form/Extension/Core/Type/FileType.php | 2 +- src/Symfony/Component/Form/Guess/Guess.php | 2 +- .../Core/DataTransformer/DateTimeTestCase.php | 1 - .../Validator/ViolationMapper/ViolationMapperTest.php | 2 -- .../Storage/Handler/MongoDbSessionHandlerTest.php | 3 +-- .../Storage/Handler/NativeFileSessionHandlerTest.php | 1 + .../Tests/Profiler/MongoDbProfilerStorageTest.php | 3 +-- .../Component/Locale/Resources/data/build-data.php | 11 +++++++---- .../Component/Process/Tests/AbstractProcessTest.php | 3 +-- .../Routing/Tests/Generator/UrlGeneratorTest.php | 2 +- .../DefaultAuthenticationSuccessHandler.php | 1 - src/Symfony/Component/Validator/Constraints/Regex.php | 4 ++-- .../Tests/Constraints/RegexValidatorTest.php | 3 +-- 20 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php index cb69d8b6ae..02312de64b 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php @@ -86,4 +86,4 @@ class DoctrineOrmTypeGuesserTest extends \PHPUnit_Framework_TestCase return new DoctrineOrmTypeGuesser($registry); } -} \ No newline at end of file +} diff --git a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php index ffe0a37b99..c4ca0eecdf 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php @@ -11,7 +11,6 @@ namespace Symfony\Bridge\Doctrine\Tests\Logger; - class DbalLoggerTest extends \PHPUnit_Framework_TestCase { /** diff --git a/src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php index 1db01def30..2216c47f27 100755 --- a/src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php @@ -23,7 +23,7 @@ class EnumNodeDefinition extends ScalarNodeDefinition } $this->values = $values; - + return $this; } @@ -40,4 +40,4 @@ class EnumNodeDefinition extends ScalarNodeDefinition return new EnumNode($this->name, $this->parent, $this->values); } -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 5ae642f33a..7a0a4895cb 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -239,7 +239,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $this->assertRegExp('/Did you mean this/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with one alternative'); } - $application->add(new \Foo1Command()); $application->add(new \Foo2Command()); diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index 5f3b809ce9..33187a7d26 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ - namespace Symfony\Component\Console\Tests\Formatter; use Symfony\Component\Console\Formatter\OutputFormatter; diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 23c58721fe..cb03996d32 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -360,7 +360,7 @@ class Filesystem if ($copyOnWindows) { if (is_link($file) || is_file($file)) { $this->copy($file, $target, isset($options['override']) ? $options['override'] : false); - } else if (is_dir($file)) { + } elseif (is_dir($file)) { $this->mkdir($target); } else { throw new IOException(sprintf('Unable to guess "%s" file type.', $file)); @@ -368,9 +368,9 @@ class Filesystem } else { if (is_link($file)) { $this->symlink($file, $target); - } else if (is_dir($file)) { + } elseif (is_dir($file)) { $this->mkdir($target); - } else if (is_file($file)) { + } elseif (is_file($file)) { $this->copy($file, $target, isset($options['override']) ? $options['override'] : false); } else { throw new IOException(sprintf('Unable to guess "%s" file type.', $file)); diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php index 4062759913..7131ff6519 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php @@ -53,7 +53,6 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer return null; } - $dateTime = new \DateTime($rfc3339); if ($this->outputTimezone !== $this->inputTimezone) { diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php index 675eff313f..58368c7c3d 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FileType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FileType.php @@ -46,7 +46,7 @@ class FileType extends AbstractType { $resolver->setDefaults(array( 'compound' => false, - 'data_class' => 'Symfony\Component\HttpFoundation\File\File' + 'data_class' => 'Symfony\Component\HttpFoundation\File\File' )); } diff --git a/src/Symfony/Component/Form/Guess/Guess.php b/src/Symfony/Component/Form/Guess/Guess.php index 84407925a7..f24407dd73 100644 --- a/src/Symfony/Component/Form/Guess/Guess.php +++ b/src/Symfony/Component/Form/Guess/Guess.php @@ -90,7 +90,7 @@ abstract class Guess */ public function __construct($confidence) { - if (self::VERY_HIGH_CONFIDENCE !== $confidence && self::HIGH_CONFIDENCE !== $confidence && + if (self::VERY_HIGH_CONFIDENCE !== $confidence && self::HIGH_CONFIDENCE !== $confidence && self::MEDIUM_CONFIDENCE !== $confidence && self::LOW_CONFIDENCE !== $confidence) { throw new \InvalidArgumentException('The confidence should be one of the constants defined in Guess.'); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php index 9683aa1e20..e9596b3efb 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeTestCase.php @@ -18,4 +18,3 @@ abstract class DateTimeTestCase extends LocalizedTestCase self::assertEquals($expected->format('c'), $actual->format('c')); } } - diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php index b3d9608cc3..e192f07108 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php @@ -227,7 +227,6 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase { // The mapping must be deterministic! If a child has the property path "[street]", // "data[street]" should be mapped, but "data.street" should not! - return array( // mapping target, child name, its property path, grand child name, its property path, violation path array(self::LEVEL_0, 'address', 'address', 'street', 'street', ''), @@ -1260,7 +1259,6 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase // 1) the error actually maps to an existing child and // 2) the property path of that child (relative to the form providing // the mapping) matches the left side of the mapping - return array( // mapping target, map from, map to, child name, its property path, grand child name, its property path, violation path array(self::LEVEL_1, 'foo', 'address', 'foo', 'foo', 'address', 'address', 'street', 'street', 'children[foo].children[street].data'), diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index fb4811dfc5..d2232f1814 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -155,7 +155,6 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase array('justOne' => true) ); - $this->storage->destroy('foo'); } @@ -183,7 +182,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase $collection->expects($this->once()) ->method('remove') - ->will($this->returnCallback(function($citeria) use($that) { + ->will($this->returnCallback(function($citeria) use ($that) { $that->assertInstanceOf('MongoTimestamp', $citeria[$that->options['time_field']]['$lt']); $that->assertGreaterThanOrEqual(time() - -1, $citeria[$that->options['time_field']]['$lt']->sec); })); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php index 9f58f2d583..de2c4939f0 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/NativeFileSessionHandlerTest.php @@ -54,6 +54,7 @@ class NativeFileSessionHandlerTest extends \PHPUnit_Framework_TestCase public function savePathDataProvider() { $base = sys_get_temp_dir(); + return array( array("$base/foo", "$base/foo", "$base/foo"), array("5;$base/foo", "5;$base/foo", "$base/foo"), diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php index b2d148d4c3..b63b84c0fb 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php @@ -40,7 +40,7 @@ class MongoDbProfilerStorageTestDataCollector extends DataCollector public function collect(Request $request, Response $response, \Exception $exception = null) { } - + public function getName() { return 'test_data_collector'; @@ -126,4 +126,3 @@ class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest } } } - diff --git a/src/Symfony/Component/Locale/Resources/data/build-data.php b/src/Symfony/Component/Locale/Resources/data/build-data.php index 8f27830a43..0382cb8d35 100644 --- a/src/Symfony/Component/Locale/Resources/data/build-data.php +++ b/src/Symfony/Component/Locale/Resources/data/build-data.php @@ -125,7 +125,8 @@ function get_data($index, $dataDir, $locale = 'en', $constraint = null) return $data; } -function icu_version() { +function icu_version() +{ exec('icu-config --version', $output, $result); if ($result !== 0 || !isset($output[0])) { @@ -135,13 +136,15 @@ function icu_version() { return $output[0]; } -function normalize_icu_version($version) { +function normalize_icu_version($version) +{ preg_match('/^(?P[0-9]\.[0-9]|[0-9]{2,})/', $version, $matches); return $matches['version']; } -function download_icu_data($version) { +function download_icu_data($version) +{ $icu = parse_ini_file(__DIR__.'/icu.ini'); if (!isset($icu[$version])) { @@ -624,4 +627,4 @@ create_stub_datafile($defaultLocale, $stubRegionDir, $countries); // Clean up clear_directory($currDir); -rmdir($currDir); \ No newline at end of file +rmdir($currDir); diff --git a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php index d83c1f3419..d8df0a5516 100644 --- a/src/Symfony/Component/Process/Tests/AbstractProcessTest.php +++ b/src/Symfony/Component/Process/Tests/AbstractProcessTest.php @@ -16,7 +16,7 @@ namespace Symfony\Component\Process\Tests; */ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase { - protected abstract function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array()); + abstract protected function getProcess($commandline, $cwd = null, array $env = null, $stdin = null, $timeout = 60, array $options = array()); /** * @expectedException \InvalidArgumentException @@ -233,7 +233,6 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Windows does not support POSIX signals'); } - $process = $this->getProcess('php -r "while (true) {}"'); $process->start(); $process->stop(); diff --git a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php index 935b14eceb..d08da04311 100644 --- a/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php +++ b/src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php @@ -214,7 +214,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $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')); diff --git a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php index dc7cbe549b..dd7a7d5547 100644 --- a/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php +++ b/src/Symfony/Component/Security/Http/Authentication/DefaultAuthenticationSuccessHandler.php @@ -58,7 +58,6 @@ class DefaultAuthenticationSuccessHandler implements AuthenticationSuccessHandle return $this->httpUtils->createRedirectResponse($request, $this->determineTargetUrl($request)); } - /** * Get the provider key. * diff --git a/src/Symfony/Component/Validator/Constraints/Regex.php b/src/Symfony/Component/Validator/Constraints/Regex.php index f26186cb13..fb5dcc1a73 100644 --- a/src/Symfony/Component/Validator/Constraints/Regex.php +++ b/src/Symfony/Component/Validator/Constraints/Regex.php @@ -62,7 +62,7 @@ class Regex extends Constraint * Convert the htmlPattern to a suitable format for HTML5 pattern. * Example: /^[a-z]+$/ would be converted to [a-z]+ * However, if options are specified, it cannot be converted - * + * * Pattern is also ignored if match=false since the pattern should * then be reversed before application. * @@ -78,7 +78,7 @@ class Regex extends Constraint if (!$this->match) { return null; } - + if (preg_match('/^(.)(\^?)(.*?)(\$?)\1$/', $this->pattern, $matches)) { $delimiter = $matches[1]; $start = empty($matches[2]) ? '.*' : ''; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index 4ab7278973..b136bbc7e3 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -162,7 +162,7 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase 'pattern' => '/[a-z]+/', )); $this->assertEquals('.*[a-z]+.*', $constraint->getHtmlPattern()); - + // Dropped because of match=false $constraint = new Regex(array( 'pattern' => '/[a-z]+/', @@ -170,5 +170,4 @@ class RegexValidatorTest extends \PHPUnit_Framework_TestCase )); $this->assertNull($constraint->getHtmlPattern()); } - } From fdb11be2429d6e6ae4922c5a655542700431f719 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 11 Dec 2012 11:49:22 +0100 Subject: [PATCH 079/175] fixed CS --- .../Command/ContainerDebugCommand.php | 15 ++++++------- .../views/Collector/logger.html.twig | 21 +++---------------- .../ClassLoader/UniversalClassLoader.php | 2 +- .../Console/Tests/ApplicationTest.php | 6 +++--- .../DependencyInjection/ContainerBuilder.php | 6 +++--- .../Finder/Adapter/AbstractFindAdapter.php | 1 + .../Finder/Adapter/BsdFindAdapter.php | 1 - .../Finder/Adapter/GnuFindAdapter.php | 1 - .../Finder/Exception/ExceptionInterface.php | 2 +- .../Finder/Expression/Expression.php | 2 +- .../Finder/Expression/ValueInterface.php | 8 +++---- src/Symfony/Component/Finder/Finder.php | 2 +- .../Component/Finder/Tests/FinderTest.php | 1 - .../Tests/Iterator/PathFilterIteratorTest.php | 1 - .../Extension/Core/Type/FormTypeTest.php | 2 ++ .../Constraints/FormValidatorTest.php | 2 -- .../Tests/File/UploadedFileTest.php | 1 - .../Handler/MongoDbSessionHandlerTest.php | 2 +- .../Component/HttpKernel/HttpCache/Store.php | 1 + src/Symfony/Component/HttpKernel/Kernel.php | 2 +- .../Profiler/MongoDbProfilerStorage.php | 10 ++++----- .../Component/HttpKernel/Profiler/Profile.php | 8 +++---- .../Debug/TraceableEventDispatcherTest.php | 2 +- .../OptionsResolver/Tests/OptionsTest.php | 1 + .../Process/Tests/AbstractProcessTest.php | 8 +++---- .../Routing/Generator/UrlGenerator.php | 2 +- .../Routing/Matcher/ApacheUrlMatcher.php | 1 + .../Component/Routing/RouteCollection.php | 2 +- .../Component/Routing/RouteCompiler.php | 2 +- .../Core/Util/SecureRandomInterface.php | 1 - src/Symfony/Component/Stopwatch/Stopwatch.php | 1 - .../Templating/Loader/FilesystemLoader.php | 2 +- .../Component/Templating/PhpEngine.php | 2 +- .../Validator/Mapping/ClassMetadata.php | 2 +- 34 files changed, 53 insertions(+), 70 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 08922a9ac5..2681fc1a96 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -89,6 +89,7 @@ EOF } $this->outputTags($output, $input->getOption('show-private')); + return; } @@ -146,8 +147,8 @@ EOF if (null !== $showTagAttributes) { $tags = $definition->getTag($showTagAttributes); - foreach($tags as $tag) { - foreach($tag as $key => $value) { + foreach ($tags as $tag) { + foreach ($tag as $key => $value) { if (!isset($maxTags[$key])) { $maxTags[$key] = strlen($key); } @@ -173,7 +174,7 @@ EOF $format1 .= '%-'.($maxScope + 19).'s %s'; $tags = array(); - foreach($maxTags as $tagName => $length) { + foreach ($maxTags as $tagName => $length) { $tags[] = ''.$tagName.''; } $output->writeln(vsprintf($format1, $this->buildArgumentsArray('Service Id', 'Scope', 'Class Name', $tags))); @@ -184,9 +185,9 @@ EOF if ($definition instanceof Definition) { $lines = array(); if (null !== $showTagAttributes) { - foreach($definition->getTag($showTagAttributes) as $key => $tag) { + foreach ($definition->getTag($showTagAttributes) as $key => $tag) { $tagValues = array(); - foreach(array_keys($maxTags) as $tagName) { + foreach (array_keys($maxTags) as $tagName) { $tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : ""; } if (0 === $key) { @@ -199,7 +200,7 @@ EOF $lines[] = $this->buildArgumentsArray($serviceId, $definition->getScope(), $definition->getClass()); } - foreach($lines as $arguments) { + foreach ($lines as $arguments) { $output->writeln(vsprintf($format, $arguments)); } } elseif ($definition instanceof Alias) { @@ -216,7 +217,7 @@ EOF protected function buildArgumentsArray($serviceId, $scope, $className, array $tagAttributes = array()) { $arguments = array($serviceId); - foreach($tagAttributes as $tagAttribute) { + foreach ($tagAttributes as $tagAttribute) { $arguments[] = $tagAttribute; } $arguments[] = $scope; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig index 7a8fa53b5f..8ab08f9170 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig @@ -59,19 +59,8 @@