From fe190b6ee96462f9d7cc268733528d81bc3231e4 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Thu, 12 Oct 2017 09:07:31 -0400 Subject: [PATCH 01/22] reject remember-me token if user check fails --- .../Authentication/Provider/RememberMeAuthenticationProvider.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php index d5e4172bb1..1e51f6b8fd 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php @@ -49,6 +49,7 @@ class RememberMeAuthenticationProvider implements AuthenticationProviderInterfac $user = $token->getUser(); $this->userChecker->checkPreAuth($user); + $this->userChecker->checkPostAuth($user); $authenticatedToken = new RememberMeToken($user, $this->providerKey, $this->key); $authenticatedToken->setAttributes($token->getAttributes()); From 7da052f18fcf65444a66bf853f5320c78aea3533 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Fri, 13 Oct 2017 09:35:47 -0700 Subject: [PATCH 02/22] Updated the source text and translation --- .../Component/Form/Resources/translations/validators.sv.xlf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Resources/translations/validators.sv.xlf b/src/Symfony/Component/Form/Resources/translations/validators.sv.xlf index 4e2518b16b..2a5e57ca81 100644 --- a/src/Symfony/Component/Form/Resources/translations/validators.sv.xlf +++ b/src/Symfony/Component/Form/Resources/translations/validators.sv.xlf @@ -11,8 +11,8 @@ Den uppladdade filen var för stor. Försök ladda upp en mindre fil. - The CSRF token is invalid. - CSRF-symbolen är inte giltig. + The CSRF token is invalid. Please try to resubmit the form. + CSRF-elementet är inte giltigt. Försök att skicka formuläret igen. From d2ab0d80199669091c3bd08b5e32ae6de3298f7d Mon Sep 17 00:00:00 2001 From: "hubert.lenoir" Date: Fri, 13 Oct 2017 18:51:13 +0200 Subject: [PATCH 03/22] =?UTF-8?q?[Debug]=C2=A0Fix=20same=20vendor=20detect?= =?UTF-8?q?ion=20in=20class=20loader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Symfony/Component/Debug/DebugClassLoader.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Debug/DebugClassLoader.php b/src/Symfony/Component/Debug/DebugClassLoader.php index 160e945ccb..84c0f663c5 100644 --- a/src/Symfony/Component/Debug/DebugClassLoader.php +++ b/src/Symfony/Component/Debug/DebugClassLoader.php @@ -203,18 +203,11 @@ class DebugClassLoader } elseif (preg_match('#\n \* @deprecated (.*?)\r?\n \*(?: @|/$)#s', $refl->getDocComment(), $notice)) { self::$deprecated[$name] = preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]); } else { - if (2 > $len = 1 + (strpos($name, '\\', 1 + strpos($name, '\\')) ?: strpos($name, '_'))) { + if (2 > $len = 1 + (strpos($name, '\\') ?: strpos($name, '_'))) { $len = 0; $ns = ''; } else { - switch ($ns = substr($name, 0, $len)) { - case 'Symfony\Bridge\\': - case 'Symfony\Bundle\\': - case 'Symfony\Component\\': - $ns = 'Symfony\\'; - $len = strlen($ns); - break; - } + $ns = substr($name, 0, $len); } $parent = get_parent_class($class); From 03be003018a3d2734528e89ffbca6eb14e8f8f03 Mon Sep 17 00:00:00 2001 From: Christian Sciberras Date: Sat, 14 Oct 2017 03:33:35 +0200 Subject: [PATCH 04/22] Fixed mistake in exception expectation --- .../DependencyInjection/ConfigurationTest.php | 9 ++++----- .../Component/Form/Tests/ButtonBuilderTest.php | 11 +++++++---- .../DateIntervalToArrayTransformerTest.php | 14 ++++++++++++-- .../Process/Tests/ProcessFailedExceptionTest.php | 10 ++++++---- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 0d2578db04..03dfee5f99 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -165,12 +165,11 @@ class ConfigurationTest extends TestCase */ public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage) { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}( - InvalidConfigurationException::class, - $expectedMessage - ); - if (method_exists($this, 'expectExceptionMessage')) { + if (method_exists($this, 'expectException')) { + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage($expectedMessage); + } else { + $this->setExpectedException(InvalidConfigurationException::class, $expectedMessage); } $processor = new Processor(); diff --git a/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php b/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php index 15df850796..014a5ae179 100644 --- a/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/ButtonBuilderTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Form\ButtonBuilder; +use Symfony\Component\Form\Exception\InvalidArgumentException; /** * @author Alexander Cheprasov @@ -53,10 +54,12 @@ class ButtonBuilderTest extends TestCase */ public function testInvalidNames($name) { - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}( - '\Symfony\Component\Form\Exception\InvalidArgumentException', - 'Buttons cannot have empty names.' - ); + if (method_exists($this, 'expectException')) { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Buttons cannot have empty names.'); + } else { + $this->setExpectedException(InvalidArgumentException::class, 'Buttons cannot have empty names.'); + } new ButtonBuilder($name); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php index 25ad31f866..81e6b3bc6c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateIntervalToArrayTransformerTest.php @@ -181,7 +181,12 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase 'minutes' => '', 'seconds' => '6', ); - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'This amount of "minutes" is invalid'); + if (method_exists($this, 'expectException')) { + $this->expectException(TransformationFailedException::class); + $this->expectExceptionMessage('This amount of "minutes" is invalid'); + } else { + $this->setExpectedException(TransformationFailedException::class, 'This amount of "minutes" is invalid'); + } $transformer->reverseTransform($input); } @@ -191,7 +196,12 @@ class DateIntervalToArrayTransformerTest extends DateIntervalTestCase $input = array( 'invert' => '1', ); - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(TransformationFailedException::class, 'The value of "invert" must be boolean'); + if (method_exists($this, 'expectException')) { + $this->expectException(TransformationFailedException::class); + $this->expectExceptionMessage('The value of "invert" must be boolean'); + } else { + $this->setExpectedException(TransformationFailedException::class, 'The value of "invert" must be boolean'); + } $transformer->reverseTransform($input); } diff --git a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php index 5f739158c9..25712af7de 100644 --- a/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessFailedExceptionTest.php @@ -29,10 +29,12 @@ class ProcessFailedExceptionTest extends TestCase ->method('isSuccessful') ->will($this->returnValue(true)); - $this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}( - '\InvalidArgumentException', - 'Expected a failed process, but the given process was successful.' - ); + if (method_exists($this, 'expectException')) { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Expected a failed process, but the given process was successful.'); + } else { + $this->setExpectedException(\InvalidArgumentException::class, 'Expected a failed process, but the given process was successful.'); + } new ProcessFailedException($process); } From 2350597288e0c431a84bdee5534e51ac3508e83f Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Sun, 15 Oct 2017 19:29:08 +0200 Subject: [PATCH 05/22] add DOMElement as return type in Crawler::getIterator to support foreach support in ide --- src/Symfony/Component/DomCrawler/Crawler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index 1ad80e933e..9596610ddc 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -1071,7 +1071,7 @@ class Crawler implements \Countable, \IteratorAggregate } /** - * @return \ArrayIterator + * @return \ArrayIterator|\DOMElement[] */ public function getIterator() { From ba37cba6c2513ecf239946e95dac22bc2e5fe1ad Mon Sep 17 00:00:00 2001 From: maryo Date: Sun, 15 Oct 2017 19:41:03 +0200 Subject: [PATCH 06/22] Fixed unsetting from loosely equal keys OrderedHashMap --- .../Form/Tests/Util/OrderedHashMapTest.php | 20 +++++++++++++++++++ .../Component/Form/Util/OrderedHashMap.php | 4 ++-- .../Form/Util/OrderedHashMapIterator.php | 8 +++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php b/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php index 89735ea618..fe922e9239 100644 --- a/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php +++ b/src/Symfony/Component/Form/Tests/Util/OrderedHashMapTest.php @@ -56,6 +56,15 @@ class OrderedHashMapTest extends TestCase $this->assertSame(array(0 => 1, 'foo' => 2, 1 => 3), iterator_to_array($map)); } + public function testInsertLooselyEqualKeys() + { + $map = new OrderedHashMap(); + $map['1 as a string'] = '1 as a string'; + $map[1] = 1; + + $this->assertSame(array('1 as a string' => '1 as a string', 1 => 1), iterator_to_array($map)); + } + /** * Updates should not change the position of an element, otherwise we could * turn foreach loops into endless loops if they change the current @@ -111,6 +120,17 @@ class OrderedHashMapTest extends TestCase $this->assertSame(array('second' => 2), iterator_to_array($map)); } + public function testUnsetFromLooselyEqualKeysHashMap() + { + $map = new OrderedHashMap(); + $map['1 as a string'] = '1 as a string'; + $map[1] = 1; + + unset($map[1]); + + $this->assertSame(array('1 as a string' => '1 as a string'), iterator_to_array($map)); + } + public function testUnsetNonExistingSucceeds() { $map = new OrderedHashMap(); diff --git a/src/Symfony/Component/Form/Util/OrderedHashMap.php b/src/Symfony/Component/Form/Util/OrderedHashMap.php index 78687032fe..24ec0d5299 100644 --- a/src/Symfony/Component/Form/Util/OrderedHashMap.php +++ b/src/Symfony/Component/Form/Util/OrderedHashMap.php @@ -133,7 +133,7 @@ class OrderedHashMap implements \ArrayAccess, \IteratorAggregate, \Countable : 1 + (int) max($this->orderedKeys); } - $this->orderedKeys[] = $key; + $this->orderedKeys[] = (string) $key; } $this->elements[$key] = $value; @@ -144,7 +144,7 @@ class OrderedHashMap implements \ArrayAccess, \IteratorAggregate, \Countable */ public function offsetUnset($key) { - if (false !== ($position = array_search($key, $this->orderedKeys))) { + if (false !== ($position = array_search((string) $key, $this->orderedKeys))) { array_splice($this->orderedKeys, $position, 1); unset($this->elements[$key]); diff --git a/src/Symfony/Component/Form/Util/OrderedHashMapIterator.php b/src/Symfony/Component/Form/Util/OrderedHashMapIterator.php index 7305f51640..11562475d8 100644 --- a/src/Symfony/Component/Form/Util/OrderedHashMapIterator.php +++ b/src/Symfony/Component/Form/Util/OrderedHashMapIterator.php @@ -118,7 +118,13 @@ class OrderedHashMapIterator implements \Iterator */ public function key() { - return $this->key; + if (null === $this->key) { + return null; + } + + $array = array($this->key => null); + + return key($array); } /** From c17a92259af8330f9b11cc11da5aabb9c4f4c59f Mon Sep 17 00:00:00 2001 From: "Anton A. Sumin" Date: Fri, 10 Mar 2017 23:00:21 +0300 Subject: [PATCH 07/22] Fixed pathinfo calculation for requests starting with a question mark. - fix bad conflict resolving issue - port symfony/symfony#21968 to 3.3+ --- .../Component/HttpFoundation/Request.php | 8 ++- .../HttpFoundation/Tests/RequestTest.php | 61 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 28e78c0a20..ac3ec7171e 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1863,6 +1863,9 @@ class Request // Does the baseUrl have anything in common with the request_uri? $requestUri = $this->getRequestUri(); + if ($requestUri !== '' && $requestUri[0] !== '/') { + $requestUri = '/'.$requestUri; + } if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, $baseUrl)) { // full $baseUrl matches @@ -1935,9 +1938,12 @@ class Request } // Remove the query string from REQUEST_URI - if ($pos = strpos($requestUri, '?')) { + if (false !== $pos = strpos($requestUri, '?')) { $requestUri = substr($requestUri, 0, $pos); } + if ($requestUri !== '' && $requestUri[0] !== '/') { + $requestUri = '/'.$requestUri; + } $pathInfo = substr($requestUri, strlen($baseUrl)); if (null !== $baseUrl && (false === $pathInfo || '' === $pathInfo)) { diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index b36fbb7e96..3c123656cc 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -1286,6 +1286,12 @@ class RequestTest extends TestCase $request->initialize(array(), array(), array(), array(), array(), $server); $this->assertEquals('/path%20test/info', $request->getPathInfo()); + + $server = array(); + $server['REQUEST_URI'] = '?a=b'; + $request->initialize(array(), array(), array(), array(), array(), $server); + + $this->assertEquals('/', $request->getPathInfo()); } public function testGetParameterPrecedence() @@ -2188,6 +2194,61 @@ class RequestTest extends TestCase Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_FORWARDED_PORT'); Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_FORWARDED_PROTO'); } + + public function nonstandardRequestsData() + { + return array( + array('', '', '/', 'http://host:8080/', ''), + array('/', '', '/', 'http://host:8080/', ''), + + array('hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'), + array('/hello/app.php/x', '', '/x', 'http://host:8080/hello/app.php/x', '/hello', '/hello/app.php'), + + array('', 'a=b', '/', 'http://host:8080/?a=b'), + array('?a=b', 'a=b', '/', 'http://host:8080/?a=b'), + array('/?a=b', 'a=b', '/', 'http://host:8080/?a=b'), + + array('x', 'a=b', '/x', 'http://host:8080/x?a=b'), + array('x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'), + array('/x?a=b', 'a=b', '/x', 'http://host:8080/x?a=b'), + + array('hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'), + array('/hello/x', '', '/x', 'http://host:8080/hello/x', '/hello'), + + array('hello/app.php/x', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'), + array('hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'), + array('/hello/app.php/x?a=b', 'a=b', '/x', 'http://host:8080/hello/app.php/x?a=b', '/hello', '/hello/app.php'), + ); + } + + /** + * @dataProvider nonstandardRequestsData + */ + public function testNonstandardRequests($requestUri, $queryString, $expectedPathInfo, $expectedUri, $expectedBasePath = '', $expectedBaseUrl = null) + { + if (null === $expectedBaseUrl) { + $expectedBaseUrl = $expectedBasePath; + } + + $server = array( + 'HTTP_HOST' => 'host:8080', + 'SERVER_PORT' => '8080', + 'QUERY_STRING' => $queryString, + 'PHP_SELF' => '/hello/app.php', + 'SCRIPT_FILENAME' => '/some/path/app.php', + 'REQUEST_URI' => $requestUri, + ); + + $request = new Request(array(), array(), array(), array(), array(), $server); + + $this->assertEquals($expectedPathInfo, $request->getPathInfo()); + $this->assertEquals($expectedUri, $request->getUri()); + $this->assertEquals($queryString, $request->getQueryString()); + $this->assertEquals(8080, $request->getPort()); + $this->assertEquals('host:8080', $request->getHttpHost()); + $this->assertEquals($expectedBaseUrl, $request->getBaseUrl()); + $this->assertEquals($expectedBasePath, $request->getBasePath()); + } } class RequestContentProxy extends Request From 56b29a754cbe4af6669b57135347da19ef475265 Mon Sep 17 00:00:00 2001 From: Yuriy Potemkin Date: Mon, 16 Oct 2017 20:34:10 +0300 Subject: [PATCH 08/22] pdo session fix --- .../Session/Storage/Handler/PdoSessionHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php index 5cdac63939..daabbc21f0 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php @@ -387,7 +387,7 @@ class PdoSessionHandler implements \SessionHandlerInterface $this->gcCalled = false; // delete the session records that have expired - $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol < :time"; + $sql = "DELETE FROM $this->table WHERE $this->lifetimeCol < :time - $this->timeCol"; $stmt = $this->pdo->prepare($sql); $stmt->bindValue(':time', time(), \PDO::PARAM_INT); From a73249db313b8b9b5453de8b68c1c9e64983efbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 16 Oct 2017 09:56:04 +0200 Subject: [PATCH 09/22] [PropertyInfo] Add support for the iterable type --- src/Symfony/Component/PropertyInfo/Tests/TypeTest.php | 6 ++++++ src/Symfony/Component/PropertyInfo/Type.php | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/PropertyInfo/Tests/TypeTest.php b/src/Symfony/Component/PropertyInfo/Tests/TypeTest.php index 9266f9808f..cd1cab9167 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/TypeTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/TypeTest.php @@ -37,6 +37,12 @@ class TypeTest extends TestCase $this->assertEquals(Type::BUILTIN_TYPE_STRING, $collectionValueType->getBuiltinType()); } + public function testIterable() + { + $type = new Type('iterable'); + $this->assertSame('iterable', $type->getBuiltinType()); + } + /** * @expectedException \InvalidArgumentException * @expectedExceptionMessage "foo" is not a valid PHP type. diff --git a/src/Symfony/Component/PropertyInfo/Type.php b/src/Symfony/Component/PropertyInfo/Type.php index ad21f91724..3dc7d785fe 100644 --- a/src/Symfony/Component/PropertyInfo/Type.php +++ b/src/Symfony/Component/PropertyInfo/Type.php @@ -27,6 +27,7 @@ class Type const BUILTIN_TYPE_ARRAY = 'array'; const BUILTIN_TYPE_NULL = 'null'; const BUILTIN_TYPE_CALLABLE = 'callable'; + const BUILTIN_TYPE_ITERABLE = 'iterable'; /** * List of PHP builtin types. @@ -43,6 +44,7 @@ class Type self::BUILTIN_TYPE_ARRAY, self::BUILTIN_TYPE_CALLABLE, self::BUILTIN_TYPE_NULL, + self::BUILTIN_TYPE_ITERABLE, ); /** @@ -102,7 +104,7 @@ class Type /** * Gets built-in type. * - * Can be bool, int, float, string, array, object, resource, null or callback. + * Can be bool, int, float, string, array, object, resource, null, callback or iterable. * * @return string */ From b5246a72ca0f2089ac945d1b0f9a1edc45377dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 15 Oct 2017 19:28:12 +0200 Subject: [PATCH 10/22] [Serializer] ObjectNormalizer: throw if PropertyAccess isn't installed --- .../Component/Serializer/Normalizer/ObjectNormalizer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php index fbd771dbd7..2c5842d6a5 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php @@ -16,6 +16,7 @@ use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Serializer\Exception\CircularReferenceException; use Symfony\Component\Serializer\Exception\LogicException; +use Symfony\Component\Serializer\Exception\RuntimeException; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; @@ -33,6 +34,10 @@ class ObjectNormalizer extends AbstractNormalizer public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null) { + if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccess')) { + throw new RuntimeException('The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it.'); + } + parent::__construct($classMetadataFactory, $nameConverter); $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); From 7d21caf8ddef5b88bed4714f6bc4ef52e91dffa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 15 Oct 2017 19:38:38 +0200 Subject: [PATCH 11/22] [Serializer] YamlEncoder: throw if the Yaml component isn't installed --- src/Symfony/Component/Serializer/Encoder/YamlEncoder.php | 5 +++++ .../Component/Serializer/Normalizer/DataUriNormalizer.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php index 41ac04f209..3ac1af679a 100644 --- a/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/YamlEncoder.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Serializer\Encoder; +use Symfony\Component\Serializer\Exception\RuntimeException; use Symfony\Component\Yaml\Dumper; use Symfony\Component\Yaml\Parser; @@ -29,6 +30,10 @@ class YamlEncoder implements EncoderInterface, DecoderInterface public function __construct(Dumper $dumper = null, Parser $parser = null, array $defaultContext = array()) { + if (!class_exists(Dumper::class)) { + throw new RuntimeException('The YamlEncoder class requires the "Yaml" component. Install "symfony/yaml" to use it.'); + } + $this->dumper = $dumper ?: new Dumper(); $this->parser = $parser ?: new Parser(); $this->defaultContext = array_merge($this->defaultContext, $defaultContext); diff --git a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php index 9e5af130d0..121d3425f7 100644 --- a/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/DataUriNormalizer.php @@ -110,7 +110,7 @@ class DataUriNormalizer implements NormalizerInterface, DenormalizerInterface $supportedTypes = array( \SplFileInfo::class => true, \SplFileObject::class => true, - 'Symfony\Component\HttpFoundation\File\File' => true, + File::class => true, ); return isset($supportedTypes[$type]); From 45ac19220081f77a96374b6d3bbc2adfbfa54f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Tue, 17 Oct 2017 12:11:27 +0200 Subject: [PATCH 12/22] Remove obsolete PHPDoc from UriSigner --- src/Symfony/Component/HttpKernel/UriSigner.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/UriSigner.php b/src/Symfony/Component/HttpKernel/UriSigner.php index a64bf2c446..526a919738 100644 --- a/src/Symfony/Component/HttpKernel/UriSigner.php +++ b/src/Symfony/Component/HttpKernel/UriSigner.php @@ -55,10 +55,6 @@ class UriSigner /** * Checks that a URI contains the correct hash. * - * The _hash query string parameter must be the last one - * (as it is generated that way by the sign() method, it should - * never be a problem). - * * @param string $uri A signed URI * * @return bool True if the URI is signed correctly, false otherwise From e5d57dd0500e6dc9f313deeb97fc1fbc4a9be052 Mon Sep 17 00:00:00 2001 From: Richard Quadling Date: Tue, 17 Oct 2017 12:58:41 +0100 Subject: [PATCH 13/22] Username and password in basic auth are allowed to contain '.' Initially reported by Fede Isas in https://github.com/beberlei/assert/pull/234 --- src/Symfony/Component/Validator/Constraints/UrlValidator.php | 2 +- .../Component/Validator/Tests/Constraints/UrlValidatorTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Validator/Constraints/UrlValidator.php b/src/Symfony/Component/Validator/Constraints/UrlValidator.php index 1ba47ffd1d..40ac709fe8 100644 --- a/src/Symfony/Component/Validator/Constraints/UrlValidator.php +++ b/src/Symfony/Component/Validator/Constraints/UrlValidator.php @@ -24,7 +24,7 @@ class UrlValidator extends ConstraintValidator { const PATTERN = '~^ (%s):// # protocol - (([\pL\pN-]+:)?([\pL\pN-]+)@)? # basic auth + (([\.\pL\pN-]+:)?([\.\pL\pN-]+)@)? # basic auth ( ([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name | # or diff --git a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php index 5406b354ce..c921fce933 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php @@ -103,6 +103,9 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest array('http://xn--d1abbgf6aiiy.xn--p1ai/'), array('http://☎.com/'), array('http://username:password@symfony.com'), + array('http://user.name:password@symfony.com'), + array('http://username:pass.word@symfony.com'), + array('http://user.name:pass.word@symfony.com'), array('http://user-name@symfony.com'), ); } From fcc2146bef98317605adec580b63dd0ca320aed2 Mon Sep 17 00:00:00 2001 From: Theo Tzaferis Date: Tue, 17 Oct 2017 12:21:58 +0200 Subject: [PATCH 14/22] Remove BC Break label from `NullDumper` class https://github.com/symfony/dependency-injection/commit/7f34aa2643519f3400a6f66415a8cf9bf7147e81 This is the commit where the class has been made "final", but it has only been made final via php doc, not via code, so this shouldn't be a BC break in my opinion. --- UPGRADE-3.3.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 3cff95d850..1b61c35223 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -82,7 +82,7 @@ DependencyInjection * Autowiring services based on the types they implement is deprecated and won't be supported in version 4.0. Rename (or alias) your services to their FQCN id to make them autowirable. - * [BC BREAK] The `NullDumper` class has been made final + * The `NullDumper` class has been made final * [BC BREAK] `_defaults` and `_instanceof` are now reserved service names in Yaml configurations. Please rename any services with that names. From 2ef619f9bb4a38394b5e3716b3febec9499c6425 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 18 Oct 2017 16:44:01 -0400 Subject: [PATCH 15/22] Adding the Form default theme files to be warmed up in Twig's cache --- .../DependencyInjection/Compiler/ExtensionPass.php | 9 ++++++++- .../TwigBundle/DependencyInjection/TwigExtension.php | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php index c829cfa437..963a63b8c3 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php @@ -45,7 +45,14 @@ class ExtensionPass implements CompilerPassInterface if ($container->has('form.extension')) { $container->getDefinition('twig.extension.form')->addTag('twig.extension'); $reflClass = new \ReflectionClass('Symfony\Bridge\Twig\Extension\FormExtension'); - $container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form')); + + $coreThemePath = dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'; + $container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array($coreThemePath)); + + $paths = $container->getDefinition('twig.cache_warmer')->getArgument(2); + $paths[$coreThemePath] = null; + $container->getDefinition('twig.cache_warmer')->replaceArgument(2, $paths); + $container->getDefinition('twig.template_iterator')->replaceArgument(2, $paths); } if ($container->has('fragment.handler')) { diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 77d10e84c1..d1fab3184e 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -89,6 +89,7 @@ class TwigExtension extends Extension } } + // paths are modified in ExtensionPass if forms are enabled $container->getDefinition('twig.cache_warmer')->replaceArgument(2, $config['paths']); $container->getDefinition('twig.template_iterator')->replaceArgument(2, $config['paths']); From c63742daefdba877428716a8ed7a90ea5c3a8678 Mon Sep 17 00:00:00 2001 From: DQNEO Date: Thu, 19 Oct 2017 20:55:56 +0900 Subject: [PATCH 16/22] content can be a resource --- 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 f9d7895db0..b987c5b902 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -130,7 +130,7 @@ class Request public $headers; /** - * @var string + * @var string|resource */ protected $content; From df086fd9b3c535bdc5f0b441e88768878dbb379b Mon Sep 17 00:00:00 2001 From: DQNEO Date: Thu, 19 Oct 2017 20:43:06 +0900 Subject: [PATCH 17/22] $isClientIpsVali is not used --- src/Symfony/Component/HttpFoundation/Request.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index ac3ec7171e..4947904776 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -221,7 +221,6 @@ class Request protected static $requestFactory; private $isHostValid = true; - private $isClientIpsValid = true; private $isForwardedValid = true; private static $trustedHeaderSet = -1; From 058fb84554d2cd2d25490f90cee02e76de6d715c Mon Sep 17 00:00:00 2001 From: DQNEO Date: Thu, 19 Oct 2017 22:42:56 +0900 Subject: [PATCH 18/22] streamed response should return $this --- .../Component/HttpFoundation/StreamedResponse.php | 8 +++++--- .../HttpFoundation/Tests/StreamedResponseTest.php | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/StreamedResponse.php b/src/Symfony/Component/HttpFoundation/StreamedResponse.php index d6b7b9e53a..01e8cf8c36 100644 --- a/src/Symfony/Component/HttpFoundation/StreamedResponse.php +++ b/src/Symfony/Component/HttpFoundation/StreamedResponse.php @@ -83,12 +83,12 @@ class StreamedResponse extends Response public function sendHeaders() { if ($this->headersSent) { - return; + return $this; } $this->headersSent = true; - parent::sendHeaders(); + return parent::sendHeaders(); } /** @@ -99,7 +99,7 @@ class StreamedResponse extends Response public function sendContent() { if ($this->streamed) { - return; + return $this; } $this->streamed = true; @@ -109,6 +109,8 @@ class StreamedResponse extends Response } call_user_func($this->callback); + + return $this; } /** diff --git a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php index 5874145348..2ccb6841ad 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/StreamedResponseTest.php @@ -121,4 +121,15 @@ class StreamedResponseTest extends TestCase $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response); $this->assertEquals(204, $response->getStatusCode()); } + + public function testReturnThis() + { + $response = new StreamedResponse(function () {}); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent()); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendContent()); + + $response = new StreamedResponse(function () {}); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders()); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response->sendHeaders()); + } } From 0d7657b306b79bc2f6657f64d5ee543f0cc6ca26 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Thu, 19 Oct 2017 20:21:06 +0200 Subject: [PATCH 19/22] [FrameworkBundle][Serializer] Move normalizer/encoders definitions to xml file & remove unnecessary checks --- .../FrameworkExtension.php | 40 +------------------ .../Resources/config/serializer.xml | 23 +++++++++++ .../FrameworkExtensionTest.php | 17 -------- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 234b2d0cb2..f19884017d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -47,15 +47,10 @@ use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface; use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\Security\Core\Security; -use Symfony\Component\Serializer\Encoder\CsvEncoder; use Symfony\Component\Serializer\Encoder\DecoderInterface; use Symfony\Component\Serializer\Encoder\EncoderInterface; -use Symfony\Component\Serializer\Encoder\YamlEncoder; use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; -use Symfony\Component\Serializer\Normalizer\DataUriNormalizer; -use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; -use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Validator\ConstraintValidatorInterface; use Symfony\Component\Validator\ObjectInitializerInterface; @@ -1278,39 +1273,6 @@ class FrameworkExtension extends Extension */ private function registerSerializerConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) { - if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) { - // Run before serializer.normalizer.object - $definition = $container->register('serializer.normalizer.data_uri', DataUriNormalizer::class); - $definition->setPublic(false); - $definition->addTag('serializer.normalizer', array('priority' => -920)); - } - - if (class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) { - // Run before serializer.normalizer.object - $definition = $container->register('serializer.normalizer.datetime', DateTimeNormalizer::class); - $definition->setPublic(false); - $definition->addTag('serializer.normalizer', array('priority' => -910)); - } - - if (class_exists('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer')) { - // Run before serializer.normalizer.object - $definition = $container->register('serializer.normalizer.json_serializable', JsonSerializableNormalizer::class); - $definition->setPublic(false); - $definition->addTag('serializer.normalizer', array('priority' => -900)); - } - - if (class_exists(YamlEncoder::class) && defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT')) { - $definition = $container->register('serializer.encoder.yaml', YamlEncoder::class); - $definition->setPublic(false); - $definition->addTag('serializer.encoder'); - } - - if (class_exists(CsvEncoder::class)) { - $definition = $container->register('serializer.encoder.csv', CsvEncoder::class); - $definition->setPublic(false); - $definition->addTag('serializer.encoder'); - } - $loader->load('serializer.xml'); $chainLoader = $container->getDefinition('serializer.mapping.chain_loader'); @@ -1367,7 +1329,7 @@ class FrameworkExtension extends Extension $container->getDefinition('serializer.mapping.class_metadata_factory')->replaceArgument( 1, new Reference($config['cache']) ); - } elseif (!$container->getParameter('kernel.debug') && class_exists(CacheClassMetadataFactory::class)) { + } elseif (!$container->getParameter('kernel.debug')) { $cacheMetadataFactory = new Definition( CacheClassMetadataFactory::class, array( diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml index d350091a01..d49feadf9b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml @@ -25,6 +25,21 @@ + + + + + + + + + + + + + + + null @@ -86,6 +101,14 @@ + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 11795e54cb..44a853dd14 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -35,7 +35,6 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\PropertyAccess\PropertyAccessor; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Serializer; -use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory; use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader; use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader; use Symfony\Component\Serializer\Normalizer\DataUriNormalizer; @@ -728,10 +727,6 @@ abstract class FrameworkExtensionTest extends TestCase public function testDataUriNormalizerRegistered() { - if (!class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) { - $this->markTestSkipped('The DataUriNormalizer has been introduced in the Serializer Component version 3.1.'); - } - $container = $this->createContainerFromFile('full'); $definition = $container->getDefinition('serializer.normalizer.data_uri'); @@ -743,10 +738,6 @@ abstract class FrameworkExtensionTest extends TestCase public function testDateTimeNormalizerRegistered() { - if (!class_exists('Symfony\Component\Serializer\Normalizer\DateTimeNormalizer')) { - $this->markTestSkipped('The DateTimeNormalizer has been introduced in the Serializer Component version 3.1.'); - } - $container = $this->createContainerFromFile('full'); $definition = $container->getDefinition('serializer.normalizer.datetime'); @@ -758,10 +749,6 @@ abstract class FrameworkExtensionTest extends TestCase public function testJsonSerializableNormalizerRegistered() { - if (!class_exists('Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer')) { - $this->markTestSkipped('The JsonSerializableNormalizer has been introduced in the Serializer Component version 3.1.'); - } - $container = $this->createContainerFromFile('full'); $definition = $container->getDefinition('serializer.normalizer.json_serializable'); @@ -784,10 +771,6 @@ abstract class FrameworkExtensionTest extends TestCase public function testSerializerCacheActivated() { - if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) { - $this->markTestSkipped('The Serializer default cache warmer has been introduced in the Serializer Component version 3.2.'); - } - $container = $this->createContainerFromFile('serializer_enabled'); $this->assertTrue($container->hasDefinition('serializer.mapping.cache_class_metadata_factory')); From ab8f5be40c5996bdc09b4163e077659a859c301d Mon Sep 17 00:00:00 2001 From: DQNEO Date: Thu, 19 Oct 2017 21:29:08 +0900 Subject: [PATCH 20/22] declare argument type --- src/Symfony/Component/HttpFoundation/AcceptHeader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/AcceptHeader.php b/src/Symfony/Component/HttpFoundation/AcceptHeader.php index 99be6768f9..c6fd85f947 100644 --- a/src/Symfony/Component/HttpFoundation/AcceptHeader.php +++ b/src/Symfony/Component/HttpFoundation/AcceptHeader.php @@ -153,7 +153,7 @@ class AcceptHeader private function sort() { if (!$this->sorted) { - uasort($this->items, function ($a, $b) { + uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) { $qA = $a->getQuality(); $qB = $b->getQuality(); From 6e18b56b779ea14802c4b0c41f832c3731a6ab51 Mon Sep 17 00:00:00 2001 From: Gunnstein Lye Date: Fri, 20 Oct 2017 15:38:08 +0200 Subject: [PATCH 21/22] [Security] Fixed auth provider authenticate() cannot return void The AuthenticationManagerInterface requires that authenticate() must return a TokenInterface, never null. Several authentication providers are violating this. Changed to throw exception instead. --- .../Provider/AnonymousAuthenticationProvider.php | 3 ++- .../Provider/PreAuthenticatedAuthenticationProvider.php | 3 ++- .../Provider/RememberMeAuthenticationProvider.php | 3 ++- .../Authentication/Provider/UserAuthenticationProvider.php | 2 +- .../Provider/AnonymousAuthenticationProviderTest.php | 6 +++++- .../Provider/PreAuthenticatedAuthenticationProviderTest.php | 6 +++++- .../Provider/RememberMeAuthenticationProviderTest.php | 6 +++++- .../Provider/UserAuthenticationProviderTest.php | 6 +++++- 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/AnonymousAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/AnonymousAuthenticationProvider.php index 882443a013..39e6ad8005 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/AnonymousAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/AnonymousAuthenticationProvider.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Security\Core\Authentication\Provider; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; @@ -38,7 +39,7 @@ class AnonymousAuthenticationProvider implements AuthenticationProviderInterface public function authenticate(TokenInterface $token) { if (!$this->supports($token)) { - return; + throw new AuthenticationException('The token is not supported by this authentication provider.'); } if ($this->key !== $token->getKey()) { diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php index b871f1f5a3..d03fcb460f 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/PreAuthenticatedAuthenticationProvider.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Security\Core\Authentication\Provider; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface; +use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; @@ -51,7 +52,7 @@ class PreAuthenticatedAuthenticationProvider implements AuthenticationProviderIn public function authenticate(TokenInterface $token) { if (!$this->supports($token)) { - return; + throw new AuthenticationException('The token is not supported by this authentication provider.'); } if (!$user = $token->getUser()) { diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php index 1e51f6b8fd..0342c26f13 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/RememberMeAuthenticationProvider.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Security\Core\Authentication\Provider; use Symfony\Component\Security\Core\User\UserCheckerInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken; +use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\Exception\BadCredentialsException; class RememberMeAuthenticationProvider implements AuthenticationProviderInterface @@ -40,7 +41,7 @@ class RememberMeAuthenticationProvider implements AuthenticationProviderInterfac public function authenticate(TokenInterface $token) { if (!$this->supports($token)) { - return; + throw new AuthenticationException('The token is not supported by this authentication provider.'); } if ($this->key !== $token->getKey()) { diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php index 7527128cc7..28d057ef3b 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php @@ -56,7 +56,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter public function authenticate(TokenInterface $token) { if (!$this->supports($token)) { - return; + throw new AuthenticationException('The token is not supported by this authentication provider.'); } $username = $token->getUsername(); diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php index b7fa4d6b54..a7367e320b 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php @@ -24,11 +24,15 @@ class AnonymousAuthenticationProviderTest extends TestCase $this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); } + /** + * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException + * @expectedExceptionMessage The token is not supported by this authentication provider. + */ public function testAuthenticateWhenTokenIsNotSupported() { $provider = $this->getProvider('foo'); - $this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); + $provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()); } /** diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php index 5a78d0ebb9..5a6b04d5b4 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php @@ -36,11 +36,15 @@ class PreAuthenticatedAuthenticationProviderTest extends TestCase $this->assertFalse($provider->supports($token)); } + /** + * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException + * @expectedExceptionMessage The token is not supported by this authentication provider. + */ public function testAuthenticateWhenTokenIsNotSupported() { $provider = $this->getProvider(); - $this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); + $provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()); } /** diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php index 241076755e..733123fbc0 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php @@ -26,12 +26,16 @@ class RememberMeAuthenticationProviderTest extends TestCase $this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); } + /** + * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException + * @expectedExceptionMessage The token is not supported by this authentication provider. + */ public function testAuthenticateWhenTokenIsNotSupported() { $provider = $this->getProvider(); $token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock(); - $this->assertNull($provider->authenticate($token)); + $provider->authenticate($token); } /** diff --git a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php index da6136f221..a08ca3f813 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authentication/Provider/UserAuthenticationProviderTest.php @@ -29,11 +29,15 @@ class UserAuthenticationProviderTest extends TestCase $this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); } + /** + * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException + * @expectedExceptionMessage The token is not supported by this authentication provider. + */ public function testAuthenticateWhenTokenIsNotSupported() { $provider = $this->getProvider(); - $this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock())); + $provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()); } /** From 6610c25cd64b85c3b41eeabddfefe0e7a70ae030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Fri, 20 Oct 2017 09:35:09 +0200 Subject: [PATCH 22/22] [Routing] Fix resource miss --- .../Component/Routing/RouteCollectionBuilder.php | 6 +++--- .../Routing/Tests/RouteCollectionBuilderTest.php | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Routing/RouteCollectionBuilder.php b/src/Symfony/Component/Routing/RouteCollectionBuilder.php index 2c9e031723..bf996ea4e0 100644 --- a/src/Symfony/Component/Routing/RouteCollectionBuilder.php +++ b/src/Symfony/Component/Routing/RouteCollectionBuilder.php @@ -312,10 +312,10 @@ class RouteCollectionBuilder $routeCollection->addCollection($subCollection); } + } - foreach ($this->resources as $resource) { - $routeCollection->addResource($resource); - } + foreach ($this->resources as $resource) { + $routeCollection->addResource($resource); } return $routeCollection; diff --git a/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php b/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php index 058a100d1f..6fc592affc 100644 --- a/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php @@ -12,7 +12,9 @@ namespace Symfony\Component\Routing\Tests; use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\FileLocator; use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\Routing\Loader\YamlFileLoader; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouteCollectionBuilder; @@ -59,7 +61,18 @@ class RouteCollectionBuilderTest extends TestCase $this->assertCount(1, $addedCollection->getResources()); // make sure the routes were imported into the top-level builder + $routeCollection = $routes->build(); $this->assertCount(1, $routes->build()); + $this->assertCount(1, $routeCollection->getResources()); + } + + public function testImportAddResources() + { + $routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator(array(__DIR__.'/Fixtures/')))); + $routeCollectionBuilder->import('file_resource.yml'); + $routeCollection = $routeCollectionBuilder->build(); + + $this->assertCount(1, $routeCollection->getResources()); } /**