From 73e4a1a5ff15c70425fcf775f1baea873495453b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 5 Dec 2018 07:43:42 +0000 Subject: [PATCH 1/6] [Contracts] extract LocaleAwareInterface out of TranslatorInterface --- UPGRADE-4.2.md | 2 ++ .../Extension/Fixtures/StubTranslator.php | 13 -------- src/Symfony/Bridge/Twig/composer.json | 2 +- .../DataCollectorTranslatorPassTest.php | 12 ------- .../Helper/Fixtures/StubTranslator.php | 13 -------- .../Bundle/FrameworkBundle/composer.json | 3 +- .../EventListener/TranslatorListener.php | 10 +++--- .../EventListener/TranslatorListenerTest.php | 4 +-- .../Component/HttpKernel/composer.json | 2 +- .../Translation/DataCollectorTranslator.php | 5 +-- .../Translation/LoggingTranslator.php | 5 +-- .../Translation/TranslatorInterface.php | 3 +- .../Component/Translation/composer.json | 2 +- .../AddValidatorInitializersPassTest.php | 3 +- .../Validator/Util/LegacyTranslatorProxy.php | 4 +++ .../Component/Validator/ValidatorBuilder.php | 3 +- src/Symfony/Component/Validator/composer.json | 2 +- .../Translation/LocaleAwareInterface.php | 31 +++++++++++++++++++ .../Translation/TranslatorInterface.php | 16 ---------- .../Contracts/Translation/TranslatorTrait.php | 2 +- 20 files changed, 63 insertions(+), 74 deletions(-) create mode 100644 src/Symfony/Contracts/Translation/LocaleAwareInterface.php diff --git a/UPGRADE-4.2.md b/UPGRADE-4.2.md index 8d69d2c526..90cd04d01e 100644 --- a/UPGRADE-4.2.md +++ b/UPGRADE-4.2.md @@ -68,6 +68,7 @@ Finder Form ---- + * The `symfony/translation` dependency has been removed - run `composer require symfony/translation` if you need the component * The `getExtendedType()` method of the `FormTypeExtensionInterface` is deprecated and will be removed in 5.0. Type extensions must implement the static `getExtendedTypes()` method instead and return an iterable of extended types. @@ -381,6 +382,7 @@ TwigBundle Validator --------- + * The `symfony/translation` dependency has been removed - run `composer require symfony/translation` if you need the component * The `checkMX` and `checkHost` options of the `Email` constraint are deprecated * The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead * The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php index 083124d6af..bd9191161a 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php @@ -19,17 +19,4 @@ class StubTranslator implements TranslatorInterface { return '[trans]'.$id.'[/trans]'; } - - public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) - { - return '[trans]'.$id.'[/trans]'; - } - - public function setLocale($locale) - { - } - - public function getLocale() - { - } } diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index 2441cbf9fa..ec0d36a2b9 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0", + "symfony/contracts": "^1.0.2", "twig/twig": "^1.35|^2.4.4" }, "require-dev": { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php index f3e4ce9603..481500c2cb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php @@ -111,16 +111,4 @@ class TranslatorWithTranslatorBag implements TranslatorInterface public function trans($id, array $parameters = array(), $domain = null, $locale = null) { } - - public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) - { - } - - public function setLocale($locale) - { - } - - public function getLocale() - { - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php index 08c0a476b4..377a67d6be 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php @@ -19,17 +19,4 @@ class StubTranslator implements TranslatorInterface { return '[trans]'.$id.'[/trans]'; } - - public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) - { - return '[trans]'.$id.'[/trans]'; - } - - public function setLocale($locale) - { - } - - public function getLocale() - { - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index f2b85c5f0c..fa14dcc25e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -19,8 +19,9 @@ "php": "^7.1.3", "ext-xml": "*", "symfony/cache": "~4.2", - "symfony/dependency-injection": "^4.2", "symfony/config": "~4.2", + "symfony/contracts": "^1.0.2", + "symfony/dependency-injection": "^4.2", "symfony/event-dispatcher": "^4.1", "symfony/http-foundation": "^4.1.2", "symfony/http-kernel": "^4.2", diff --git a/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php b/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php index 7cf059886d..e0b344e4a8 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php @@ -17,8 +17,8 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; -use Symfony\Contracts\Translation\TranslatorInterface; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\LocaleAwareInterface; /** * Synchronizes the locale between the request and the translator. @@ -31,12 +31,12 @@ class TranslatorListener implements EventSubscriberInterface private $requestStack; /** - * @param TranslatorInterface $translator + * @param LocaleAwareInterface $translator */ public function __construct($translator, RequestStack $requestStack) { - if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) { - throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator))); + if (!$translator instanceof TranslatorInterface && !$translator instanceof LocaleAwareInterface) { + throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, LocaleAwareInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator))); } $this->translator = $translator; $this->requestStack = $requestStack; diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php index c4cb9d053b..b448f3bfd1 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php @@ -17,7 +17,7 @@ use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\EventListener\TranslatorListener; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Contracts\Translation\TranslatorInterface; +use Symfony\Contracts\Translation\LocaleAwareInterface; class TranslatorListenerTest extends TestCase { @@ -27,7 +27,7 @@ class TranslatorListenerTest extends TestCase protected function setUp() { - $this->translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); + $this->translator = $this->getMockBuilder(LocaleAwareInterface::class)->getMock(); $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock(); $this->listener = new TranslatorListener($this->translator, $this->requestStack); } diff --git a/src/Symfony/Component/HttpKernel/composer.json b/src/Symfony/Component/HttpKernel/composer.json index 8228377e04..1e5684d579 100644 --- a/src/Symfony/Component/HttpKernel/composer.json +++ b/src/Symfony/Component/HttpKernel/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0", + "symfony/contracts": "^1.0.2", "symfony/event-dispatcher": "~4.1", "symfony/http-foundation": "^4.1.1", "symfony/debug": "~3.4|~4.0", diff --git a/src/Symfony/Component/Translation/DataCollectorTranslator.php b/src/Symfony/Component/Translation/DataCollectorTranslator.php index 5e547163a3..ca6bedc71b 100644 --- a/src/Symfony/Component/Translation/DataCollectorTranslator.php +++ b/src/Symfony/Component/Translation/DataCollectorTranslator.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Translation; use Symfony\Component\Translation\Exception\InvalidArgumentException; use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; +use Symfony\Contracts\Translation\LocaleAwareInterface; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -39,8 +40,8 @@ class DataCollectorTranslator implements LegacyTranslatorInterface, TranslatorIn if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) { throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator))); } - if (!$translator instanceof TranslatorBagInterface) { - throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', \get_class($translator))); + if (!$translator instanceof TranslatorBagInterface || !$translator instanceof LocaleAwareInterface) { + throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface, TranslatorBagInterface and LocaleAwareInterface.', \get_class($translator))); } $this->translator = $translator; diff --git a/src/Symfony/Component/Translation/LoggingTranslator.php b/src/Symfony/Component/Translation/LoggingTranslator.php index 2746fcfe30..4fe756d7a7 100644 --- a/src/Symfony/Component/Translation/LoggingTranslator.php +++ b/src/Symfony/Component/Translation/LoggingTranslator.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Translation; use Psr\Log\LoggerInterface; use Symfony\Component\Translation\Exception\InvalidArgumentException; use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; +use Symfony\Contracts\Translation\LocaleAwareInterface; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -37,8 +38,8 @@ class LoggingTranslator implements TranslatorInterface, LegacyTranslatorInterfac if (!$translator instanceof LegacyTranslatorInterface && !$translator instanceof TranslatorInterface) { throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator))); } - if (!$translator instanceof TranslatorBagInterface) { - throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface and TranslatorBagInterface.', \get_class($translator))); + if (!$translator instanceof TranslatorBagInterface || !$translator instanceof LocaleAwareInterface) { + throw new InvalidArgumentException(sprintf('The Translator "%s" must implement TranslatorInterface, TranslatorBagInterface and LocaleAwareInterface.', \get_class($translator))); } $this->translator = $translator; diff --git a/src/Symfony/Component/Translation/TranslatorInterface.php b/src/Symfony/Component/Translation/TranslatorInterface.php index 02cb5027b8..3ecef054b1 100644 --- a/src/Symfony/Component/Translation/TranslatorInterface.php +++ b/src/Symfony/Component/Translation/TranslatorInterface.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Translation; use Symfony\Component\Translation\Exception\InvalidArgumentException; +use Symfony\Contracts\Translation\LocaleAwareInterface; /** * TranslatorInterface. @@ -20,7 +21,7 @@ use Symfony\Component\Translation\Exception\InvalidArgumentException; * * @deprecated since Symfony 4.2, use Symfony\Contracts\Translation\TranslatorInterface instead */ -interface TranslatorInterface +interface TranslatorInterface extends LocaleAwareInterface { /** * Translates the given message. diff --git a/src/Symfony/Component/Translation/composer.json b/src/Symfony/Component/Translation/composer.json index 29ba62ab15..7d5df73025 100644 --- a/src/Symfony/Component/Translation/composer.json +++ b/src/Symfony/Component/Translation/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0", + "symfony/contracts": "^1.0.2", "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { diff --git a/src/Symfony/Component/Validator/Tests/DependencyInjection/AddValidatorInitializersPassTest.php b/src/Symfony/Component/Validator/Tests/DependencyInjection/AddValidatorInitializersPassTest.php index 26d5e6646d..ff7e28a29e 100644 --- a/src/Symfony/Component/Validator/Tests/DependencyInjection/AddValidatorInitializersPassTest.php +++ b/src/Symfony/Component/Validator/Tests/DependencyInjection/AddValidatorInitializersPassTest.php @@ -17,6 +17,7 @@ use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass; use Symfony\Component\Validator\Util\LegacyTranslatorProxy; +use Symfony\Contracts\Translation\LocaleAwareInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorTrait; @@ -72,7 +73,7 @@ class AddValidatorInitializersPassTest extends TestCase } } -class TestTranslator implements TranslatorInterface +class TestTranslator implements TranslatorInterface, LocaleAwareInterface { use TranslatorTrait; } diff --git a/src/Symfony/Component/Validator/Util/LegacyTranslatorProxy.php b/src/Symfony/Component/Validator/Util/LegacyTranslatorProxy.php index 12f487bf2f..f87c1fbbb3 100644 --- a/src/Symfony/Component/Validator/Util/LegacyTranslatorProxy.php +++ b/src/Symfony/Component/Validator/Util/LegacyTranslatorProxy.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Validator\Util; use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface; +use Symfony\Contracts\Translation\LocaleAwareInterface; use Symfony\Contracts\Translation\TranslatorInterface; /** @@ -23,6 +24,9 @@ class LegacyTranslatorProxy implements LegacyTranslatorInterface, TranslatorInte public function __construct(TranslatorInterface $translator) { + if (!$translator instanceof LocaleAwareInterface) { + throw new \InvalidArgumentException(sprintf('The translator passed to "%s()" must implement "%s".', __METHOD__, LocaleAwareInterface::class)); + } $this->translator = $translator; } diff --git a/src/Symfony/Component/Validator/ValidatorBuilder.php b/src/Symfony/Component/Validator/ValidatorBuilder.php index 7a4b52164a..8e4de01267 100644 --- a/src/Symfony/Component/Validator/ValidatorBuilder.php +++ b/src/Symfony/Component/Validator/ValidatorBuilder.php @@ -30,6 +30,7 @@ use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader; use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader; use Symfony\Component\Validator\Util\LegacyTranslatorProxy; use Symfony\Component\Validator\Validator\RecursiveValidator; +use Symfony\Contracts\Translation\LocaleAwareInterface; use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorTrait; @@ -332,7 +333,7 @@ class ValidatorBuilder implements ValidatorBuilderInterface $translator = $this->translator; if (null === $translator) { - $translator = new class() implements TranslatorInterface { + $translator = new class() implements TranslatorInterface, LocaleAwareInterface { use TranslatorTrait; }; // Force the locale to be 'en' when no translator is provided rather than relying on the Intl default locale diff --git a/src/Symfony/Component/Validator/composer.json b/src/Symfony/Component/Validator/composer.json index 442d7c67b4..88a29241f5 100644 --- a/src/Symfony/Component/Validator/composer.json +++ b/src/Symfony/Component/Validator/composer.json @@ -17,7 +17,7 @@ ], "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0", + "symfony/contracts": "^1.0.2", "symfony/polyfill-ctype": "~1.8", "symfony/polyfill-mbstring": "~1.0" }, diff --git a/src/Symfony/Contracts/Translation/LocaleAwareInterface.php b/src/Symfony/Contracts/Translation/LocaleAwareInterface.php new file mode 100644 index 0000000000..dbd8894fe7 --- /dev/null +++ b/src/Symfony/Contracts/Translation/LocaleAwareInterface.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Contracts\Translation; + +interface LocaleAwareInterface +{ + /** + * Sets the current locale. + * + * @param string $locale The locale + * + * @throws \InvalidArgumentException If the locale contains invalid characters + */ + public function setLocale($locale); + + /** + * Returns the current locale. + * + * @return string The locale + */ + public function getLocale(); +} diff --git a/src/Symfony/Contracts/Translation/TranslatorInterface.php b/src/Symfony/Contracts/Translation/TranslatorInterface.php index 2130c1b2cf..2bdc415cbd 100644 --- a/src/Symfony/Contracts/Translation/TranslatorInterface.php +++ b/src/Symfony/Contracts/Translation/TranslatorInterface.php @@ -62,20 +62,4 @@ interface TranslatorInterface * @throws \InvalidArgumentException If the locale contains invalid characters */ public function trans($id, array $parameters = array(), $domain = null, $locale = null); - - /** - * Sets the current locale. - * - * @param string $locale The locale - * - * @throws \InvalidArgumentException If the locale contains invalid characters - */ - public function setLocale($locale); - - /** - * Returns the current locale. - * - * @return string The locale - */ - public function getLocale(); } diff --git a/src/Symfony/Contracts/Translation/TranslatorTrait.php b/src/Symfony/Contracts/Translation/TranslatorTrait.php index e19e37cfe5..4e53fbd42c 100644 --- a/src/Symfony/Contracts/Translation/TranslatorTrait.php +++ b/src/Symfony/Contracts/Translation/TranslatorTrait.php @@ -14,7 +14,7 @@ namespace Symfony\Contracts\Translation; use Symfony\Component\Translation\Exception\InvalidArgumentException; /** - * A trait to help implement TranslatorInterface. + * A trait to help implement TranslatorInterface and LocaleAwareInterface. * * @author Fabien Potencier */ From 8624cde5b06caaa186dbc6386cd3cc75fada9cc6 Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Wed, 5 Dec 2018 09:34:58 +0000 Subject: [PATCH 2/6] [DoctrineBridge] Conflict with Messenger <4.2 --- src/Symfony/Bridge/Doctrine/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index bc828b43e2..db7c8ce7a3 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -46,7 +46,8 @@ }, "conflict": { "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", - "symfony/dependency-injection": "<3.4" + "symfony/dependency-injection": "<3.4", + "symfony/messenger": "<4.2" }, "suggest": { "symfony/form": "", From 3d3b3ced487d72c28ee24f6023df34bf6b27bcb2 Mon Sep 17 00:00:00 2001 From: Fabien Bourigault Date: Wed, 5 Dec 2018 23:36:36 +0100 Subject: [PATCH 3/6] fix TransChoiceTokenParser deprecation message --- src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php index 490fb14ff4..ea605111ca 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php @@ -40,7 +40,7 @@ class TransChoiceTokenParser extends TransTokenParser $lineno = $token->getLine(); $stream = $this->parser->getStream(); - @trigger_error(sprintf('The "transchoice" tag is deprecated since Symfony 4.2, use the "trans" one instead with a "%count%" parameter in %s line %d.', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED); + @trigger_error(sprintf('The "transchoice" tag is deprecated since Symfony 4.2, use the "trans" one instead with a "%%count%%" parameter in %s line %d.', $stream->getSourceContext()->getName(), $lineno), E_USER_DEPRECATED); $vars = new ArrayExpression(array(), $lineno); From 109fee57094bbf35e8e718029bf7fe6b177bd35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Delprat?= Date: Thu, 6 Dec 2018 10:31:13 +0900 Subject: [PATCH 4/6] Fixes sprintf(): Too few arguments in Translator Similar to : https://github.com/symfony/symfony/pull/29344 --- .../Component/Translation/Formatter/MessageFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Translation/Formatter/MessageFormatter.php b/src/Symfony/Component/Translation/Formatter/MessageFormatter.php index 11f766c8cd..e36f242c89 100644 --- a/src/Symfony/Component/Translation/Formatter/MessageFormatter.php +++ b/src/Symfony/Component/Translation/Formatter/MessageFormatter.php @@ -66,7 +66,7 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf */ public function choiceFormat($message, $number, $locale, array $parameters = array()) { - @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the format() one instead with a %count% parameter.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the format() one instead with a %%count%% parameter.', __METHOD__), E_USER_DEPRECATED); $parameters = array('%count%' => $number) + $parameters; From 447baacbadc7c233bb5f6eeb1d3aa4a56dba512d Mon Sep 17 00:00:00 2001 From: Raito Akehanareru Date: Fri, 30 Nov 2018 13:50:43 +0100 Subject: [PATCH 5/6] [Cache] Fixed Memcached adapter doClear()to call flush() --- .../Component/Cache/Tests/Adapter/MemcachedAdapterTest.php | 5 +++++ src/Symfony/Component/Cache/Traits/MemcachedTrait.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php index 59d28a33c1..1f2f4d40ac 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php @@ -192,4 +192,9 @@ class MemcachedAdapterTest extends AdapterTestCase array(\Memcached::OPT_SOCKET_RECV_SIZE => 1, \Memcached::OPT_SOCKET_SEND_SIZE => 2, \Memcached::OPT_RETRY_TIMEOUT => 8), ); } + + public function testClear() + { + $this->assertTrue($this->createCachePool()->clear()); + } } diff --git a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php index cf04f1cf85..8160f14116 100644 --- a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php +++ b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php @@ -260,7 +260,7 @@ trait MemcachedTrait */ protected function doClear($namespace) { - return false; + return '' === $namespace && $this->getClient()->flush(); } private function checkResultCode($result) From 96169b804614c58b6247adbafc5ae3b143f117f2 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Wed, 5 Dec 2018 17:42:17 -0500 Subject: [PATCH 6/6] [TwigBridge] Deprecating legacy Twig paths in DebugCommand and simplifications --- .../Bridge/Twig/Command/DebugCommand.php | 75 +++++++------------ .../Twig/Tests/Command/DebugCommandTest.php | 50 ++++++++++++- .../Resources/BarBundle/views/base.html.twig | 0 .../bundles/UnknownBundle/base.html.twig | 0 .../WebProfileBundle/Profiler/base.html.twig | 0 5 files changed, 75 insertions(+), 50 deletions(-) create mode 100644 src/Symfony/Bridge/Twig/Tests/Fixtures/Resources/BarBundle/views/base.html.twig create mode 100644 src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/UnknownBundle/base.html.twig create mode 100644 src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/WebProfileBundle/Profiler/base.html.twig diff --git a/src/Symfony/Bridge/Twig/Command/DebugCommand.php b/src/Symfony/Bridge/Twig/Command/DebugCommand.php index 072022c0a4..e9d9eda30e 100644 --- a/src/Symfony/Bridge/Twig/Command/DebugCommand.php +++ b/src/Symfony/Bridge/Twig/Command/DebugCommand.php @@ -208,8 +208,8 @@ EOF $io->table(array('Namespace', 'Paths'), $this->buildTableRows($paths)); } - if ($wronBundles = $this->findWrongBundleOverrides()) { - foreach ($this->buildWarningMessages($wronBundles) as $message) { + if ($wrongBundles = $this->findWrongBundleOverrides()) { + foreach ($this->buildWarningMessages($wrongBundles) as $message) { $io->warning($message); } } @@ -253,13 +253,7 @@ EOF } foreach ($namespaces as $namespace) { - $paths = array_map(function ($path) { - if (null !== $this->projectDir && 0 === strpos($path, $this->projectDir)) { - $path = ltrim(substr($path, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); - } - - return $path; - }, $loader->getPaths($namespace)); + $paths = array_map(array($this, 'getRelativePath'), $loader->getPaths($namespace)); if (FilesystemLoader::MAIN_NAMESPACE === $namespace) { $namespace = '(None)'; @@ -368,53 +362,38 @@ EOF if ($this->rootDir && $this->projectDir) { $folders = glob($this->rootDir.'/Resources/*/views', GLOB_ONLYDIR); - $relativePath = ltrim(substr($this->rootDir.'/Resources/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); - $bundleNames = array_reduce( - $folders, - function ($carry, $absolutePath) use ($relativePath) { - if (0 === strpos($absolutePath, $this->projectDir)) { - $name = basename(\dirname($absolutePath)); - $path = $relativePath.$name; - $carry[$name] = $path; - } + $relativePath = ltrim(substr($this->rootDir.\DIRECTORY_SEPARATOR.'Resources/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); + $bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) { + if (0 === strpos($absolutePath, $this->projectDir)) { + $name = basename(\dirname($absolutePath)); + $path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR); + $carry[$name] = $path; - return $carry; - }, - $bundleNames - ); + @trigger_error(sprintf('Templates directory "%s" is deprecated since Symfony 4.2, use "%s" instead.', $absolutePath, $this->twigDefaultPath.'/bundles/'.$name), E_USER_DEPRECATED); + } + + return $carry; + }, $bundleNames); } if ($this->twigDefaultPath && $this->projectDir) { $folders = glob($this->twigDefaultPath.'/bundles/*', GLOB_ONLYDIR); - $relativePath = ltrim(substr($this->twigDefaultPath.'/bundles', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); - $bundleNames = array_reduce( - $folders, - function ($carry, $absolutePath) use ($relativePath) { - if (0 === strpos($absolutePath, $this->projectDir)) { - $path = ltrim(substr($absolutePath, \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); - $name = ltrim(substr($path, \strlen($relativePath)), \DIRECTORY_SEPARATOR); - $carry[$name] = $path; - } + $relativePath = ltrim(substr($this->twigDefaultPath.'/bundles/', \strlen($this->projectDir)), \DIRECTORY_SEPARATOR); + $bundleNames = array_reduce($folders, function ($carry, $absolutePath) use ($relativePath) { + if (0 === strpos($absolutePath, $this->projectDir)) { + $name = basename($absolutePath); + $path = ltrim($relativePath.$name, \DIRECTORY_SEPARATOR); + $carry[$name] = $path; + } - return $carry; - }, - $bundleNames - ); + return $carry; + }, $bundleNames); } - if (\count($bundleNames)) { - $notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata); - if (\count($notFoundBundles)) { - $alternatives = array(); - foreach ($notFoundBundles as $notFoundBundle => $path) { - $alternatives[$path] = array(); - foreach ($this->bundlesMetadata as $name => $bundle) { - $lev = levenshtein($notFoundBundle, $name); - if ($lev <= \strlen($notFoundBundle) / 3 || false !== strpos($name, $notFoundBundle)) { - $alternatives[$path][] = $name; - } - } - } + if ($notFoundBundles = array_diff_key($bundleNames, $this->bundlesMetadata)) { + $alternatives = array(); + foreach ($notFoundBundles as $notFoundBundle => $path) { + $alternatives[$path] = $this->findAlternatives($notFoundBundle, array_keys($this->bundlesMetadata)); } } diff --git a/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php b/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php index ed3fea871e..e648a52d84 100644 --- a/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Command/DebugCommandTest.php @@ -42,6 +42,52 @@ class DebugCommandTest extends TestCase $this->assertEquals($expected, json_decode($tester->getDisplay(true), true)); } + public function testWarningsWrongBundleOverriding() + { + $bundleMetadata = array( + 'TwigBundle' => 'vendor/twig-bundle/', + 'WebProfilerBundle' => 'vendor/web-profiler-bundle/', + ); + $defaultPath = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'templates'; + + $tester = $this->createCommandTester(array(), $bundleMetadata, $defaultPath); + $ret = $tester->execute(array('--filter' => 'unknown', '--format' => 'json'), array('decorated' => false)); + + $expected = array('warnings' => array( + 'Path "templates/bundles/UnknownBundle" not matching any bundle found', + 'Path "templates/bundles/WebProfileBundle" not matching any bundle found, did you mean "WebProfilerBundle"?', + )); + + $this->assertEquals(0, $ret, 'Returns 0 in case of success'); + $this->assertEquals($expected, json_decode($tester->getDisplay(true), true)); + } + + /** + * @group legacy + * @expectedDeprecation Templates directory "%sResources/BarBundle/views" is deprecated since Symfony 4.2, use "%stemplates/bundles/BarBundle" instead. + */ + public function testDeprecationForWrongBundleOverridingInLegacyPath() + { + $bundleMetadata = array( + 'TwigBundle' => 'vendor/twig-bundle/', + 'WebProfilerBundle' => 'vendor/web-profiler-bundle/', + ); + $defaultPath = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'templates'; + $rootDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'; + + $tester = $this->createCommandTester(array(), $bundleMetadata, $defaultPath, $rootDir); + $ret = $tester->execute(array('--filter' => 'unknown', '--format' => 'json'), array('decorated' => false)); + + $expected = array('warnings' => array( + 'Path "Resources/BarBundle" not matching any bundle found', + 'Path "templates/bundles/UnknownBundle" not matching any bundle found', + 'Path "templates/bundles/WebProfileBundle" not matching any bundle found, did you mean "WebProfilerBundle"?', + )); + + $this->assertEquals(0, $ret, 'Returns 0 in case of success'); + $this->assertEquals($expected, json_decode($tester->getDisplay(true), true)); + } + /** * @expectedException \Symfony\Component\Console\Exception\InvalidArgumentException * @expectedExceptionMessage Malformed namespaced template name "@foo" (expecting "@namespace/template_name"). @@ -233,7 +279,7 @@ TXT ); } - private function createCommandTester(array $paths = array()): CommandTester + private function createCommandTester(array $paths = array(), array $bundleMetadata = array(), string $defaultPath = null, string $rootDir = null): CommandTester { $projectDir = \dirname(__DIR__).\DIRECTORY_SEPARATOR.'Fixtures'; $loader = new FilesystemLoader(array(), $projectDir); @@ -246,7 +292,7 @@ TXT } $application = new Application(); - $application->add(new DebugCommand(new Environment($loader), $projectDir)); + $application->add(new DebugCommand(new Environment($loader), $projectDir, $bundleMetadata, $defaultPath, $rootDir)); $command = $application->find('debug:twig'); return new CommandTester($command); diff --git a/src/Symfony/Bridge/Twig/Tests/Fixtures/Resources/BarBundle/views/base.html.twig b/src/Symfony/Bridge/Twig/Tests/Fixtures/Resources/BarBundle/views/base.html.twig new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/UnknownBundle/base.html.twig b/src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/UnknownBundle/base.html.twig new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/WebProfileBundle/Profiler/base.html.twig b/src/Symfony/Bridge/Twig/Tests/Fixtures/templates/bundles/WebProfileBundle/Profiler/base.html.twig new file mode 100644 index 0000000000..e69de29bb2