Skip to content

Commit 00ea207

Browse files
[Contracts] Add Translation\TranslatorInterface + decouple symfony/validator from symfony/translation
1 parent f0168e3 commit 00ea207

File tree

57 files changed

+909
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+909
-208
lines changed

UPGRADE-4.2.md

+12
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,15 @@ Serializer
117117

118118
* Relying on the default value (false) of the "as_collection" option is deprecated since 4.2.
119119
You should set it to false explicitly instead as true will be the default value in 5.0.
120+
121+
Translation
122+
-----------
123+
124+
* The `TranslationInterface` has been deprecated in favor of `Symfony\Contracts\Translation\TranslationInterface`
125+
* The `MessageSelector`, `Interval` and `PluralizationRules` classes have been deprecated, use `IdentityTranslator` instead
126+
127+
Validator
128+
---------
129+
130+
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
131+
* The `ValidatorBuilderInterface` has been deprecated and `ValidatorBuilder` made final

UPGRADE-5.0.md

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ Translation
145145

146146
* The `FileDumper::setBackup()` method has been removed.
147147
* The `TranslationWriter::disableBackup()` method has been removed.
148+
* The `TranslationInterface` has been removed in favor of `Symfony\Contracts\Translation\TranslationInterface`
149+
* The `MessageSelector`, `Interval` and `PluralizationRules` classes have been removed, use `IdentityTranslator` instead
148150

149151
TwigBundle
150152
----------
@@ -157,6 +159,8 @@ Validator
157159
* The `Email::__construct()` 'strict' property has been removed. Use 'mode'=>"strict" instead.
158160
* Calling `EmailValidator::__construct()` method with a boolean parameter has been removed, use `EmailValidator("strict")` instead.
159161
* Removed the `checkDNS` and `dnsMessage` options from the `Url` constraint.
162+
* The component is now decoupled from `symfony/translation` and uses `Symfony\Contracts\Translation\TranslatorInterface` instead
163+
* The `ValidatorBuilderInterface` has been removed and `ValidatorBuilder` is now final
160164

161165
Workflow
162166
--------

src/Symfony/Bridge/Twig/Extension/TranslationExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Bridge\Twig\TokenParser\TransChoiceTokenParser;
1717
use Symfony\Bridge\Twig\TokenParser\TransDefaultDomainTokenParser;
1818
use Symfony\Bridge\Twig\TokenParser\TransTokenParser;
19-
use Symfony\Component\Translation\TranslatorInterface;
19+
use Symfony\Contracts\Translation\TranslatorInterface;
2020
use Twig\Extension\AbstractExtension;
2121
use Twig\NodeVisitor\NodeVisitorInterface;
2222
use Twig\TokenParser\AbstractTokenParser;

src/Symfony/Bridge/Twig/Tests/Extension/Fixtures/StubTranslator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Twig\Tests\Extension\Fixtures;
1313

14-
use Symfony\Component\Translation\TranslatorInterface;
14+
use Symfony\Contracts\Translation\TranslatorInterface;
1515

1616
class StubTranslator implements TranslatorInterface
1717
{

src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Bridge\Twig\Extension\TranslationExtension;
1616
use Symfony\Bridge\Twig\Translation\TwigExtractor;
1717
use Symfony\Component\Translation\MessageCatalogue;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1819
use Twig\Environment;
1920
use Twig\Error\Error;
2021
use Twig\Loader\ArrayLoader;
@@ -33,7 +34,7 @@ public function testExtract($template, $messages)
3334
'cache' => false,
3435
'autoescape' => false,
3536
));
36-
$twig->addExtension(new TranslationExtension($this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock()));
37+
$twig->addExtension(new TranslationExtension($this->getMockBuilder(TranslatorInterface::class)->getMock()));
3738

3839
$extractor = new TwigExtractor($twig);
3940
$extractor->setPrefix('prefix');
@@ -82,7 +83,7 @@ public function getExtractData()
8283
public function testExtractSyntaxError($resources)
8384
{
8485
$twig = new Environment($this->getMockBuilder('Twig\Loader\LoaderInterface')->getMock());
85-
$twig->addExtension(new TranslationExtension($this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock()));
86+
$twig->addExtension(new TranslationExtension($this->getMockBuilder(TranslatorInterface::class)->getMock()));
8687

8788
$extractor = new TwigExtractor($twig);
8889

@@ -124,7 +125,7 @@ public function testExtractWithFiles($resource)
124125
'cache' => false,
125126
'autoescape' => false,
126127
));
127-
$twig->addExtension(new TranslationExtension($this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock()));
128+
$twig->addExtension(new TranslationExtension($this->getMockBuilder(TranslatorInterface::class)->getMock()));
128129

