From 8566dc18fc8ca3cc0b5332f2ea4b25420df9e56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vasseur?= Date: Tue, 29 Dec 2015 20:19:28 +0100 Subject: [PATCH 1/8] Remove normalizer cache in Serializer class --- .../Component/Serializer/Serializer.php | 2 - .../Serializer/Tests/SerializerTest.php | 44 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index b618ca06c0..1819def5f6 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -237,7 +237,6 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz foreach ($this->normalizers as $normalizer) { if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($object, $format)) { - $this->normalizerCache[$class][$format] = $normalizer; return $normalizer->normalize($object, $format, $context); } @@ -272,7 +271,6 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz foreach ($this->normalizers as $normalizer) { if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $class, $format)) { - $this->denormalizerCache[$class][$format] = $normalizer; return $normalizer->denormalize($data, $class, $format, $context); } diff --git a/src/Symfony/Component/Serializer/Tests/SerializerTest.php b/src/Symfony/Component/Serializer/Tests/SerializerTest.php index c2a231b11e..7fd607b626 100644 --- a/src/Symfony/Component/Serializer/Tests/SerializerTest.php +++ b/src/Symfony/Component/Serializer/Tests/SerializerTest.php @@ -73,6 +73,50 @@ class SerializerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->serializer->denormalize(json_encode($data), 'stdClass', 'json')); } + public function testNormalizeWithSupportOnData() + { + $normalizer1 = $this->getMock('Symfony\Component\Serializer\Normalizer\NormalizerInterface'); + $normalizer1->method('supportsNormalization') + ->willReturnCallback(function ($data, $format) { + return isset($data->test); + }); + $normalizer1->method('normalize')->willReturn('test1'); + + $normalizer2 = $this->getMock('Symfony\Component\Serializer\Normalizer\NormalizerInterface'); + $normalizer2->method('supportsNormalization') + ->willReturn(true); + $normalizer2->method('normalize')->willReturn('test2'); + + $serializer = new Serializer(array($normalizer1, $normalizer2)); + + $data = new \stdClass(); + $data->test = true; + $this->assertEquals('test1', $serializer->normalize($data)); + + $this->assertEquals('test2', $serializer->normalize(new \stdClass())); + } + + public function testDenormalizeWithSupportOnData() + { + $denormalizer1 = $this->getMock('Symfony\Component\Serializer\Normalizer\DenormalizerInterface'); + $denormalizer1->method('supportsDenormalization') + ->willReturnCallback(function ($data, $type, $format) { + return isset($data['test1']); + }); + $denormalizer1->method('denormalize')->willReturn('test1'); + + $denormalizer2 = $this->getMock('Symfony\Component\Serializer\Normalizer\DenormalizerInterface'); + $denormalizer2->method('supportsDenormalization') + ->willReturn(true); + $denormalizer2->method('denormalize')->willReturn('test2'); + + $serializer = new Serializer(array($denormalizer1, $denormalizer2)); + + $this->assertEquals('test1', $serializer->denormalize(array('test1' => true), 'test')); + + $this->assertEquals('test2', $serializer->denormalize(array(), 'test')); + } + public function testSerialize() { $this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder())); From 2040139db6c6108aed91fbafa606619a3bcb9ba4 Mon Sep 17 00:00:00 2001 From: Tim van Densen Date: Thu, 7 Jan 2016 10:55:58 +0100 Subject: [PATCH 2/8] Added sort order SORT_STRING for params in UriSigner --- src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php | 1 + src/Symfony/Component/HttpKernel/UriSigner.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php b/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php index b66014d849..37a1d2fe93 100644 --- a/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php @@ -33,6 +33,7 @@ class UriSignerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($signer->check($signer->sign('http://example.com/foo'))); $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar'))); + $this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer'))); $this->assertTrue($signer->sign('http://example.com/foo?foo=bar&bar=foo') === $signer->sign('http://example.com/foo?bar=foo&foo=bar')); } diff --git a/src/Symfony/Component/HttpKernel/UriSigner.php b/src/Symfony/Component/HttpKernel/UriSigner.php index d77d27430d..5a96ef2228 100644 --- a/src/Symfony/Component/HttpKernel/UriSigner.php +++ b/src/Symfony/Component/HttpKernel/UriSigner.php @@ -91,8 +91,8 @@ class UriSigner private function buildUrl(array $url, array $params = array()) { - ksort($params); - $url['query'] = http_build_query($params); + ksort($params, SORT_STRING); + $url['query'] = http_build_query($params, '', '&'); $scheme = isset($url['scheme']) ? $url['scheme'].'://' : ''; $host = isset($url['host']) ? $url['host'] : ''; From e38fa135ab691e1d2d9f8d6a02a4275c3328902f Mon Sep 17 00:00:00 2001 From: Diego Saint Esteben Date: Thu, 7 Jan 2016 14:13:41 -0300 Subject: [PATCH 3/8] Use proper class to fetch $versionStrategy property --- src/Symfony/Bridge/Twig/Extension/AssetExtension.php | 9 +++------ .../FrameworkBundle/Templating/Helper/AssetsHelper.php | 3 ++- .../Tests/Templating/Helper/AssetsHelperTest.php | 8 ++++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php index d90d13f6fd..a72f4503dd 100644 --- a/src/Symfony/Bridge/Twig/Extension/AssetExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/AssetExtension.php @@ -98,19 +98,16 @@ class AssetExtension extends \Twig_Extension { if ($version) { $package = $this->packages->getPackage($packageName); - $class = new \ReflectionClass($package); - while ('Symfony\Component\Asset\Package' !== $class->getName()) { - $class = $class->getParentClass(); - } - - $v = $class->getProperty('versionStrategy'); + $v = new \ReflectionProperty('Symfony\Component\Asset\Package', 'versionStrategy'); $v->setAccessible(true); + $currentVersionStrategy = $v->getValue($package); if (property_exists($currentVersionStrategy, 'format')) { $f = new \ReflectionProperty($currentVersionStrategy, 'format'); $f->setAccessible(true); + $format = $f->getValue($currentVersionStrategy); $v->setValue($package, new StaticVersionStrategy($version, $format)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/AssetsHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/AssetsHelper.php index 8379c6830e..6acc045393 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/AssetsHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/AssetsHelper.php @@ -95,13 +95,14 @@ class AssetsHelper extends Helper if ($version) { $package = $this->packages->getPackage($packageName); - $v = new \ReflectionProperty($package, 'versionStrategy'); + $v = new \ReflectionProperty('Symfony\Component\Asset\Package', 'versionStrategy'); $v->setAccessible(true); $currentVersionStrategy = $v->getValue($package); $f = new \ReflectionProperty($currentVersionStrategy, 'format'); $f->setAccessible(true); + $format = $f->getValue($currentVersionStrategy); $v->setValue($package, new StaticVersionStrategy($version, $format)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/AssetsHelperTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/AssetsHelperTest.php index 71528de92e..9460799684 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/AssetsHelperTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/AssetsHelperTest.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper; use Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper; use Symfony\Component\Asset\Package; use Symfony\Component\Asset\Packages; +use Symfony\Component\Asset\PathPackage; use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy; class AssetsHelperTest extends \PHPUnit_Framework_TestCase @@ -23,11 +24,14 @@ class AssetsHelperTest extends \PHPUnit_Framework_TestCase */ public function testLegacyGetUrl() { - $package = new Package(new StaticVersionStrategy('22', '%s?version=%s')); - $packages = new Packages($package); + $versionStrategy = new StaticVersionStrategy('22', '%s?version=%s'); + $package = new Package($versionStrategy); + $imagePackage = new PathPackage('images', $versionStrategy); + $packages = new Packages($package, array('images' => $imagePackage)); $helper = new AssetsHelper($packages); $this->assertEquals('me.png?version=42', $helper->getUrl('me.png', null, '42')); + $this->assertEquals('/images/me.png?version=42', $helper->getUrl('me.png', 'images', '42')); } /** From de7b4d73c61f7ee2423773263384e0e43e1f5ad6 Mon Sep 17 00:00:00 2001 From: Pavel Batanov Date: Sat, 9 Jan 2016 09:10:09 +0300 Subject: [PATCH 4/8] Fix #17306 Paths with % in it are note allowed (like urlencoded) --- .../DependencyInjection/FrameworkExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index de97b1f44c..4248623d3d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -562,17 +562,17 @@ class FrameworkExtension extends Extension $dirs[] = dirname($r->getFileName()).'/../../Resources/translations'; } } - $overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations'; + $rootDir = $container->getParameter('kernel.root_dir'); foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { $reflection = new \ReflectionClass($class); if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) { $dirs[] = $dir; } - if (is_dir($dir = sprintf($overridePath, $bundle))) { + if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) { $dirs[] = $dir; } } - if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) { + if (is_dir($dir = $rootDir.'/Resources/translations')) { $dirs[] = $dir; } From 0f8da347f87d40e7b61e1959e5e044445caf0559 Mon Sep 17 00:00:00 2001 From: mantulo Date: Sat, 9 Jan 2016 22:07:10 +0600 Subject: [PATCH 5/8] Update AbstractChoiceListTest.php fixed phpdoc namespace --- .../Form/Tests/ChoiceList/AbstractChoiceListTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/AbstractChoiceListTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/AbstractChoiceListTest.php index ca244ebd69..958bb66d50 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/AbstractChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/AbstractChoiceListTest.php @@ -17,7 +17,7 @@ namespace Symfony\Component\Form\Tests\ChoiceList; abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase { /** - * @var \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface + * @var \Symfony\Component\Form\ChoiceList\ChoiceListInterface */ protected $list; @@ -210,7 +210,7 @@ abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase } /** - * @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface + * @return \Symfony\Component\Form\ChoiceList\ChoiceListInterface */ abstract protected function createChoiceList(); From 6ebd1792d813c2d5ae2133d8bb4c166fc52f51c6 Mon Sep 17 00:00:00 2001 From: Disparity Date: Sun, 20 Dec 2015 12:25:54 +0600 Subject: [PATCH 6/8] Added support \IteratorAggregate for UniqueEntityValidator Expand the list of supported types of results returned from the repositories. Added processing of type \IteratorAggregate (and as a consequence doctrine Collection) --- .../Constraints/UniqueEntityValidatorTest.php | 39 +++++++++++++++++++ .../Constraints/UniqueEntityValidator.php | 4 ++ 2 files changed, 43 insertions(+) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index 9c2b510d34..f5c37e6787 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectRepository; @@ -330,6 +331,44 @@ class UniqueEntityValidatorTest extends AbstractConstraintValidatorTest $this->assertNoViolation(); } + /** + * @dataProvider resultTypesProvider + */ + public function testValidateResultTypes($entity1, $result) + { + $constraint = new UniqueEntity(array( + 'message' => 'myMessage', + 'fields' => array('name'), + 'em' => self::EM_NAME, + 'repositoryMethod' => 'findByCustom', + )); + + $repository = $this->createRepositoryMock(); + $repository->expects($this->once()) + ->method('findByCustom') + ->will($this->returnValue($result)) + ; + $this->em = $this->createEntityManagerMock($repository); + $this->registry = $this->createRegistryMock($this->em); + $this->validator = $this->createValidator(); + $this->validator->initialize($this->context); + + $this->validator->validate($entity1, $constraint); + + $this->assertNoViolation(); + } + + public function resultTypesProvider() + { + $entity = new SingleIntIdEntity(1, 'foo'); + + return array( + array($entity, array($entity)), + array($entity, new \ArrayIterator(array($entity))), + array($entity, new ArrayCollection(array($entity))), + ); + } + public function testAssociatedEntity() { $constraint = new UniqueEntity(array( diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index 84692aba06..2ee3f1da2e 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -109,6 +109,10 @@ class UniqueEntityValidator extends ConstraintValidator $repository = $em->getRepository(get_class($entity)); $result = $repository->{$constraint->repositoryMethod}($criteria); + if ($result instanceof \IteratorAggregate) { + $result = $result->getIterator(); + } + /* If the result is a MongoCursor, it must be advanced to the first * element. Rewinding should have no ill effect if $result is another * iterator implementation. From 81f81812a5127d1f3aec4f458057a474e4ccb926 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Wed, 6 Jan 2016 14:34:50 +0100 Subject: [PATCH 7/8] [2.3] Static Code Analysis for Components --- src/Symfony/Component/BrowserKit/Client.php | 2 +- .../Component/Console/Helper/TableHelper.php | 2 +- .../Component/Console/Output/ConsoleOutput.php | 2 +- .../Component/DependencyInjection/Container.php | 2 +- .../DependencyInjection/Extension/Extension.php | 4 +--- .../DependencyInjection/Loader/XmlFileLoader.php | 3 ++- .../DependencyInjection/Loader/YamlFileLoader.php | 3 ++- src/Symfony/Component/Filesystem/Filesystem.php | 2 +- src/Symfony/Component/HttpFoundation/HeaderBag.php | 8 ++++---- .../Component/HttpFoundation/ResponseHeaderBag.php | 4 ++-- src/Symfony/Component/HttpKernel/Bundle/Bundle.php | 2 +- .../Component/HttpKernel/HttpCache/Store.php | 14 +++++--------- .../HttpKernel/Profiler/PdoProfilerStorage.php | 3 +-- src/Symfony/Component/HttpKernel/UriSigner.php | 2 +- .../Component/PropertyAccess/PropertyAccessor.php | 4 ++-- .../Http/Firewall/DigestAuthenticationListener.php | 6 ++---- .../Translation/Dumper/IcuResFileDumper.php | 2 +- .../Validator/Mapping/Loader/XmlFileLoader.php | 2 +- 18 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 1370f1c838..22c889ecd7 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -136,7 +136,7 @@ abstract class Client */ public function getServerParameter($key, $default = '') { - return (isset($this->server[$key])) ? $this->server[$key] : $default; + return isset($this->server[$key]) ? $this->server[$key] : $default; } /** diff --git a/src/Symfony/Component/Console/Helper/TableHelper.php b/src/Symfony/Component/Console/Helper/TableHelper.php index 00814ecdd9..16aede1248 100644 --- a/src/Symfony/Component/Console/Helper/TableHelper.php +++ b/src/Symfony/Component/Console/Helper/TableHelper.php @@ -111,7 +111,7 @@ class TableHelper extends Helper default: throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout)); - }; + } return $this; } diff --git a/src/Symfony/Component/Console/Output/ConsoleOutput.php b/src/Symfony/Component/Console/Output/ConsoleOutput.php index 8e1f360141..f666c793e2 100644 --- a/src/Symfony/Component/Console/Output/ConsoleOutput.php +++ b/src/Symfony/Component/Console/Output/ConsoleOutput.php @@ -131,7 +131,7 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface PHP_OS, ); - return false !== stristr(implode(';', $checks), 'OS400'); + return false !== stripos(implode(';', $checks), 'OS400'); } /** diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index fb0e31911b..75de9c4fde 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -536,6 +536,6 @@ class Container implements IntrospectableContainerInterface */ public static function underscore($id) { - return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.'))); + return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id))); } } diff --git a/src/Symfony/Component/DependencyInjection/Extension/Extension.php b/src/Symfony/Component/DependencyInjection/Extension/Extension.php index f8e058bafd..20ea1002cb 100644 --- a/src/Symfony/Component/DependencyInjection/Extension/Extension.php +++ b/src/Symfony/Component/DependencyInjection/Extension/Extension.php @@ -91,9 +91,7 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn $container->addResource(new FileResource($r->getFileName())); if (!method_exists($class, '__construct')) { - $configuration = new $class(); - - return $configuration; + return new $class(); } } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 95470ce7f7..b268cb9904 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -91,8 +91,9 @@ class XmlFileLoader extends FileLoader return; } + $defaultDirectory = dirname($file); foreach ($imports as $import) { - $this->setCurrentDir(dirname($file)); + $this->setCurrentDir($defaultDirectory); $this->import((string) $import['resource'], null, (bool) $import->getAttributeAsPhp('ignore-errors'), $file); } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 440b46fa80..91adf2b78d 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -94,12 +94,13 @@ class YamlFileLoader extends FileLoader throw new InvalidArgumentException(sprintf('The "imports" key should contain an array in %s. Check your YAML syntax.', $file)); } + $defaultDirectory = dirname($file); foreach ($content['imports'] as $import) { if (!is_array($import)) { throw new InvalidArgumentException(sprintf('The values in the "imports" key should be arrays in %s. Check your YAML syntax.', $file)); } - $this->setCurrentDir(dirname($file)); + $this->setCurrentDir($defaultDirectory); $this->import($import['resource'], null, isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false, $file); } } diff --git a/src/Symfony/Component/Filesystem/Filesystem.php b/src/Symfony/Component/Filesystem/Filesystem.php index 3ff72d28fb..4fe9f3485e 100644 --- a/src/Symfony/Component/Filesystem/Filesystem.php +++ b/src/Symfony/Component/Filesystem/Filesystem.php @@ -431,7 +431,7 @@ class Filesystem return strspn($file, '/\\', 0, 1) || (strlen($file) > 3 && ctype_alpha($file[0]) && substr($file, 1, 1) === ':' - && (strspn($file, '/\\', 2, 1)) + && strspn($file, '/\\', 2, 1) ) || null !== parse_url($file, PHP_URL_SCHEME) ; diff --git a/src/Symfony/Component/HttpFoundation/HeaderBag.php b/src/Symfony/Component/HttpFoundation/HeaderBag.php index bcf143099e..761be9673f 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/HeaderBag.php @@ -113,7 +113,7 @@ class HeaderBag implements \IteratorAggregate, \Countable */ public function get($key, $default = null, $first = true) { - $key = strtr(strtolower($key), '_', '-'); + $key = str_replace('_', '-', strtolower($key)); if (!array_key_exists($key, $this->headers)) { if (null === $default) { @@ -139,7 +139,7 @@ class HeaderBag implements \IteratorAggregate, \Countable */ public function set($key, $values, $replace = true) { - $key = strtr(strtolower($key), '_', '-'); + $key = str_replace('_', '-', strtolower($key)); $values = array_values((array) $values); @@ -163,7 +163,7 @@ class HeaderBag implements \IteratorAggregate, \Countable */ public function has($key) { - return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers); + return array_key_exists(str_replace('_', '-', strtolower($key)), $this->headers); } /** @@ -186,7 +186,7 @@ class HeaderBag implements \IteratorAggregate, \Countable */ public function remove($key) { - $key = strtr(strtolower($key), '_', '-'); + $key = str_replace('_', '-', strtolower($key)); unset($this->headers[$key]); diff --git a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php index a0a3f63080..37635c2e63 100644 --- a/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php @@ -99,7 +99,7 @@ class ResponseHeaderBag extends HeaderBag { parent::set($key, $values, $replace); - $uniqueKey = strtr(strtolower($key), '_', '-'); + $uniqueKey = str_replace('_', '-', strtolower($key)); $this->headerNames[$uniqueKey] = $key; // ensure the cache-control header has sensible defaults @@ -118,7 +118,7 @@ class ResponseHeaderBag extends HeaderBag { parent::remove($key); - $uniqueKey = strtr(strtolower($key), '_', '-'); + $uniqueKey = str_replace('_', '-', strtolower($key)); unset($this->headerNames[$uniqueKey]); if ('cache-control' === $uniqueKey) { diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 8437af995a..9082b3e304 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -181,7 +181,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface foreach ($finder as $file) { $ns = $prefix; if ($relativePath = $file->getRelativePath()) { - $ns .= '\\'.strtr($relativePath, '/', '\\'); + $ns .= '\\'.str_replace('/', '\\', $relativePath); } $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php')); if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) { diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Store.php b/src/Symfony/Component/HttpKernel/HttpCache/Store.php index 41cfa86f53..c37cc459ea 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Store.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Store.php @@ -38,10 +38,8 @@ class Store implements StoreInterface public function __construct($root) { $this->root = $root; - if (!is_dir($this->root)) { - if (false === @mkdir($this->root, 0777, true) && !is_dir($this->root)) { - throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root)); - } + if (!is_dir($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) { + throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root)); } $this->keyCache = new \SplObjectStorage(); $this->locks = array(); @@ -249,10 +247,8 @@ class Store implements StoreInterface } } - if ($modified) { - if (false === $this->save($key, serialize($entries))) { - throw new \RuntimeException('Unable to store the metadata.'); - } + if ($modified && false === $this->save($key, serialize($entries))) { + throw new \RuntimeException('Unable to store the metadata.'); } } @@ -273,7 +269,7 @@ class Store implements StoreInterface } foreach (preg_split('/[\s,]+/', $vary) as $header) { - $key = strtr(strtolower($header), '_', '-'); + $key = str_replace('_', '-', strtolower($header)); $v1 = isset($env1[$key]) ? $env1[$key] : null; $v2 = isset($env2[$key]) ? $env2[$key] : null; if ($v1 !== $v2) { diff --git a/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php b/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php index a545e6b44b..da50cedb15 100644 --- a/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php +++ b/src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php @@ -187,9 +187,8 @@ abstract class PdoProfilerStorage implements ProfilerStorageInterface $stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR); } $stmt->execute(); - $return = $stmt->fetchAll(\PDO::FETCH_ASSOC); - return $return; + return $stmt->fetchAll(\PDO::FETCH_ASSOC); } protected function close($db) diff --git a/src/Symfony/Component/HttpKernel/UriSigner.php b/src/Symfony/Component/HttpKernel/UriSigner.php index d77d27430d..66e0541ae6 100644 --- a/src/Symfony/Component/HttpKernel/UriSigner.php +++ b/src/Symfony/Component/HttpKernel/UriSigner.php @@ -51,7 +51,7 @@ class UriSigner $uri = $this->buildUrl($url, $params); - return $uri.(false === (strpos($uri, '?')) ? '?' : '&').'_hash='.$this->computeHash($uri); + return $uri.(false === strpos($uri, '?') ? '?' : '&').'_hash='.$this->computeHash($uri); } /** diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index 5270df26f3..3b9b49490d 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -442,11 +442,11 @@ class PropertyAccessor implements PropertyAccessorInterface } foreach ($itemToRemove as $item) { - call_user_func(array($object, $access[self::ACCESS_REMOVER]), $item); + $object->{$access[self::ACCESS_REMOVER]}($item); } foreach ($itemsToAdd as $item) { - call_user_func(array($object, $access[self::ACCESS_ADDER]), $item); + $object->{$access[self::ACCESS_ADDER]}($item); } } elseif (!$access[self::ACCESS_HAS_PROPERTY] && property_exists($object, $property)) { // Needed to support \stdClass instances. We need to explicitly diff --git a/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php index 5e1159f733..4e5766756f 100644 --- a/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php @@ -172,10 +172,8 @@ class DigestData throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s" (%s)', $this->header, implode(', ', $keys))); } - if ('auth' === $this->elements['qop']) { - if (!isset($this->elements['nc']) || !isset($this->elements['cnonce'])) { - throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header)); - } + if ('auth' === $this->elements['qop'] && !isset($this->elements['nc'], $this->elements['cnonce'])) { + throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header)); } if ($expectedRealm !== $this->elements['realm']) { diff --git a/src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php b/src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php index 4b42a92ee9..ba63a4c530 100644 --- a/src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/IcuResFileDumper.php @@ -30,8 +30,8 @@ class IcuResFileDumper implements DumperInterface } // save a file for each domain + $file = $messages->getLocale().'.'.$this->getExtension(); foreach ($messages->getDomains() as $domain) { - $file = $messages->getLocale().'.'.$this->getExtension(); $path = $options['path'].'/'.$domain.'/'; if (!is_dir($path) && !@mkdir($path) && !is_dir($path)) { diff --git a/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php b/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php index 1ebb68a49d..6275d1c547 100644 --- a/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php @@ -190,7 +190,7 @@ class XmlFileLoader extends FileLoader */ private function loadClassMetadataFromXml(ClassMetadata $metadata, $classDescription) { - foreach ($classDescription->{'group-sequence-provider'} as $_) { + if (count($classDescription->{'group-sequence-provider'}) > 0) { $metadata->setGroupSequenceProvider(true); } From 12fd48c1929a8730537a16c91ecbe40bc299300d Mon Sep 17 00:00:00 2001 From: Quentin Date: Tue, 12 Jan 2016 12:47:35 +0100 Subject: [PATCH 8/8] Typo fix --- UPGRADE-3.0.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index 4ec8065a98..09b2938edd 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -10,8 +10,8 @@ UPGRADE FROM 2.x to 3.0 | -------- | --- | `registerNamespaces()` | `addPrefixes()` | `registerPrefixes()` | `addPrefixes()` - | `registerNamespaces()` | `addPrefix()` - | `registerPrefixes()` | `addPrefix()` + | `registerNamespace()` | `addPrefix()` + | `registerPrefix()` | `addPrefix()` | `getNamespaces()` | `getPrefixes()` | `getNamespaceFallbacks()` | `getFallbackDirs()` | `getPrefixFallbacks()` | `getFallbackDirs()`