From 97d28b5e4e23cca3dbe090e29d427275f4d98bf6 Mon Sep 17 00:00:00 2001 From: Stadly Date: Fri, 26 Apr 2019 12:01:40 +0200 Subject: [PATCH 01/26] Load plurals from mo files properly --- .../Translation/Loader/MoFileLoader.php | 13 ++++--------- .../Tests/Loader/MoFileLoaderTest.php | 5 ++++- .../Translation/Tests/fixtures/plurals.mo | Bin 74 -> 448 bytes 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Translation/Loader/MoFileLoader.php b/src/Symfony/Component/Translation/Loader/MoFileLoader.php index 74d2b2f441..4b249df024 100644 --- a/src/Symfony/Component/Translation/Loader/MoFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/MoFileLoader.php @@ -111,17 +111,12 @@ class MoFileLoader extends FileLoader $ids = ['singular' => $singularId, 'plural' => $pluralId]; $item = compact('ids', 'translated'); - if (\is_array($item['translated'])) { - $messages[$item['ids']['singular']] = stripcslashes($item['translated'][0]); + if (!empty($item['ids']['singular'])) { + $id = $item['ids']['singular']; if (isset($item['ids']['plural'])) { - $plurals = []; - foreach ($item['translated'] as $plural => $translated) { - $plurals[] = sprintf('{%d} %s', $plural, $translated); - } - $messages[$item['ids']['plural']] = stripcslashes(implode('|', $plurals)); + $id .= '|'.$item['ids']['plural']; } - } elseif (!empty($item['ids']['singular'])) { - $messages[$item['ids']['singular']] = stripcslashes($item['translated']); + $messages[$id] = stripcslashes(implode('|', (array) $item['translated'])); } } diff --git a/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php index 63de5cebaa..d6adecb173 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/MoFileLoaderTest.php @@ -34,7 +34,10 @@ class MoFileLoaderTest extends TestCase $resource = __DIR__.'/../fixtures/plurals.mo'; $catalogue = $loader->load($resource, 'en', 'domain1'); - $this->assertEquals(['foo' => 'bar', 'foos' => '{0} bar|{1} bars'], $catalogue->all('domain1')); + $this->assertEquals([ + 'foo|foos' => 'bar|bars', + '{0} no foos|one foo|%count% foos' => '{0} no bars|one bar|%count% bars', + ], $catalogue->all('domain1')); $this->assertEquals('en', $catalogue->getLocale()); $this->assertEquals([new FileResource($resource)], $catalogue->getResources()); } diff --git a/src/Symfony/Component/Translation/Tests/fixtures/plurals.mo b/src/Symfony/Component/Translation/Tests/fixtures/plurals.mo index 6445e77beab595289cd154ea253c4e49dfd6af47..3945ad95beae6c9ce059cb8d5209c53653c47440 100644 GIT binary patch literal 448 zcmYL_&rSkC493@giP@uP5A{Hzhe047$dWxF7!rsZvl@?^6|RIMVJP@`5{?BFK$r{hUKD*w_WrkMko+TAzA#5p zh<$%fwf5NPz3~C8!RxhV@?u>p^om_Am{C@(3|6YI&B7+Y%TU_1)q#yn&l%2AXkK*U z%;-54P7NmNfs8FRClF`1x#}81C#AYZN5NBf^iukce`|==soWsj3Y|96G(?`Qa7HR8 zTu40{jC#Ad&3Ys5YIel(+uKs6I(l`N%L+^GK=F*ml1uONzH0CK{P-yu)#E}>N}eUq r9+z%=Qv$^Cqq-p`vw1|OX;M09)m!yu9F5UGz5fS3b_Eugd`kOrxNfwcU51|TkGNJ=aM;bH~=*B}U7 From 23db9be884776baa4071cc4f087d7694345b1a34 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Wed, 19 Jun 2019 12:46:55 +0100 Subject: [PATCH 02/26] Don't assume port 0 for X-Forwarded-Port --- 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 ea3f460c46..fc26304ad2 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1037,7 +1037,7 @@ class Request $pos = strrpos($host, ':'); } - if (false !== $pos) { + if (false !== $pos && !empty(substr($host, $pos + 1))) { return (int) substr($host, $pos + 1); } From c266d6c7371799cf8d5f803322b24a773e5e1f1b Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Wed, 19 Jun 2019 17:03:11 +0100 Subject: [PATCH 03/26] Update Request.php --- src/Symfony/Component/HttpFoundation/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index fc26304ad2..38b7fc2169 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1037,8 +1037,8 @@ class Request $pos = strrpos($host, ':'); } - if (false !== $pos && !empty(substr($host, $pos + 1))) { - return (int) substr($host, $pos + 1); + if (false !== $pos && '' !== $port = substr($host, $pos + 1)) { + return (int) $port; } return 'https' === $this->getScheme() ? 443 : 80; From 6c49a0c758c0dfacbe812bef8348ae7356029137 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Sun, 30 Jun 2019 23:48:04 +0100 Subject: [PATCH 04/26] Add test case --- .../Component/HttpFoundation/Tests/RequestTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index d266e1f68a..650d8fca7d 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -2427,6 +2427,18 @@ class RequestTest extends TestCase $this->assertSame(443, $request->getPort()); } + + public function testTrustedPortDoesNotDefaultToZero() + { + Request::setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_ALL); + + $request = Request::create('/'); + $request->server->set('REMOTE_ADDR', '1.1.1.1'); + $request->headers->set('X-Forwarded-Host', 'test.example.com'); + $request->headers->set('X-Forwarded-Port', null); + + $this->assertSame(80, $request->getPort()); + } } class RequestContentProxy extends Request From adcdd938a4e29599b7c4135fecffc216e9ca17a6 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 4 Jul 2019 22:58:06 +0200 Subject: [PATCH 05/26] PHP 5 compat --- 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 38b7fc2169..7185d75e92 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -1037,7 +1037,7 @@ class Request $pos = strrpos($host, ':'); } - if (false !== $pos && '' !== $port = substr($host, $pos + 1)) { + if (false !== $pos && $port = substr($host, $pos + 1)) { return (int) $port; } From ec5d7346b397d2ce8c4837d83da6d6881db31651 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 5 Jul 2019 09:04:50 +0200 Subject: [PATCH 06/26] Fix CS regarding nullable arguments --- src/Symfony/Component/Console/Helper/ProgressBar.php | 2 +- src/Symfony/Component/HttpFoundation/UrlHelper.php | 2 +- .../Component/HttpKernel/DataCollector/LoggerDataCollector.php | 2 +- .../Component/HttpKernel/EventListener/LocaleAwareListener.php | 2 +- .../Core/Authentication/AuthenticationTrustResolver.php | 2 +- .../Serializer/Extractor/ObjectPropertyListExtractor.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index e30fe786e3..cb2bc21379 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -248,7 +248,7 @@ final class ProgressBar * * @param int|null $max Number of steps to complete the bar (0 if indeterminate), if null it will be inferred from $iterable */ - public function iterate(iterable $iterable, ?int $max = null): iterable + public function iterate(iterable $iterable, int $max = null): iterable { $this->start($max ?? (is_countable($iterable) ? \count($iterable) : 0)); diff --git a/src/Symfony/Component/HttpFoundation/UrlHelper.php b/src/Symfony/Component/HttpFoundation/UrlHelper.php index 3c06e93217..f114c0a9fb 100644 --- a/src/Symfony/Component/HttpFoundation/UrlHelper.php +++ b/src/Symfony/Component/HttpFoundation/UrlHelper.php @@ -23,7 +23,7 @@ final class UrlHelper private $requestStack; private $requestContext; - public function __construct(RequestStack $requestStack, ?RequestContext $requestContext = null) + public function __construct(RequestStack $requestStack, RequestContext $requestContext = null) { $this->requestStack = $requestStack; $this->requestContext = $requestContext; diff --git a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php index 4091b6760f..405a951526 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php @@ -149,7 +149,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte return $logs; } - private function getContainerCompilerLogs(?string $compilerLogsFilepath = null): array + private function getContainerCompilerLogs(string $compilerLogsFilepath = null): array { if (!file_exists($compilerLogsFilepath)) { return []; diff --git a/src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php b/src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php index 325b8cbc0d..fb8e67e7ed 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/LocaleAwareListener.php @@ -63,7 +63,7 @@ class LocaleAwareListener implements EventSubscriberInterface ]; } - private function setLocale(string $locale, ?string $defaultLocale = null): void + private function setLocale(string $locale, string $defaultLocale = null): void { foreach ($this->localeAwareServices as $service) { try { diff --git a/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolver.php b/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolver.php index cba6a87082..bc057445da 100644 --- a/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolver.php +++ b/src/Symfony/Component/Security/Core/Authentication/AuthenticationTrustResolver.php @@ -25,7 +25,7 @@ class AuthenticationTrustResolver implements AuthenticationTrustResolverInterfac private $anonymousClass; private $rememberMeClass; - public function __construct(?string $anonymousClass = null, ?string $rememberMeClass = null) + public function __construct(string $anonymousClass = null, string $rememberMeClass = null) { $this->anonymousClass = $anonymousClass; $this->rememberMeClass = $rememberMeClass; diff --git a/src/Symfony/Component/Serializer/Extractor/ObjectPropertyListExtractor.php b/src/Symfony/Component/Serializer/Extractor/ObjectPropertyListExtractor.php index 2ea19d28fa..c3e117945e 100644 --- a/src/Symfony/Component/Serializer/Extractor/ObjectPropertyListExtractor.php +++ b/src/Symfony/Component/Serializer/Extractor/ObjectPropertyListExtractor.php @@ -23,7 +23,7 @@ final class ObjectPropertyListExtractor implements ObjectPropertyListExtractorIn private $propertyListExtractor; private $objectClassResolver; - public function __construct(PropertyListExtractorInterface $propertyListExtractor, ?callable $objectClassResolver = null) + public function __construct(PropertyListExtractorInterface $propertyListExtractor, callable $objectClassResolver = null) { $this->propertyListExtractor = $propertyListExtractor; $this->objectClassResolver = $objectClassResolver; From 5e26d96a6b9c4b3529c1dd54560b888e09b5689b Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sat, 6 Jul 2019 10:17:29 +0200 Subject: [PATCH 07/26] [Intl] Init compile tmp volume --- src/Symfony/Component/Intl/Resources/bin/compile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Intl/Resources/bin/compile b/src/Symfony/Component/Intl/Resources/bin/compile index a593809604..d66558395d 100755 --- a/src/Symfony/Component/Intl/Resources/bin/compile +++ b/src/Symfony/Component/Intl/Resources/bin/compile @@ -1,8 +1,7 @@ #!/usr/bin/env bash -if [[ $1 == force ]]; then - docker pull jakzal/php-intl -fi; +[[ $1 == force ]] && docker pull jakzal/php-intl +[[ ! -d /tmp/symfony/icu ]] && mkdir -p /tmp/symfony/icu docker run \ -it --rm --name symfony-intl \ From 0c52a531e2af2b2434cf409564bf7ed4e2d3fae9 Mon Sep 17 00:00:00 2001 From: Bruno Nogueira Nascimento Wowk Date: Fri, 5 Jul 2019 15:17:39 -0300 Subject: [PATCH 08/26] Remove call to deprecated method --- .../Component/Messenger/DependencyInjection/MessengerPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php index f0ed17627f..a7a0a3aec3 100644 --- a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php +++ b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php @@ -214,7 +214,7 @@ class MessengerPass implements CompilerPassInterface throw new RuntimeException(sprintf('Invalid handler service "%s": type-hint of argument "$%s" in method "%s::__invoke()" must be a class , "%s" given.', $serviceId, $parameters[0]->getName(), $handlerClass->getName(), $type)); } - return [(string) $parameters[0]->getType()]; + return [$parameters[0]->getType()->getName()]; } private function registerReceivers(ContainerBuilder $container, array $busIds) From 50b3ec4dc507c6448411f14f8051e449470016ad Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Sun, 7 Jul 2019 01:09:30 +0200 Subject: [PATCH 09/26] [Messenger] fix publishing headers set on AmqpStamp --- .../Tests/Transport/AmqpExt/ConnectionTest.php | 15 +++++++++++++++ .../Messenger/Transport/AmqpExt/AmqpStamp.php | 4 ++-- .../Messenger/Transport/AmqpExt/Connection.php | 15 +++++++-------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php b/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php index e7dee84219..a81f54c4bc 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/AmqpExt/ConnectionTest.php @@ -418,6 +418,21 @@ class ConnectionTest extends TestCase $connection->channel(); } + public function testAmqpStampHeadersAreUsed() + { + $factory = new TestAmqpFactory( + $this->createMock(\AMQPConnection::class), + $this->createMock(\AMQPChannel::class), + $this->createMock(\AMQPQueue::class), + $amqpExchange = $this->createMock(\AMQPExchange::class) + ); + + $amqpExchange->expects($this->once())->method('publish')->with('body', null, AMQP_NOPARAM, ['headers' => ['Foo' => 'X', 'Bar' => 'Y']]); + + $connection = Connection::fromDsn('amqp://localhost', [], $factory); + $connection->publish('body', ['Foo' => 'X'], 0, new AmqpStamp(null, AMQP_NOPARAM, ['headers' => ['Bar' => 'Y']])); + } + public function testItCanPublishWithTheDefaultRoutingKey() { $factory = new TestAmqpFactory( diff --git a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpStamp.php b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpStamp.php index d7a00c09b4..b8298d5697 100644 --- a/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpStamp.php +++ b/src/Symfony/Component/Messenger/Transport/AmqpExt/AmqpStamp.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Messenger\Transport\AmqpExt; -use Symfony\Component\Messenger\Stamp\StampInterface; +use Symfony\Component\Messenger\Stamp\NonSendableStampInterface; /** * @author Guillaume Gammelin @@ -19,7 +19,7 @@ use Symfony\Component\Messenger\Stamp\StampInterface; * * @experimental in 4.3 */ -final class AmqpStamp implements StampInterface +final class AmqpStamp implements NonSendableStampInterface { private $routingKey; private $flags; diff --git a/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php b/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php index ecd72a7be9..3c7a91f621 100644 --- a/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/AmqpExt/Connection.php @@ -191,9 +191,7 @@ class Connection $this->exchange(), $body, $this->getRoutingKeyForMessage($amqpStamp), - [ - 'headers' => $headers, - ], + $headers, $amqpStamp ); } @@ -223,20 +221,21 @@ class Connection $this->getDelayExchange(), $body, $this->getRoutingKeyForDelay($delay, $routingKey), - [ - 'headers' => $headers, - ], + $headers, $amqpStamp ); } - private function publishOnExchange(\AMQPExchange $exchange, string $body, string $routingKey = null, array $attributes = [], AmqpStamp $amqpStamp = null) + private function publishOnExchange(\AMQPExchange $exchange, string $body, string $routingKey = null, array $headers = [], AmqpStamp $amqpStamp = null) { + $attributes = $amqpStamp ? $amqpStamp->getAttributes() : []; + $attributes['headers'] = array_merge($headers, $attributes['headers'] ?? []); + $exchange->publish( $body, $routingKey, $amqpStamp ? $amqpStamp->getFlags() : AMQP_NOPARAM, - array_merge($amqpStamp ? $amqpStamp->getAttributes() : [], $attributes) + $attributes ); } From 8ffc61692d03799ab3eb55798186774646fbb871 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sun, 7 Jul 2019 09:15:14 +0200 Subject: [PATCH 10/26] [Intl] Remove --dev from intl compile autoloader --- src/Symfony/Component/Intl/Resources/bin/autoload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Intl/Resources/bin/autoload.php b/src/Symfony/Component/Intl/Resources/bin/autoload.php index 13e0564781..14167a5f4a 100644 --- a/src/Symfony/Component/Intl/Resources/bin/autoload.php +++ b/src/Symfony/Component/Intl/Resources/bin/autoload.php @@ -12,7 +12,7 @@ $autoload = __DIR__.'/../../vendor/autoload.php'; if (!file_exists($autoload)) { - bailout('You should run "composer install --dev" in the component before running this script.'); + bailout('You should run "composer install" in the component before running this script.'); } require_once $autoload; From 0c326d0b5533ef871169abea57498a876daa3625 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sun, 7 Jul 2019 18:36:17 +0200 Subject: [PATCH 11/26] Add missing test for workflow dump description --- src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php | 1 + .../Tests/fixtures/puml/square/simple-workflow-marking.puml | 3 ++- .../Tests/fixtures/puml/square/simple-workflow-nomarking.puml | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php b/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php index 12c8f745e0..ae48d52d07 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php @@ -56,6 +56,7 @@ trait WorkflowBuilderTrait $placesMetadata = []; $placesMetadata['c'] = [ 'bg_color' => 'DeepSkyBlue', + 'description' => 'My custom place description', ]; $transitionsMetadata = new \SplObjectStorage(); diff --git a/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-marking.puml b/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-marking.puml index a316b64253..0ea138f83f 100644 --- a/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-marking.puml +++ b/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-marking.puml @@ -17,7 +17,8 @@ skinparam agent { } state "a" <> state "b" <> -state "c" <> +state "c" <> as c +c : My custom place description agent "t1" agent "t2" "a" -[#Purple]-> "t1": "My custom transition label 2" diff --git a/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-nomarking.puml b/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-nomarking.puml index 348ff6476b..02e7f396ea 100644 --- a/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-nomarking.puml +++ b/src/Symfony/Component/Workflow/Tests/fixtures/puml/square/simple-workflow-nomarking.puml @@ -17,7 +17,8 @@ skinparam agent { } state "a" <> state "b" -state "c" <> +state "c" <> as c +c : My custom place description agent "t1" agent "t2" "a" -[#Purple]-> "t1": "My custom transition label 2" From ff0c14171ba08300c99220f4085d26cdbff2deb2 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Sun, 7 Jul 2019 09:09:54 +0200 Subject: [PATCH 12/26] [Console] Update to inherit and add licence --- .../CommandLoader/CommandLoaderInterface.php | 9 ++++++ .../CommandLoader/ContainerCommandLoader.php | 9 ++++++ .../Formatter/OutputFormatterStyle.php | 30 ++++--------------- .../OutputFormatterStyleInterface.php | 2 +- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/Symfony/Component/Console/CommandLoader/CommandLoaderInterface.php b/src/Symfony/Component/Console/CommandLoader/CommandLoaderInterface.php index 9462996f6d..ca1029cb60 100644 --- a/src/Symfony/Component/Console/CommandLoader/CommandLoaderInterface.php +++ b/src/Symfony/Component/Console/CommandLoader/CommandLoaderInterface.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\CommandLoader; use Symfony\Component\Console\Command\Command; diff --git a/src/Symfony/Component/Console/CommandLoader/ContainerCommandLoader.php b/src/Symfony/Component/Console/CommandLoader/ContainerCommandLoader.php index 753ad0fb70..8000c7d5ec 100644 --- a/src/Symfony/Component/Console/CommandLoader/ContainerCommandLoader.php +++ b/src/Symfony/Component/Console/CommandLoader/ContainerCommandLoader.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Console\CommandLoader; use Psr\Container\ContainerInterface; diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php index b27439a761..477bd87f0c 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -75,11 +75,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface } /** - * Sets style foreground color. - * - * @param string|null $color The color name - * - * @throws InvalidArgumentException When the color name isn't defined + * {@inheritdoc} */ public function setForeground($color = null) { @@ -97,11 +93,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface } /** - * Sets style background color. - * - * @param string|null $color The color name - * - * @throws InvalidArgumentException When the color name isn't defined + * {@inheritdoc} */ public function setBackground($color = null) { @@ -119,11 +111,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface } /** - * Sets some specific style option. - * - * @param string $option The option name - * - * @throws InvalidArgumentException When the option name isn't defined + * {@inheritdoc} */ public function setOption($option) { @@ -137,11 +125,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface } /** - * Unsets some specific style option. - * - * @param string $option The option name - * - * @throws InvalidArgumentException When the option name isn't defined + * {@inheritdoc} */ public function unsetOption($option) { @@ -168,11 +152,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface } /** - * Applies the style to a given text. - * - * @param string $text The text to style - * - * @return string + * {@inheritdoc} */ public function apply($text) { diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleInterface.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleInterface.php index 4c7dc4134d..af171c2702 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyleInterface.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyleInterface.php @@ -21,7 +21,7 @@ interface OutputFormatterStyleInterface /** * Sets style foreground color. * - * @param string $color The color name + * @param string|null $color The color name */ public function setForeground($color = null); From 5249eaf9d56e44d8343a7068731b2a12c55f4596 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 8 Jul 2019 00:10:35 +0200 Subject: [PATCH 13/26] [EventDispatcher] Add tag kernel.rest on 'debug.event_dispatcher' service --- src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml index 24df7d5059..9f1da6a83c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml @@ -9,6 +9,7 @@ + From 9fc56c7e2836adc90e7739c1d46050e729912648 Mon Sep 17 00:00:00 2001 From: Sander Date: Fri, 5 Jul 2019 07:45:32 +0200 Subject: [PATCH 14/26] [Serializer]: AbstractObjectNormalizer ignores the property types of discriminated classes Add tests Remove test group Allow null Add quux null attribute Add quux value to serialize test --- .../Normalizer/AbstractObjectNormalizer.php | 7 +-- .../Fixtures/AbstractDummyFirstChild.php | 13 ++++++ .../Fixtures/AbstractDummySecondChild.php | 13 ++++++ .../Tests/Fixtures/DummyFirstChildQuux.php | 30 +++++++++++++ .../Tests/Fixtures/DummySecondChildQuux.php | 30 +++++++++++++ .../AbstractObjectNormalizerTest.php | 44 ++++++++++++++++++- .../Serializer/Tests/SerializerTest.php | 7 ++- 7 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 src/Symfony/Component/Serializer/Tests/Fixtures/DummyFirstChildQuux.php create mode 100644 src/Symfony/Component/Serializer/Tests/Fixtures/DummySecondChildQuux.php diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php index 620fa8a626..6c1e816a94 100644 --- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php @@ -281,13 +281,14 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer $reflectionClass = new \ReflectionClass($class); $object = $this->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes, $format); + $resolvedClass = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object); foreach ($normalizedData as $attribute => $value) { if ($this->nameConverter) { - $attribute = $this->nameConverter->denormalize($attribute, $class, $format, $context); + $attribute = $this->nameConverter->denormalize($attribute, $resolvedClass, $format, $context); } - if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($class, $attribute, $format, $context)) { + if ((false !== $allowedAttributes && !\in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($resolvedClass, $attribute, $format, $context)) { if (!($context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES])) { $extraAttributes[] = $attribute; } @@ -295,7 +296,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer continue; } - $value = $this->validateAndDenormalize($class, $attribute, $value, $format, $context); + $value = $this->validateAndDenormalize($resolvedClass, $attribute, $value, $format, $context); try { $this->setAttributeValue($object, $attribute, $value, $format, $context); } catch (InvalidArgumentException $e) { diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummyFirstChild.php b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummyFirstChild.php index 645c307c35..20672c39b5 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummyFirstChild.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummyFirstChild.php @@ -15,10 +15,23 @@ class AbstractDummyFirstChild extends AbstractDummy { public $bar; + /** @var DummyFirstChildQuux|null */ + public $quux; + public function __construct($foo = null, $bar = null) { parent::__construct($foo); $this->bar = $bar; } + + public function getQuux(): ?DummyFirstChildQuux + { + return $this->quux; + } + + public function setQuux(DummyFirstChildQuux $quux): void + { + $this->quux = $quux; + } } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummySecondChild.php b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummySecondChild.php index 5a41b9441a..67a72977e2 100644 --- a/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummySecondChild.php +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/AbstractDummySecondChild.php @@ -15,10 +15,23 @@ class AbstractDummySecondChild extends AbstractDummy { public $baz; + /** @var DummySecondChildQuux|null */ + public $quux; + public function __construct($foo = null, $baz = null) { parent::__construct($foo); $this->baz = $baz; } + + public function getQuux(): ?DummySecondChildQuux + { + return $this->quux; + } + + public function setQuux(DummySecondChildQuux $quux): void + { + $this->quux = $quux; + } } diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/DummyFirstChildQuux.php b/src/Symfony/Component/Serializer/Tests/Fixtures/DummyFirstChildQuux.php new file mode 100644 index 0000000000..7ba39fc346 --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/DummyFirstChildQuux.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Serializer\Tests\Fixtures; + +class DummyFirstChildQuux +{ + /** + * @var string + */ + private $value; + + public function __construct(string $value) + { + $this->value = $value; + } + + public function getValue(): string + { + return $this->value; + } +} diff --git a/src/Symfony/Component/Serializer/Tests/Fixtures/DummySecondChildQuux.php b/src/Symfony/Component/Serializer/Tests/Fixtures/DummySecondChildQuux.php new file mode 100644 index 0000000000..11c4d0eccd --- /dev/null +++ b/src/Symfony/Component/Serializer/Tests/Fixtures/DummySecondChildQuux.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Serializer\Tests\Fixtures; + +class DummySecondChildQuux +{ + /** + * @var string + */ + private $value; + + public function __construct(string $value) + { + $this->value = $value; + } + + public function getValue(): string + { + return $this->value; + } +} diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php index a45009d233..9d6debb0e7 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php @@ -16,13 +16,22 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\PropertyInfo\Type; use Symfony\Component\Serializer\Exception\NotNormalizableValueException; +use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; +use Symfony\Component\Serializer\Mapping\ClassDiscriminatorMapping; +use Symfony\Component\Serializer\Mapping\ClassMetadata; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; +use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerAwareInterface; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummy; +use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyFirstChild; +use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild; +use Symfony\Component\Serializer\Tests\Fixtures\DummySecondChildQuux; class AbstractObjectNormalizerTest extends TestCase { @@ -147,6 +156,39 @@ class AbstractObjectNormalizerTest extends TestCase return $denormalizer; } + public function testDenormalizeWithDiscriminatorMapUsesCorrectClassname() + { + $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); + $loaderMock = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock(); + $loaderMock->method('hasMetadataFor')->willReturnMap([ + [ + AbstractDummy::class, + true, + ], + ]); + + $loaderMock->method('getMetadataFor')->willReturnMap([ + [ + AbstractDummy::class, + new ClassMetadata( + AbstractDummy::class, + new ClassDiscriminatorMapping('type', [ + 'first' => AbstractDummyFirstChild::class, + 'second' => AbstractDummySecondChild::class, + ]) + ), + ], + ]); + + $discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock); + $normalizer = new AbstractObjectNormalizerDummy($factory, null, new PhpDocExtractor(), $discriminatorResolver); + $serializer = new Serializer([$normalizer]); + $normalizer->setSerializer($serializer); + $normalizedData = $normalizer->denormalize(['foo' => 'foo', 'baz' => 'baz', 'quux' => ['value' => 'quux'], 'type' => 'second'], AbstractDummy::class); + + $this->assertInstanceOf(DummySecondChildQuux::class, $normalizedData->quux); + } + /** * Test that additional attributes throw an exception if no metadata factory is specified. * @@ -190,7 +232,7 @@ class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = []) { - return \in_array($attribute, ['foo', 'baz']); + return \in_array($attribute, ['foo', 'baz', 'quux', 'value']); } public function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null) diff --git a/src/Symfony/Component/Serializer/Tests/SerializerTest.php b/src/Symfony/Component/Serializer/Tests/SerializerTest.php index a3b931b524..26a94b2f6f 100644 --- a/src/Symfony/Component/Serializer/Tests/SerializerTest.php +++ b/src/Symfony/Component/Serializer/Tests/SerializerTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Serializer\Tests; use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; +use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor; use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata; @@ -34,6 +35,7 @@ use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummy; use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyFirstChild; use Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild; +use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux; use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface; use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne; use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo; @@ -382,6 +384,7 @@ class SerializerTest extends TestCase public function testDeserializeAndSerializeAbstractObjectsWithTheClassMetadataDiscriminatorResolver() { $example = new AbstractDummyFirstChild('foo-value', 'bar-value'); + $example->setQuux(new DummyFirstChildQuux('quux')); $loaderMock = $this->getMockBuilder(ClassMetadataFactoryInterface::class)->getMock(); $loaderMock->method('hasMetadataFor')->willReturnMap([ @@ -405,9 +408,9 @@ class SerializerTest extends TestCase ]); $discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock); - $serializer = new Serializer([new ObjectNormalizer(null, null, null, null, $discriminatorResolver)], ['json' => new JsonEncoder()]); + $serializer = new Serializer([new ObjectNormalizer(null, null, null, new PhpDocExtractor(), $discriminatorResolver)], ['json' => new JsonEncoder()]); - $jsonData = '{"type":"first","bar":"bar-value","foo":"foo-value"}'; + $jsonData = '{"type":"first","quux":{"value":"quux"},"bar":"bar-value","foo":"foo-value"}'; $deserialized = $serializer->deserialize($jsonData, AbstractDummy::class, 'json'); $this->assertEquals($example, $deserialized); From 6b69a992304d4281420a5f60d1fd08a3f525c3e7 Mon Sep 17 00:00:00 2001 From: Stadly Date: Fri, 26 Apr 2019 11:57:49 +0200 Subject: [PATCH 15/26] [Translator] Load plurals from po files properly --- .../Translation/Loader/PoFileLoader.php | 31 ++++++++++--------- .../Tests/Loader/PoFileLoaderTest.php | 23 +++++++++++--- .../Tests/fixtures/missing-plurals.po | 4 +++ .../Translation/Tests/fixtures/plurals.po | 2 ++ 4 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 src/Symfony/Component/Translation/Tests/fixtures/missing-plurals.po diff --git a/src/Symfony/Component/Translation/Loader/PoFileLoader.php b/src/Symfony/Component/Translation/Loader/PoFileLoader.php index 1412a786a7..cf8a4b8553 100644 --- a/src/Symfony/Component/Translation/Loader/PoFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/PoFileLoader.php @@ -126,23 +126,24 @@ class PoFileLoader extends FileLoader */ private function addMessage(array &$messages, array $item) { - if (\is_array($item['translated'])) { - $messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated'][0]); + if (!empty($item['ids']['singular'])) { + $id = stripcslashes($item['ids']['singular']); if (isset($item['ids']['plural'])) { - $plurals = $item['translated']; - // PO are by definition indexed so sort by index. - ksort($plurals); - // Make sure every index is filled. - end($plurals); - $count = key($plurals); - // Fill missing spots with '-'. - $empties = array_fill(0, $count + 1, '-'); - $plurals += $empties; - ksort($plurals); - $messages[stripcslashes($item['ids']['plural'])] = stripcslashes(implode('|', $plurals)); + $id .= '|'.stripcslashes($item['ids']['plural']); } - } elseif (!empty($item['ids']['singular'])) { - $messages[stripcslashes($item['ids']['singular'])] = stripcslashes($item['translated']); + + $translated = (array) $item['translated']; + // PO are by definition indexed so sort by index. + ksort($translated); + // Make sure every index is filled. + end($translated); + $count = key($translated); + // Fill missing spots with '-'. + $empties = array_fill(0, $count + 1, '-'); + $translated += $empties; + ksort($translated); + + $messages[$id] = stripcslashes(implode('|', $translated)); } } } diff --git a/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php index d8e2c1993b..cb94e90a94 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/PoFileLoaderTest.php @@ -34,7 +34,10 @@ class PoFileLoaderTest extends TestCase $resource = __DIR__.'/../fixtures/plurals.po'; $catalogue = $loader->load($resource, 'en', 'domain1'); - $this->assertEquals(['foo' => 'bar', 'foos' => 'bar|bars'], $catalogue->all('domain1')); + $this->assertEquals([ + 'foo|foos' => 'bar|bars', + '{0} no foos|one foo|%count% foos' => '{0} no bars|one bar|%count% bars', + ], $catalogue->all('domain1')); $this->assertEquals('en', $catalogue->getLocale()); $this->assertEquals([new FileResource($resource)], $catalogue->getResources()); } @@ -89,10 +92,8 @@ class PoFileLoaderTest extends TestCase $catalogue = $loader->load($resource, 'en', 'domain1'); $messages = $catalogue->all('domain1'); - $this->assertArrayHasKey('escaped "foo"', $messages); - $this->assertArrayHasKey('escaped "foos"', $messages); - $this->assertEquals('escaped "bar"', $messages['escaped "foo"']); - $this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foos"']); + $this->assertArrayHasKey('escaped "foo"|escaped "foos"', $messages); + $this->assertEquals('escaped "bar"|escaped "bars"', $messages['escaped "foo"|escaped "foos"']); } public function testSkipFuzzyTranslations() @@ -106,4 +107,16 @@ class PoFileLoaderTest extends TestCase $this->assertArrayNotHasKey('foo2', $messages); $this->assertArrayHasKey('foo3', $messages); } + + public function testMissingPlurals() + { + $loader = new PoFileLoader(); + $resource = __DIR__.'/../fixtures/missing-plurals.po'; + $catalogue = $loader->load($resource, 'en', 'domain1'); + + $this->assertEquals([ + 'foo|foos' => '-|bar|-|bars', + ], $catalogue->all('domain1')); + $this->assertEquals('en', $catalogue->getLocale()); + } } diff --git a/src/Symfony/Component/Translation/Tests/fixtures/missing-plurals.po b/src/Symfony/Component/Translation/Tests/fixtures/missing-plurals.po new file mode 100644 index 0000000000..3b47fca805 --- /dev/null +++ b/src/Symfony/Component/Translation/Tests/fixtures/missing-plurals.po @@ -0,0 +1,4 @@ +msgid "foo" +msgid_plural "foos" +msgstr[3] "bars" +msgstr[1] "bar" diff --git a/src/Symfony/Component/Translation/Tests/fixtures/plurals.po b/src/Symfony/Component/Translation/Tests/fixtures/plurals.po index 439c41ad7f..61d1ba42b4 100644 --- a/src/Symfony/Component/Translation/Tests/fixtures/plurals.po +++ b/src/Symfony/Component/Translation/Tests/fixtures/plurals.po @@ -3,3 +3,5 @@ msgid_plural "foos" msgstr[0] "bar" msgstr[1] "bars" +msgid "{0} no foos|one foo|%count% foos" +msgstr "{0} no bars|one bar|%count% bars" From 213dfd149271a426b9d5024c150767ac4d39bff9 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Fri, 5 Jul 2019 10:40:43 +0100 Subject: [PATCH 16/26] [Messenger] Doctrine Transport: Support setting auto_setup from DSN --- .../Transport/Doctrine/ConnectionTest.php | 118 +++++++++++------- .../Transport/Doctrine/Connection.php | 15 +-- 2 files changed, 78 insertions(+), 55 deletions(-) diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php index 83708c5085..e50b48fcf4 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php @@ -157,62 +157,88 @@ class ConnectionTest extends TestCase /** * @dataProvider buildConfigurationProvider */ - public function testBuildConfiguration($dsn, $options, $expectedManager, $expectedTableName, $expectedRedeliverTimeout, $expectedQueue) + public function testBuildConfiguration($dsn, $options, $expectedConnection, $expectedTableName, $expectedRedeliverTimeout, $expectedQueue, $expectedAutoSetup) { $config = Connection::buildConfiguration($dsn, $options); - $this->assertEquals($expectedManager, $config['connection']); + $this->assertEquals($expectedConnection, $config['connection']); $this->assertEquals($expectedTableName, $config['table_name']); $this->assertEquals($expectedRedeliverTimeout, $config['redeliver_timeout']); $this->assertEquals($expectedQueue, $config['queue_name']); + $this->assertEquals($expectedAutoSetup, $config['auto_setup']); } public function buildConfigurationProvider() { - return [ - [ - 'dsn' => 'doctrine://default', - 'options' => [], - 'expectedManager' => 'default', - 'expectedTableName' => 'messenger_messages', - 'expectedRedeliverTimeout' => 3600, - 'expectedQueue' => 'default', - ], - // test options from options array - [ - 'dsn' => 'doctrine://default', - 'options' => [ - 'table_name' => 'name_from_options', - 'redeliver_timeout' => 1800, - 'queue_name' => 'important', - ], - 'expectedManager' => 'default', - 'expectedTableName' => 'name_from_options', - 'expectedRedeliverTimeout' => 1800, - 'expectedQueue' => 'important', - ], - // tests options from dsn - [ - 'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal', - 'options' => [], - 'expectedManager' => 'default', - 'expectedTableName' => 'name_from_dsn', - 'expectedRedeliverTimeout' => 1200, - 'expectedQueue' => 'normal', - ], - // test options from options array wins over options from dsn - [ - 'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal', - 'options' => [ - 'table_name' => 'name_from_options', - 'redeliver_timeout' => 1800, - 'queue_name' => 'important', - ], - 'expectedManager' => 'default', - 'expectedTableName' => 'name_from_options', - 'expectedRedeliverTimeout' => 1800, - 'expectedQueue' => 'important', - ], + yield 'no options' => [ + 'dsn' => 'doctrine://default', + 'options' => [], + 'expectedConnection' => 'default', + 'expectedTableName' => 'messenger_messages', + 'expectedRedeliverTimeout' => 3600, + 'expectedQueue' => 'default', + 'expectedAutoSetup' => true, ]; + + yield 'test options array' => [ + 'dsn' => 'doctrine://default', + 'options' => [ + 'table_name' => 'name_from_options', + 'redeliver_timeout' => 1800, + 'queue_name' => 'important', + 'auto_setup' => false, + ], + 'expectedConnection' => 'default', + 'expectedTableName' => 'name_from_options', + 'expectedRedeliverTimeout' => 1800, + 'expectedQueue' => 'important', + 'expectedAutoSetup' => false, + ]; + + yield 'options from dsn' => [ + 'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal&auto_setup=false', + 'options' => [], + 'expectedConnection' => 'default', + 'expectedTableName' => 'name_from_dsn', + 'expectedRedeliverTimeout' => 1200, + 'expectedQueue' => 'normal', + 'expectedAutoSetup' => false, + ]; + + yield 'options from options array wins over options from dsn' => [ + 'dsn' => 'doctrine://default?table_name=name_from_dsn&redeliver_timeout=1200&queue_name=normal&auto_setup=true', + 'options' => [ + 'table_name' => 'name_from_options', + 'redeliver_timeout' => 1800, + 'queue_name' => 'important', + 'auto_setup' => false, + ], + 'expectedConnection' => 'default', + 'expectedTableName' => 'name_from_options', + 'expectedRedeliverTimeout' => 1800, + 'expectedQueue' => 'important', + 'expectedAutoSetup' => false, + ]; + + yield 'options from dsn with falsey boolean' => [ + 'dsn' => 'doctrine://default?auto_setup=0', + 'options' => [], + 'expectedConnection' => 'default', + 'expectedTableName' => 'messenger_messages', + 'expectedRedeliverTimeout' => 3600, + 'expectedQueue' => 'default', + 'expectedAutoSetup' => false, + ]; + + yield 'options from dsn with thruthy boolean' => [ + 'dsn' => 'doctrine://default?auto_setup=1', + 'options' => [], + 'expectedConnection' => 'default', + 'expectedTableName' => 'messenger_messages', + 'expectedRedeliverTimeout' => 3600, + 'expectedQueue' => 'default', + 'expectedAutoSetup' => true, + ]; + } /** diff --git a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php index 74a85bbfbe..c8692ba348 100644 --- a/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php @@ -76,22 +76,19 @@ class Connection parse_str($components['query'], $query); } - $configuration = [ - 'connection' => $components['host'], - 'table_name' => $options['table_name'] ?? ($query['table_name'] ?? self::DEFAULT_OPTIONS['table_name']), - 'queue_name' => $options['queue_name'] ?? ($query['queue_name'] ?? self::DEFAULT_OPTIONS['queue_name']), - 'redeliver_timeout' => $options['redeliver_timeout'] ?? ($query['redeliver_timeout'] ?? self::DEFAULT_OPTIONS['redeliver_timeout']), - 'auto_setup' => $options['auto_setup'] ?? ($query['auto_setup'] ?? self::DEFAULT_OPTIONS['auto_setup']), - ]; + $configuration = ['connection' => $components['host']]; + $configuration += $options + $query + self::DEFAULT_OPTIONS; + + $configuration['auto_setup'] = filter_var($configuration['auto_setup'], FILTER_VALIDATE_BOOLEAN); // check for extra keys in options - $optionsExtraKeys = array_diff(array_keys($options), array_keys($configuration)); + $optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS)); if (0 < \count($optionsExtraKeys)) { throw new InvalidArgumentException(sprintf('Unknown option found : [%s]. Allowed options are [%s]', implode(', ', $optionsExtraKeys), implode(', ', self::DEFAULT_OPTIONS))); } // check for extra keys in options - $queryExtraKeys = array_diff(array_keys($query), array_keys($configuration)); + $queryExtraKeys = array_diff(array_keys($query), array_keys(self::DEFAULT_OPTIONS)); if (0 < \count($queryExtraKeys)) { throw new InvalidArgumentException(sprintf('Unknown option found in DSN: [%s]. Allowed options are [%s]', implode(', ', $queryExtraKeys), implode(', ', self::DEFAULT_OPTIONS))); } From 853e032c1972d5a9447927b3da6dc332f3dbb831 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 8 Jul 2019 11:24:04 +0200 Subject: [PATCH 17/26] fixed CS --- .../Messenger/Tests/Transport/Doctrine/ConnectionTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php index e50b48fcf4..d2caf2dfab 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php @@ -238,7 +238,6 @@ class ConnectionTest extends TestCase 'expectedQueue' => 'default', 'expectedAutoSetup' => true, ]; - } /** From f7738d934bba4bf3d33168cae2d30aab8e30e80d Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 3 Jun 2019 16:43:29 +0200 Subject: [PATCH 18/26] [SecurityBundle] Fix profiler dump for non-invokable security listeners --- .../SecurityBundle/Debug/WrappedListener.php | 25 ++++++++++++++----- .../Debug/TraceableFirewallListenerTest.php | 6 +---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php index 2a36e10102..42735a1025 100644 --- a/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php +++ b/src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php @@ -39,10 +39,6 @@ final class WrappedListener implements ListenerInterface public function __construct($listener) { $this->listener = $listener; - - if (null === self::$hasVarDumper) { - self::$hasVarDumper = class_exists(ClassStub::class); - } } /** @@ -76,8 +72,25 @@ final class WrappedListener implements ListenerInterface public function getInfo(): array { - if (null === $this->stub) { - $this->stub = self::$hasVarDumper ? new ClassStub(\get_class($this->listener)) : \get_class($this->listener); + if (null !== $this->stub) { + // no-op + } elseif (self::$hasVarDumper ?? self::$hasVarDumper = class_exists(ClassStub::class)) { + $this->stub = ClassStub::wrapCallable($this->listener); + } elseif (\is_array($this->listener)) { + $this->stub = (\is_object($this->listener[0]) ? \get_class($this->listener[0]) : $this->listener[0]).'::'.$this->listener[1]; + } elseif ($this->listener instanceof \Closure) { + $r = new \ReflectionFunction($this->listener); + if (false !== strpos($r->name, '{closure}')) { + $this->stub = 'closure'; + } elseif ($class = $r->getClosureScopeClass()) { + $this->stub = $class->name.'::'.$r->name; + } else { + $this->stub = $r->name; + } + } elseif (\is_string($this->listener)) { + $this->stub = $this->listener; + } else { + $this->stub = \get_class($this->listener).'::__invoke'; } return [ diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php index c301ead2fa..b7c6bcc076 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php @@ -20,7 +20,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator; -use Symfony\Component\VarDumper\Caster\ClassStub; /** * @group time-sensitive @@ -56,9 +55,6 @@ class TraceableFirewallListenerTest extends TestCase $listeners = $firewall->getWrappedListeners(); $this->assertCount(1, $listeners); - $this->assertSame($response, $listeners[0]['response']); - $this->assertInstanceOf(ClassStub::class, $listeners[0]['stub']); - $this->assertSame(\get_class($listener), (string) $listeners[0]['stub']); - $this->assertSame(1, $listenerCalled); + $this->assertSame($listener, $listeners[0]['stub']); } } From bd498f2503fb725a0ee509b0de7e70b4f71291d2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 8 Jul 2019 13:57:06 +0200 Subject: [PATCH 19/26] fixed CS --- src/Symfony/Component/HttpFoundation/Tests/RequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php index 650d8fca7d..73d12cb3f7 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/RequestTest.php @@ -2435,7 +2435,7 @@ class RequestTest extends TestCase $request = Request::create('/'); $request->server->set('REMOTE_ADDR', '1.1.1.1'); $request->headers->set('X-Forwarded-Host', 'test.example.com'); - $request->headers->set('X-Forwarded-Port', null); + $request->headers->set('X-Forwarded-Port', ''); $this->assertSame(80, $request->getPort()); } From a0901294d4376a940b1b9b8cae441c10a5624513 Mon Sep 17 00:00:00 2001 From: "Nathanael d. Noblet" Date: Sat, 25 May 2019 08:21:47 -0600 Subject: [PATCH 20/26] [FrameworkBundle] Inform the user when save_path will be ignored --- .../DependencyInjection/Configuration.php | 8 +++++++- .../DependencyInjection/FrameworkExtension.php | 9 +++++++++ .../Tests/DependencyInjection/ConfigurationTest.php | 1 - .../Fixtures/php/session_savepath.php | 8 ++++++++ .../Fixtures/xml/session_savepath.xml | 12 ++++++++++++ .../Fixtures/yml/session_savepath.yml | 4 ++++ .../DependencyInjection/FrameworkExtensionTest.php | 7 +++++++ 7 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/session_savepath.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_savepath.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/session_savepath.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 52c7706456..52369bbffa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -470,6 +470,12 @@ class Configuration implements ConfigurationInterface $rootNode ->children() ->arrayNode('session') + ->validate() + ->ifTrue(function ($v) { + return empty($v['handler_id']) && !empty($v['save_path']); + }) + ->thenInvalid('Session save path is ignored without a handler service') + ->end() ->info('session configuration') ->canBeEnabled() ->children() @@ -498,7 +504,7 @@ class Configuration implements ConfigurationInterface ->defaultTrue() ->setDeprecated('The "%path%.%node%" option is enabled by default and deprecated since Symfony 3.4. It will be always enabled in 4.0.') ->end() - ->scalarNode('save_path')->defaultValue('%kernel.cache_dir%/sessions')->end() + ->scalarNode('save_path')->end() ->integerNode('metadata_update_threshold') ->defaultValue('0') ->info('seconds to wait between 2 session metadata updates') diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 4e792ded2e..650e1f2f50 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -873,6 +873,11 @@ class FrameworkExtension extends Extension // session handler (the internal callback registered with PHP session management) if (null === $config['handler_id']) { + // If the user set a save_path without using a non-default \SessionHandler, it will silently be ignored + if (isset($config['save_path'])) { + throw new LogicException('Session save path is ignored without a handler service'); + } + // Set the handler class to be null $container->getDefinition('session.storage.native')->replaceArgument(1, null); $container->getDefinition('session.storage.php_bridge')->replaceArgument(0, null); @@ -880,6 +885,10 @@ class FrameworkExtension extends Extension $container->setAlias('session.handler', $config['handler_id'])->setPrivate(true); } + if (!isset($config['save_path'])) { + $config['save_path'] = ini_get('session.save_path'); + } + $container->setParameter('session.save_path', $config['save_path']); if (\PHP_VERSION_ID < 70000) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 91764a642e..b1dea4cba4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -378,7 +378,6 @@ class ConfigurationTest extends TestCase 'handler_id' => 'session.handler.native_file', 'cookie_httponly' => true, 'gc_probability' => 1, - 'save_path' => '%kernel.cache_dir%/sessions', 'metadata_update_threshold' => '0', 'use_strict_mode' => true, ], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/session_savepath.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/session_savepath.php new file mode 100644 index 0000000000..89841bca43 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/session_savepath.php @@ -0,0 +1,8 @@ +loadFromExtension('framework', [ + 'session' => [ + 'handler_id' => null, + 'save_path' => '/some/path', + ], +]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_savepath.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_savepath.xml new file mode 100644 index 0000000000..a9ddd8016b --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_savepath.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/session_savepath.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/session_savepath.yml new file mode 100644 index 0000000000..174ebe5869 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/session_savepath.yml @@ -0,0 +1,4 @@ +framework: + session: + handler_id: null + save_path: /some/path diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 51b4ff1524..2572c3aadf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -24,6 +24,7 @@ use Symfony\Component\Cache\Adapter\DoctrineAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\ProxyAdapter; use Symfony\Component\Cache\Adapter\RedisAdapter; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -474,6 +475,12 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0)); } + public function testNullSessionHandlerWithSavePath() + { + $this->expectException(InvalidConfigurationException::class); + $this->createContainerFromFile('session_savepath'); + } + public function testRequest() { $container = $this->createContainerFromFile('full'); From 5328c4b55293149802bb38ed904f86a1d7f681b6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 8 Jul 2019 14:55:32 +0200 Subject: [PATCH 21/26] fixed tests on old PHP versions --- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index ce305d16cc..b0356b3c14 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -474,9 +474,11 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertNull($container->getDefinition('session.storage.php_bridge')->getArgument(0)); } + /** + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ public function testNullSessionHandlerWithSavePath() { - $this->expectException(InvalidConfigurationException::class); $this->createContainerFromFile('session_savepath'); } From 60939d988dff2a0a4fa14cd3c1126c04759d8bb6 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 8 Jul 2019 15:34:24 +0200 Subject: [PATCH 22/26] Added tests to cover the possibility of having scalars as services. --- .../Tests/ContainerBuilderTest.php | 15 ++++++++++++++ .../Tests/ContainerTest.php | 10 ++++++++++ .../Tests/Dumper/PhpDumperTest.php | 20 +++++++++++++++++++ .../Tests/Fixtures/ScalarFactory.php | 14 +++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/ScalarFactory.php diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index b3bea30b74..46074a67a5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -38,6 +38,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition; +use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory; use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy; use Symfony\Component\DependencyInjection\TypedReference; use Symfony\Component\ExpressionLanguage\Expression; @@ -1532,6 +1533,20 @@ class ContainerBuilderTest extends TestCase $this->assertSame(['service_container'], array_keys($container->getDefinitions())); } + + public function testScalarService() + { + $c = new ContainerBuilder(); + $c->register('foo', 'string') + ->setPublic(true) + ->setFactory([ScalarFactory::class, 'getSomeValue']) + ; + + $c->compile(); + + $this->assertTrue($c->has('foo')); + $this->assertSame('some value', $c->get('foo')); + } } class FooClass diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php index d2616a34ba..5dbec886e6 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php @@ -386,6 +386,16 @@ class ContainerTest extends TestCase $this->assertTrue($sc->has('foo\\baz'), '->has() returns true if a get*Method() is defined'); } + public function testScalarService() + { + $c = new Container(); + + $c->set('foo', 'some value'); + + $this->assertTrue($c->has('foo')); + $this->assertSame('some value', $c->get('foo')); + } + public function testInitialized() { $sc = new ProjectServiceContainer(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index a1ccb52b60..926933bb0e 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php @@ -30,6 +30,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\Tests\Fixtures\CustomDefinition; +use Symfony\Component\DependencyInjection\Tests\Fixtures\ScalarFactory; use Symfony\Component\DependencyInjection\Tests\Fixtures\StubbedTranslator; use Symfony\Component\DependencyInjection\Tests\Fixtures\TestServiceSubscriber; use Symfony\Component\DependencyInjection\TypedReference; @@ -1115,6 +1116,25 @@ class PhpDumperTest extends TestCase $this->assertEquals((object) ['foo' => (object) []], $container->get('Bar')); } + + public function testScalarService() + { + $container = new ContainerBuilder(); + $container->register('foo', 'string') + ->setPublic(true) + ->setFactory([ScalarFactory::class, 'getSomeValue']) + ; + + $container->compile(); + + $dumper = new PhpDumper($container); + eval('?>'.$dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Scalar_Service'])); + + $container = new \Symfony_DI_PhpDumper_Test_Scalar_Service(); + + $this->assertTrue($container->has('foo')); + $this->assertSame('some value', $container->get('foo')); + } } class Rot13EnvVarProcessor implements EnvVarProcessorInterface diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ScalarFactory.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ScalarFactory.php new file mode 100644 index 0000000000..15646a8d0c --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/ScalarFactory.php @@ -0,0 +1,14 @@ + Date: Mon, 8 Jul 2019 19:17:40 +0200 Subject: [PATCH 23/26] Spell "triggering" properly As a side effect, the property name matches the one in the declaration, which was correct. --- .../PhpUnit/DeprecationErrorHandler/Deprecation.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php index 6d5b39fd54..ea84256663 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php @@ -76,7 +76,7 @@ class Deprecation // No-op } $line = $trace[$i]; - $this->trigerringFilePathType = $this->getPathType($file); + $this->triggeringFilePathType = $this->getPathType($file); if (isset($line['object']) || isset($line['class'])) { if (isset($line['class']) && 0 === strpos($line['class'], SymfonyTestsListenerFor::class)) { $parsedMsg = unserialize($this->message); @@ -88,7 +88,7 @@ class Deprecation // then we need to use the serialized information to determine // if the error has been triggered from vendor code. if (isset($parsedMsg['triggering_file'])) { - $this->trigerringFilePathType = $this->getPathType($parsedMsg['triggering_file']); + $this->triggeringFilePathType = $this->getPathType($parsedMsg['triggering_file']); } return; @@ -177,10 +177,10 @@ class Deprecation */ public function getType() { - if (self::PATH_TYPE_SELF === $this->trigerringFilePathType) { + if (self::PATH_TYPE_SELF === $this->triggeringFilePathType) { return self::TYPE_SELF; } - if (self::PATH_TYPE_UNDETERMINED === $this->trigerringFilePathType) { + if (self::PATH_TYPE_UNDETERMINED === $this->triggeringFilePathType) { return self::TYPE_UNDETERMINED; } $erroringFile = $erroringPackage = null; From e9abc7d654fa519ce647025a85621626d62d9d53 Mon Sep 17 00:00:00 2001 From: Arman <44655055+Arman-Hosseini@users.noreply.github.com> Date: Tue, 9 Jul 2019 10:43:23 +0430 Subject: [PATCH 24/26] Improve fa translations --- .../Resources/translations/validators.fa.xlf | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf b/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf index ff1aa7c0b1..2cfcbea4b0 100644 --- a/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf +++ b/src/Symfony/Component/Validator/Resources/translations/validators.fa.xlf @@ -16,19 +16,19 @@ This value should be blank. - این فیلد باید خالی باشد. + این مقدار باید خالی باشد. The value you selected is not a valid choice. - گزینه انتخابی معتبر نیست. + مقدار انتخاب شده شامل گزینه های معتبر نمی باشد. You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices. - باید حداقل {{ limit }} گزینه انتخاب کنید.|باید حداقل {{ limit }} گزینه انتخاب کنید. + باید حداقل {{ limit }} گزینه انتخاب نمایید.|باید حداقل {{ limit }} گزینه انتخاب نمایید. You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices. - حداکثر {{ limit }} گزینه می توانید انتخاب کنید.|حداکثر {{ limit }} گزینه می توانید انتخاب کنید. + حداکثر {{ limit }} گزینه می توانید انتخاب نمایید.|حداکثر {{ limit }} گزینه می توانید انتخاب نمایید. One or more of the given values is invalid. @@ -44,87 +44,87 @@ This value is not a valid date. - این مقدار یک تاریخ معتبر نیست. + این مقدار یک تاریخ معتبر نمی باشد. This value is not a valid datetime. - این مقدار یک تاریخ و زمان معتبر نیست. + این مقدار یک تاریخ و زمان معتبر نمی باشد. This value is not a valid email address. - این یک رایانامه معتبر نیست. + این یک رایانامه معتبر نمی باشد. The file could not be found. - فایل پیدا نشد. + فایل یافت نشد. The file is not readable. - فایل قابلیت خواندن ندارد. + فایل قابلیت خوانده شدن ندارد. The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}. - فایل بیش از اندازه بزرگ است({{ size }} {{ suffix }}). حداکثر اندازه مجاز برابر {{ limit }} {{ suffix }} است. + فایل بیش از اندازه بزرگ است({{ size }} {{ suffix }}). حداکثر اندازه مجاز برابر با {{ limit }} {{ suffix }} می باشد. The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}. - این نوع فایل مجاز نیست({{ type }}). نوع های مجاز {{ types }} هستند. + این نوع فایل مجاز نمی باشد({{ type }}). نوع های مجاز شامل {{ types }} می باشند. This value should be {{ limit }} or less. - این مقدار باید کوچکتر یا مساوی {{ limit }} باشد. + این مقدار باید کوچکتر و یا مساوی {{ limit }} باشد. This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less. - بسیار طولانی است.حداکثر تعداد حروف مجاز برابر {{ limit }} است.|بسیار طولانی است.حداکثر تعداد حروف مجاز برابر {{ limit }} است. + بسیار طولانی است.حداکثر تعداد حروف مجاز برابر {{ limit }} می باشد.|بسیار طولانی است.حداکثر تعداد حروف مجاز برابر {{ limit }} می باشد. This value should be {{ limit }} or more. - این مقدار باید برابر و یا بیشتر از {{ limit }} باشد. + این مقدار باید بزرگتر و یا مساوی {{ limit }} باشد. This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more. - بسیار کوتاه است.تعداد حروف باید حداقل {{ limit }} باشد.|بسیار کوتاه است.تعداد حروف باید حداقل {{ limit }} باشد. + مقدار وارد شده بسیار کوتاه است.تعداد حروف وارد شده، باید حداقل شامل {{ limit }} کاراکتر باشد.|مقدار وارد شده بسیار کوتاه است.تعداد حروف وارد شده، باید حداقل شامل {{ limit }} کاراکتر باشد. This value should not be blank. - این مقدار نباید تهی باشد. + این مقدار نباید خالی باشد. This value should not be null. - باید مقداری داشته باشد.. + این مقدار باید شامل چیزی باشد. This value should be null. - نباید مقداری داشته باشد. + این مقدار باید شامل چیزی نباشد. This value is not valid. - این مقدار معتبر نیست. + این مقدار معتبر نمی باشد. This value is not a valid time. - این مقدار یک زمان صحیح نیست. + این مقدار یک زمان صحیح نمی باشد. This value is not a valid URL. - این یک URL معتبر نیست. + این مقدار شامل یک URL معتبر نمی باشد. The two values should be equal. - دو مقدار باید برابر باشند. + دو مقدار باید با یکدیگر برابر باشند. The file is too large. Allowed maximum size is {{ limit }} {{ suffix }}. - فایل بیش از اندازه بزرگ است. حداکثر اندازه مجاز برابر {{ limit }} {{ suffix }} است. + فایل بیش از اندازه بزرگ است. حداکثر اندازه مجاز برابر با {{ limit }} {{ suffix }} می باشد. The file is too large. - فایل بیش از اندازه بزرگ است. + فایل بیش از اندازه بزرگ می باشد. The file could not be uploaded. - بارگذاری فایل با شکست مواجه شد. + بارگذاری فایل با شکست مواجه گردید. This value should be a valid number. @@ -132,23 +132,23 @@ This file is not a valid image. - این فایل یک تصویر نیست. + این فایل یک تصویر نمی باشد. This is not a valid IP address. - این مقدار یک IP معتبر نیست. + این مقدار یک IP معتبر نمی باشد. This value is not a valid language. - این مقدار یک زبان صحیح نیست. + این مقدار یک زبان صحیح نمی باشد. This value is not a valid locale. - این مقدار یک محل صحیح نیست. + این مقدار یک محل صحیح نمی باشد. This value is not a valid country. - این مقدار یک کشور صحیح نیست. + این مقدار یک کشور صحیح نمی باشد. This value is already used. @@ -156,23 +156,23 @@ The size of the image could not be detected. - اندازه تصویر قابل شناسایی نیست. + اندازه تصویر قابل شناسایی نمی باشد. The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px. - طول تصویر بسیار بزرگ است ({{ width }}px). بشینه طول مجاز {{ max_width }}px است. + طول تصویر بسیار بزرگ است ({{ width }}px). بشینه طول مجاز {{ max_width }}px می باشد. The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px. - طول تصویر بسیار کوچک است ({{ width }}px). کمینه طول موردنظر {{ min_width }}px است. + طول تصویر بسیار کوچک است ({{ width }}px). کمینه طول موردنظر {{ min_width }}px می باشد. The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px. - ارتفاع تصویر بسیار بزرگ است ({{ height }}px). بشینه ارتفاع مجاز {{ max_height }}px است. + ارتفاع تصویر بسیار بزرگ است ({{ height }}px). بشینه ارتفاع مجاز {{ max_height }}px می باشد. The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px. - ارتفاع تصویر بسیار کوچک است ({{ height }}px). کمینه ارتفاع موردنظر {{ min_height }}px است. + ارتفاع تصویر بسیار کوچک است ({{ height }}px). کمینه ارتفاع موردنظر {{ min_height }}px می باشد. This value should be the user's current password. @@ -184,67 +184,67 @@ The file was only partially uploaded. - فایل به صورت جزیی بارگذاری شده است. + پرونده به صورت جزیی بارگذاری گردیده است. No file was uploaded. - هیچ فایلی بارگذاری نشد. + هیچ پرونده ای بارگذاری نگردیده است. No temporary folder was configured in php.ini. - فولدر موقت در php.ini پیکربندی نشده است. + فولدر موقت در php.ini پیکربندی نگردیده است. Cannot write temporary file to disk. - فایل موقت را نمی توان در دیسک نوشت. + فایل موقتی را نمی توان در دیسک نوشت. A PHP extension caused the upload to fail. - اکستنشن PHP موجب شد که بارگذاری فایل با شکست مواجه شود. + یک اکستنشن PHP موجب شد که بارگذاری فایل با شکست مواجه گردد. This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more. - این مجموعه می بایست دارای {{ limit }} عنصر یا بیشتر باشد.|این مجموعه می بایست دارای {{ limit }} عنصر یا بیشتر باشد. + این مجموعه می بایست دارای حداقل {{ limit }} عنصر یا بیشتر باشد.|این مجموعه می بایست دارای حداقل {{ limit }} عنصر یا بیشتر باشد. This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less. - این مجموعه می بایست دارای حداقل {{ limit }} عنصر یا کمتر باشد.|این مجموعه می بایست دارای {{ limit }} عنصر یا کمتر باشد. + این مجموعه می بایست دارای حداکثر {{ limit }} عنصر یا کمتر باشد.|این مجموعه می بایست دارای حداکثر {{ limit }} عنصر یا کمتر باشد. This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements. - این مجموعه می بایست به طور دقیق دارا {{ limit }} عنصر باشد.|این مجموعه می بایست به طور دقیق دارای {{ limit }} قلم باشد. + این مجموعه می بایست به طور دقیق دارای {{ limit }} عنصر باشد.|این مجموعه می بایست به طور دقیق دارای {{ limit }} عنصر باشد. Invalid card number. - شماره کارت نامعتبر است. + شماره کارت نامعتبر می باشد. Unsupported card type or invalid card number. - نوع کارت پشتیبانی نمی شود یا شماره کارت نامعتبر است. + نوع کارت پشتیبانی نمی شود و یا شماره کارت نامعتبر می باشد. This is not a valid International Bank Account Number (IBAN). - این یک شماره حساب بین المللی بانک (IBAN) درست نیست. + این یک شماره حساب بانک بین المللی معتبر نمی باشد (IBAN). This value is not a valid ISBN-10. - این مقدار یک ISBN-10 درست نیست. + این مقدار یک ISBN-10 معتبر نمی باشد. This value is not a valid ISBN-13. - این مقدار یک ISBN-13 درست نیست. + این مقدار یک ISBN-13 معتبر نمی باشد. This value is neither a valid ISBN-10 nor a valid ISBN-13. - این مقدار یک ISBN-10 درست یا ISBN-13 درست نیست. + این مقدار یک ISBN-10 صحیح و یا ISBN-13 معتبر نمی باشد. This value is not a valid ISSN. - این مقدار یک ISSN درست نیست. + این مقدار یک ISSN معتبر نمی باشد. This value is not a valid currency. - این مقدار یک یکای پول درست نیست. + این مقدار یک واحد پول معتبر نمی باشد. This value should be equal to {{ compared_value }}. @@ -256,11 +256,11 @@ This value should be greater than or equal to {{ compared_value }}. - این مقدار باید بزرگتر یا مساوی با {{ compared_value }} باشد. + این مقدار باید بزرگتر و یا مساوی با {{ compared_value }} باشد. This value should be identical to {{ compared_value_type }} {{ compared_value }}. - این مقدار باید با {{ compared_value_type }} {{ compared_value }} یکی باشد. + این مقدار باید با {{ compared_value_type }} {{ compared_value }} یکسان باشد. This value should be less than {{ compared_value }}. @@ -268,7 +268,7 @@ This value should be less than or equal to {{ compared_value }}. - این مقدار باید کمتر یا مساوی با {{ compared_value }} باشد. + این مقدار باید کمتر و یا مساوی با {{ compared_value }} باشد. This value should not be equal to {{ compared_value }}. @@ -276,43 +276,43 @@ This value should not be identical to {{ compared_value_type }} {{ compared_value }}. - این مقدار نباید {{ compared_value_type }} {{ compared_value }} یکی باشد. + این مقدار نباید با {{ compared_value_type }} {{ compared_value }} یکسان باشد. The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}. - ابعاد {{ ratio }} عکس بیش از حد بزرگ است.حداکثر ابعاد مجاز {{ max_ratio }} است. + ابعاد {{ ratio }} عکس بیش از حد بزرگ است.حداکثر ابعاد مجاز {{ max_ratio }} می باشد. The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}. - ابعاد {{ ratio }} عکس بیش از حد کوچک است.حداقل ابعاد مجاز {{ min_ratio }} است. + ابعاد {{ ratio }} عکس بیش از حد کوچک است.حداقل ابعاد مجاز {{ min_ratio }} می باشد. The image is square ({{ width }}x{{ height }}px). Square images are not allowed. - این عکس مربع width }}x{{ height }}px}} می باشد.عکس مربع مجاز نمی باشد. + این تصویر یک مربع width }}x{{ height }}px}} می باشد.تصویر مربع مجاز نمی باشد. The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed. - این عکس افقی width }}x{{ height }}px}} می باشد.عکس افقی مجاز نمی باشد. + این تصویر افقی width }}x{{ height }}px}} می باشد.تصویر افقی مجاز نمی باشد. The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed. - این عکس عمودی width }}x{{ height }}px}} می باشد.عکس عمودی مجاز نمی باشد. + این تصویر عمودی width }}x{{ height }}px}} می باشد.تصویر عمودی مجاز نمی باشد. An empty file is not allowed. - فایل خالی مجاز نمی باشد. + پرونده خالی مجاز نمی باشد. The host could not be resolved. - هاست قابل حل نیست. + میزبان قابل حل نمی باشد. This value does not match the expected {{ charset }} charset. - این مقدار مورد نظر نمی باشد. مقدار مورد نظر {{ charset }} می باشد. + این مقدار مطابق با مقدار مورد انتظار {{ charset }} نمی باشد. This is not a valid Business Identifier Code (BIC). - این مقدار یک BIC درست نیست. + این مقدار یک BIC معتبر نمی باشد. Error @@ -320,7 +320,7 @@ This is not a valid UUID. - این مقدار یک UUID درست نیست. + این مقدار یک UUID معتبر نمی باشد. This value should be a multiple of {{ compared_value }}. @@ -328,7 +328,7 @@ This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}. - این BIC با IBAN ارتباط ندارد. + این BIC با IBAN ارتباطی ندارد. From 346ce8811ed0f2e51177e2ee6ada24778445b933 Mon Sep 17 00:00:00 2001 From: Amin-Hosseini Date: Tue, 9 Jul 2019 14:02:42 +0430 Subject: [PATCH 25/26] [Translator] Improve farsi(persian) translations for Form --- .../Component/Form/Resources/translations/validators.fa.xlf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Resources/translations/validators.fa.xlf b/src/Symfony/Component/Form/Resources/translations/validators.fa.xlf index 468d2f6fdd..1c784c24a0 100644 --- a/src/Symfony/Component/Form/Resources/translations/validators.fa.xlf +++ b/src/Symfony/Component/Form/Resources/translations/validators.fa.xlf @@ -4,15 +4,15 @@ This form should not contain extra fields. - این فرم نباید فیلد اضافی داشته باشد. + این فرم نباید شامل فیلد اضافه ای باشد. The uploaded file was too large. Please try to upload a smaller file. - فایل بارگذاری شده بسیار بزرگ است. لطفا فایل کوچکتری را بارگزاری کنید. + فایل بارگذاری شده بسیار بزرگ می باشد. لطفا فایل کوچکتری را بارگذاری نمایید. The CSRF token is invalid. Please try to resubmit the form. - مقدار CSRF نامعتبر است. لطفا فرم را مجددا ارسال فرمایید.. + توکن CSRF نامعتبر می باشد. لطفا فرم را مجددا ارسال نمایید. From a9a6eb5c5802d76656f1f38f18c733eb7e69b803 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Tue, 9 Jul 2019 11:57:56 -0400 Subject: [PATCH 26/26] Fix Twig 1.x compatibility --- .../Bundle/WebProfilerBundle/Controller/ExceptionController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php index 4ae1afcf83..d5b0f5e66b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php @@ -60,7 +60,7 @@ class ExceptionController $exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException(); $template = $this->getTemplate(); - if (!$this->twig->getLoader()->exists($template)) { + if (!$this->templateExists($template)) { $handler = new ExceptionHandler($this->debug, $this->twig->getCharset(), $this->fileLinkFormat); return new Response($handler->getContent($exception), 200, ['Content-Type' => 'text/html']);