129130
$extractor = new TwigExtractor($twig);
130131
$catalogue = new MessageCatalogue('en');

src/Symfony/Bridge/Twig/composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"symfony/polyfill-intl-icu": "~1.0",
3030
"symfony/routing": "~3.4|~4.0",
3131
"symfony/templating": "~3.4|~4.0",
32-
"symfony/translation": "~3.4|~4.0",
32+
"symfony/translation": "~4.2",
3333
"symfony/yaml": "~3.4|~4.0",
3434
"symfony/security": "~3.4|~4.0",
3535
"symfony/security-acl": "~2.8|~3.0",
@@ -41,8 +41,9 @@
4141
"symfony/workflow": "~3.4|~4.0"
4242
},
4343
"conflict": {
44+
"symfony/console": "<3.4",
4445
"symfony/form": "<4.1.2",
45-
"symfony/console": "<3.4"
46+
"symfony/translation": "<4.2"
4647
},
4748
"suggest": {
4849
"symfony/finder": "",

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TranslationsCacheWarmer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
1616
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1717
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
18-
use Symfony\Component\Translation\TranslatorInterface;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1919

2020
/**
2121
* Generates the catalogues for translations.

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use Symfony\Component\Translation\MessageCatalogue;
2727
use Symfony\Component\Translation\Reader\TranslationReaderInterface;
2828
use Symfony\Component\Translation\Translator;
29-
use Symfony\Component\Translation\TranslatorInterface;
29+
use Symfony\Contracts\Translation\TranslatorInterface;
3030

3131
/**
3232
* Helps finding unused or missing translation messages in a given locale

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1717
use Symfony\Component\Translation\TranslatorBagInterface;
18-
use Symfony\Component\Translation\TranslatorInterface;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1919

2020
/**
2121
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
use Symfony\Component\Stopwatch\Stopwatch;
9292
use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand;
9393
use Symfony\Component\Translation\Translator;
94+
use Symfony\Component\Translation\Util\XliffUtils;
9495
use Symfony\Component\Validator\ConstraintValidatorInterface;
9596
use Symfony\Component\Validator\ObjectInitializerInterface;
9697
use Symfony\Component\WebLink\HttpHeaderSerializer;
@@ -966,6 +967,10 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
966967

967968
$loader->load('translation.xml');
968969

970+
if (!\class_exists(XliffUtils::class)) {
971+
$container->getDefinition('translator.formatter.default')->replaceArgument(0, new Reference('translator.selector'));
972+
}
973+
969974
// Use the "real" translator instead of the identity default
970975
$container->setAlias('translator', 'translator.default')->setPublic(true);
971976
$container->setAlias('translator.formatter', new Alias($config['formatter'], false));

src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.xml

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
<services>
77
<defaults public="false" />
88

9-
<service id="translator" class="Symfony\Component\Translation\IdentityTranslator" public="true">
10-
<argument type="service" id="translator.selector" />
11-
</service>
9+
<service id="translator" class="Symfony\Component\Translation\IdentityTranslator" public="true" />
1210
<service id="Symfony\Component\Translation\TranslatorInterface" alias="translator" />
11+
<service id="Symfony\Contracts\Translation\TranslatorInterface" alias="translator" />
1312

14-
<service id="translator.selector" class="Symfony\Component\Translation\MessageSelector" />
13+
<service id="identity_translator" class="Symfony\Component\Translation\IdentityTranslator" />
14+
<service id="translator.selector" class="Symfony\Component\Translation\MessageSelector">
15+
<deprecated>The "%service_id%" service is deprecated since Symfony 4.2, use "identity_translator" instead.</deprecated>
16+
</service>
1517
</services>
1618
</container>

src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
</call>
2222
</service>
2323
<service id="Symfony\Component\Translation\TranslatorInterface" alias="translator" />
24+
<service id="Symfony\Contracts\Translation\TranslatorInterface" alias="translator" />
2425

2526
<service id="translator.logging" class="Symfony\Component\Translation\LoggingTranslator">
2627
<argument type="service" id="translator.logging.inner" />
@@ -29,7 +30,7 @@
2930
</service>
3031

3132
<service id="translator.formatter.default" class="Symfony\Component\Translation\Formatter\MessageFormatter">
32-
<argument type="service" id="translator.selector" />
33+
<argument type="service" id="identity_translator" />
3334
</service>
3435

3536
<service id="translation.loader.php" class="Symfony\Component\Translation\Loader\PhpFileLoader">

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/TranslatorHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
1313

1414
use Symfony\Component\Templating\Helper\Helper;
15-
use Symfony\Component\Translation\TranslatorInterface;
15+
use Symfony\Contracts\Translation\TranslatorInterface;
1616

1717
/**
1818
* @author Fabien Potencier <fabien@symfony.com>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Reference;
18-
use Symfony\Component\Translation\TranslatorInterface;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1919

2020
class DataCollectorTranslatorPassTest extends TestCase
2121
{

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/Fixtures/StubTranslator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures;
1313

14-
use Symfony\Component\Translation\TranslatorInterface;
14+
use Symfony\Contracts\Translation\TranslatorInterface;
1515

1616
class StubTranslator implements TranslatorInterface
1717
{

src/Symfony/Bundle/FrameworkBundle/composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"symfony/security-csrf": "~3.4|~4.0",
4848
"symfony/serializer": "^4.1",
4949
"symfony/stopwatch": "~3.4|~4.0",
50-
"symfony/translation": "~3.4|~4.0",
50+
"symfony/translation": "~4.2",
5151
"symfony/templating": "~3.4|~4.0",
5252
"symfony/validator": "^4.1",
5353
"symfony/var-dumper": "~3.4|~4.0",
@@ -70,7 +70,7 @@
7070
"symfony/property-info": "<3.4",
7171
"symfony/serializer": "<4.1",
7272
"symfony/stopwatch": "<3.4",
73-
"symfony/translation": "<3.4",
73+
"symfony/translation": "<4.2",
7474
"symfony/twig-bridge": "<4.1.1",
7575
"symfony/validator": "<4.1",
7676
"symfony/workflow": "<4.1"

src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2020
use Symfony\Component\DependencyInjection\Reference;
2121
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
22+
use Symfony\Contracts\Translation\TranslatorInterface;
2223
use Twig\Extension\ExtensionInterface;
2324
use Twig\Extension\RuntimeExtensionInterface;
2425
use Twig\Loader\LoaderInterface;
@@ -48,7 +49,7 @@ public function load(array $configs, ContainerBuilder $container)
4849
$loader->load('console.xml');
4950
}
5051

51-
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
52+
if (!interface_exists(TranslatorInterface::class)) {
5253
$container->removeDefinition('twig.translation.extractor');
5354
}
5455

src/Symfony/Bundle/TwigBundle/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
},
4242
"conflict": {
4343
"symfony/dependency-injection": "<4.1",
44-
"symfony/framework-bundle": "<4.1"
44+
"symfony/framework-bundle": "<4.1",
45+
"symfony/translation": "<4.2"
4546
},
4647
"autoload": {
4748
"psr-4": { "Symfony\\Bundle\\TwigBundle\\": "" },

src/Symfony/Component/Form/Extension/Csrf/CsrfExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Form\AbstractExtension;
1515
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
16-
use Symfony\Component\Translation\TranslatorInterface;
16+
use Symfony\Contracts\Translation\TranslatorInterface;
1717

1818
/**
1919
* This extension protects forms by using a CSRF token.

src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Form\Util\ServerParams;
1919
use Symfony\Component\Security\Csrf\CsrfToken;
2020
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
21-
use Symfony\Component\Translation\TranslatorInterface;
21+
use Symfony\Contracts\Translation\TranslatorInterface;
2222

2323
/**
2424
* @author Bernhard Schussek <bschussek@gmail.com>

src/Symfony/Component/Form/Extension/Csrf/Type/FormTypeCsrfExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Symfony\Component\Form\Util\ServerParams;
2020
use Symfony\Component\OptionsResolver\OptionsResolver;
2121
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
22-
use Symfony\Component\Translation\TranslatorInterface;
22+
use Symfony\Contracts\Translation\TranslatorInterface;
2323

2424
/**
2525
* @author Bernhard Schussek <bschussek@gmail.com>

src/Symfony/Component/Form/Extension/Validator/Type/UploadValidatorExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\Component\Form\AbstractTypeExtension;
1515
use Symfony\Component\OptionsResolver\Options;
1616
use Symfony\Component\OptionsResolver\OptionsResolver;
17-
use Symfony\Component\Translation\TranslatorInterface;
17+
use Symfony\Contracts\Translation\TranslatorInterface;
1818

1919
/**
2020
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>

src/Symfony/Component/Form/Tests/Extension/Csrf/Type/FormTypeCsrfExtensionTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Symfony\Component\Form\FormError;
1818
use Symfony\Component\Form\Test\TypeTestCase;
1919
use Symfony\Component\Security\Csrf\CsrfToken;
20+
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
21+
use Symfony\Contracts\Translation\TranslatorInterface;
2022

2123
class FormTypeCsrfExtensionTest_ChildType extends AbstractType
2224
{
@@ -42,8 +44,8 @@ class FormTypeCsrfExtensionTest extends TypeTestCase
4244

4345
protected function setUp()
4446
{
45-
$this->tokenManager = $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock();
46-
$this->translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock();
47+
$this->tokenManager = $this->getMockBuilder(CsrfTokenManagerInterface::class)->getMock();
48+
$this->translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
4749

4850
parent::setUp();
4951
}

src/Symfony/Component/Form/Tests/Extension/Validator/Type/UploadValidatorExtensionTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
use Symfony\Component\Form\Test\TypeTestCase;
1616
use Symfony\Component\OptionsResolver\Options;
1717
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
1819

1920
class UploadValidatorExtensionTest extends TypeTestCase
2021
{
2122
public function testPostMaxSizeTranslation()
2223
{
23-
$translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock();
24+
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
2425

2526
$translator->expects($this->any())
2627
->method('trans')

src/Symfony/Component/Form/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"symfony/http-foundation": "~3.4|~4.0",
3434
"symfony/http-kernel": "~3.4|~4.0",
3535
"symfony/security-csrf": "~3.4|~4.0",
36-
"symfony/translation": "~3.4|~4.0",
36+
"symfony/translation": "~4.2",
3737
"symfony/var-dumper": "~3.4|~4.0"
3838
},
3939
"conflict": {
@@ -42,6 +42,7 @@
4242
"symfony/doctrine-bridge": "<3.4",
4343
"symfony/framework-bundle": "<3.4",
4444
"symfony/http-kernel": "<3.4",
45+
"symfony/translation": "<4.2",
4546
"symfony/twig-bridge": "<3.4.5|<4.0.5,>=4.0"
4647
},
4748
"suggest": {

src/Symfony/Component/HttpKernel/EventListener/TranslatorListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1818
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1919
use Symfony\Component\HttpKernel\KernelEvents;
20-
use Symfony\Component\Translation\TranslatorInterface;
20+
use Symfony\Contracts\Translation\TranslatorInterface;
2121

2222
/**
2323
* Synchronizes the locale between the request and the translator.

src/Symfony/Component/HttpKernel/Tests/EventListener/TranslatorListenerTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1818
use Symfony\Component\HttpKernel\EventListener\TranslatorListener;
1919
use Symfony\Component\HttpKernel\HttpKernelInterface;
20+
use Symfony\Contracts\Translation\TranslatorInterface;
2021

2122
class TranslatorListenerTest extends TestCase
2223
{
@@ -26,7 +27,7 @@ class TranslatorListenerTest extends TestCase
2627

2728
protected function setUp()
2829
{
29-
$this->translator = $this->getMockBuilder('Symfony\Component\Translation\TranslatorInterface')->getMock();
30+
$this->translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
3031
$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
3132
$this->listener = new TranslatorListener($this->translator, $this->requestStack);
3233
}

src/Symfony/Component/HttpKernel/composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"symfony/routing": "~3.4|~4.0",
3838
"symfony/stopwatch": "~3.4|~4.0",
3939
"symfony/templating": "~3.4|~4.0",
40-
"symfony/translation": "~3.4|~4.0",
40+
"symfony/translation": "~4.2",
4141
"symfony/var-dumper": "^4.1.1",
4242
"psr/cache": "~1.0"
4343
},
@@ -47,6 +47,7 @@
4747
"conflict": {
4848
"symfony/config": "<3.4",
4949
"symfony/dependency-injection": "<4.2",
50+
"symfony/translation": "<4.2",
5051
"symfony/var-dumper": "<4.1.1",
5152
"twig/twig": "<1.34|<2.4,>=2"
5253
},

0 commit comments

Comments
 (0)