From ff02e83138aa7131e7fa8bf5ccd2230e6721cc58 Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Wed, 13 Dec 2017 00:00:05 +0200 Subject: [PATCH 01/26] Add Symfony 4 support --- composer.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 18130fe9..4fd43bb1 100644 --- a/composer.json +++ b/composer.json @@ -11,11 +11,11 @@ ], "require": { "php": "^5.5 || ^7.0", - "symfony/framework-bundle": "^2.7 || ^3.0", - "symfony/validator": "^2.7 || ^3.0", - "symfony/translation": "^2.7 || ^3.0", - "symfony/finder": "^2.7 || ^3.0", - "symfony/intl": "^2.7 || ^3.0", + "symfony/framework-bundle": "^2.7 || ^3.0 || ^4.0", + "symfony/validator": "^2.7 || ^3.0 || ^4.0", + "symfony/translation": "^2.7 || ^3.0 || ^4.0", + "symfony/finder": "^2.7 || ^3.0 || ^4.0", + "symfony/intl": "^2.7 || ^3.0 || ^4.0", "php-translation/common": "^0.2.1", "php-translation/symfony-storage": "^0.3.2", @@ -27,13 +27,13 @@ "php-http/curl-client": "^1.7", "php-http/message": "^1.6", "php-http/message-factory": "^1.0.2", - "symfony/console": "^2.7 || ^3.0", - "symfony/twig-bundle": "^2.7 || ^3.0", - "symfony/twig-bridge": "^2.7 || ^3.0", - "symfony/asset": "^2.7 || ^3.0", - "symfony/templating": "^2.7 || ^3.0", - "symfony/dependency-injection": "^2.7 || ^3.0", - "symfony/web-profiler-bundle": "^2.7 || ^3.0", + "symfony/console": "^2.7 || ^3.0 || ^4.0", + "symfony/twig-bundle": "^2.7 || ^3.0 || ^4.0", + "symfony/twig-bridge": "^2.7 || ^3.0 || ^4.0", + "symfony/asset": "^2.7 || ^3.0 || ^4.0", + "symfony/templating": "^2.7 || ^3.0 || ^4.0", + "symfony/dependency-injection": "^2.7 || ^3.0 || ^4.0", + "symfony/web-profiler-bundle": "^2.7 || ^3.0 || ^4.0", "matthiasnoback/symfony-dependency-injection-test": "^1.0 || ^2.0", "guzzlehttp/psr7": "^1.4", "nyholm/nsa": "^1.1", From 24882e43a25788ee81f99f5b30226ba778a7b2ad Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 13 Dec 2017 10:17:01 +0200 Subject: [PATCH 02/26] Use ChildDefinition instead of DefinitionDecorator --- DependencyInjection/TranslationExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index b2072e36..dfb52580 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\DefinitionDecorator; +use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -105,7 +105,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config) /* * Configure storage chain service */ - $storageDefinition = new DefinitionDecorator('php_translation.storage.abstract'); + $storageDefinition = new ChildDefinition('php_translation.storage.abstract'); $storageDefinition->replaceArgument(2, new Reference($configurationServiceId)); $container->setDefinition('php_translation.storage.'.$name, $storageDefinition); @@ -121,7 +121,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config) continue; } - $def = new DefinitionDecorator($serviceId); + $def = new ChildDefinition($serviceId); $def->replaceArgument(2, [$c['output_dir']]) ->replaceArgument(3, [$c['local_file_storage_options']]) ->addTag('php_translation.storage', ['type' => 'local', 'name' => $name]); From a16f91605c8c1559026623b3868afa880d46184b Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 13 Dec 2017 11:00:08 +0200 Subject: [PATCH 03/26] Make some services public and fix deprecated class calls --- Catalogue/CatalogueFetcher.php | 14 +++++++------- Command/ExtractCommand.php | 2 +- Resources/config/edit_in_place.yml | 1 + Resources/config/services.yml | 10 +++++++++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Catalogue/CatalogueFetcher.php b/Catalogue/CatalogueFetcher.php index 4f5c954e..717f1c62 100644 --- a/Catalogue/CatalogueFetcher.php +++ b/Catalogue/CatalogueFetcher.php @@ -11,8 +11,8 @@ namespace Translation\Bundle\Catalogue; -use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader; use Symfony\Component\Translation\MessageCatalogue; +use Symfony\Component\Translation\Reader\TranslationReader; use Translation\Bundle\Model\Configuration; /** @@ -26,16 +26,16 @@ final class CatalogueFetcher { /** - * @var TranslationLoader + * @var TranslationReader */ - private $loader; + private $reader; /** - * @param TranslationLoader $loader + * @param TranslationReader $reader */ - public function __construct(TranslationLoader $loader) + public function __construct(TranslationReader $reader) { - $this->loader = $loader; + $this->reader = $reader; } /** @@ -57,7 +57,7 @@ public function getCatalogues(Configuration $config, array $locales = []) $currentCatalogue = new MessageCatalogue($locale); foreach ($dirs as $path) { if (is_dir($path)) { - $this->loader->loadMessages($path, $currentCatalogue); + $this->reader->read($path, $currentCatalogue); } } $catalogues[] = $currentCatalogue; diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 50a0d3ff..6b8b4935 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -39,7 +39,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); - $importer = $container->get('php_translation.importer'); + $importer = $container->get('test.php_translation.importer'); $config = $container->get('php_translation.configuration_manager') ->getConfiguration($input->getArgument('configuration')); diff --git a/Resources/config/edit_in_place.yml b/Resources/config/edit_in_place.yml index 6d89c949..c8a779be 100644 --- a/Resources/config/edit_in_place.yml +++ b/Resources/config/edit_in_place.yml @@ -11,6 +11,7 @@ services: - ~ php_translation.edit_in_place.activator: + public: true class: Translation\Bundle\EditInPlace\Activator arguments: ['@session'] diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 4cb140f8..c4e9a842 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,9 +1,11 @@ services: php_translation.catalogue_fetcher: + public: true class: Translation\Bundle\Catalogue\CatalogueFetcher - arguments: ["@translation.loader"] + arguments: ["@translation.reader"] php_translation.catalogue_writer: + public: true class: Translation\Bundle\Catalogue\CatalogueWriter arguments: ["@translation.writer", "%php_translation.default_locale%"] @@ -19,12 +21,17 @@ services: class: Translation\Extractor\Extractor php_translation.configuration_manager: + public: true class: Translation\Bundle\Service\ConfigurationManager php_translation.importer: class: Translation\Bundle\Service\Importer arguments: ["@php_translation.extractor"] + test.php_translation.importer: + public: true + alias: 'php_translation.importer' + php_translation.local_file_storage.abstract: class: Translation\SymfonyStorage\FileStorage abstract: true @@ -41,5 +48,6 @@ services: - { name: translation.dumper, alias: xlf, legacy-alias: xliff } php_translation.catalogue_counter: + public: true class: Translation\Bundle\Catalogue\CatalogueCounter arguments: [] From 6fb34297f64e82ecefa97f621d879cc3e46c7215 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 13 Dec 2017 11:13:50 +0200 Subject: [PATCH 04/26] Fix more tests --- DependencyInjection/TranslationExtension.php | 1 + Resources/config/services.yml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index dfb52580..87d1f66a 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -107,6 +107,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config) */ $storageDefinition = new ChildDefinition('php_translation.storage.abstract'); $storageDefinition->replaceArgument(2, new Reference($configurationServiceId)); + $storageDefinition->setPublic(true); $container->setDefinition('php_translation.storage.'.$name, $storageDefinition); // Add storages diff --git a/Resources/config/services.yml b/Resources/config/services.yml index c4e9a842..66751b9f 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -15,6 +15,7 @@ services: arguments: ["@php_translation.catalogue_fetcher", "@php_translation.catalogue_writer", ~] php_translation.catalogue_manager: + public: true class: Translation\Bundle\Catalogue\CatalogueManager php_translation.extractor: @@ -35,7 +36,8 @@ services: php_translation.local_file_storage.abstract: class: Translation\SymfonyStorage\FileStorage abstract: true - arguments: ["@translation.writer", "@translation.loader", ~, []] + # TODO Update Translation\SymfonyStorage\FileStorage, the 2nd arg should be @translation.reader instead of translation.reader + arguments: ["@translation.writer", "@translation.reader", ~, []] php_translation.storage.xlf_loader: class: Translation\SymfonyStorage\Loader\XliffLoader From 1c4e527ebb580d502c2a27bc9561420ca18bc5ed Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Sat, 16 Dec 2017 12:30:31 +0200 Subject: [PATCH 05/26] Fix remaining tests: Make more services public --- DependencyInjection/TranslationExtension.php | 3 ++- Resources/config/extractors.yml | 2 ++ Resources/config/services.yml | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 87d1f66a..e55a5723 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -11,6 +11,7 @@ namespace Translation\Bundle\DependencyInjection; +use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -132,7 +133,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config) if ($first !== null) { // Create some aliases for the default storage - $container->setAlias('php_translation.storage', 'php_translation.storage.'.$first); + $container->setAlias('php_translation.storage', new Alias('php_translation.storage.'.$first, true)); if ($first !== 'default') { $container->setAlias('php_translation.storage.default', 'php_translation.storage.'.$first); } diff --git a/Resources/config/extractors.yml b/Resources/config/extractors.yml index efb9c280..762cfb83 100644 --- a/Resources/config/extractors.yml +++ b/Resources/config/extractors.yml @@ -1,10 +1,12 @@ services: php_translation.extractor.php: + public: true class: Translation\Extractor\FileExtractor\PHPFileExtractor tags: - { name: 'php_translation.extractor', type: 'php' } php_translation.extractor.twig: + public: true class: Translation\Extractor\FileExtractor\TwigFileExtractor arguments: ["@twig"] tags: diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 66751b9f..beae032b 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -19,6 +19,7 @@ services: class: Translation\Bundle\Catalogue\CatalogueManager php_translation.extractor: + public: true class: Translation\Extractor\Extractor php_translation.configuration_manager: @@ -36,7 +37,6 @@ services: php_translation.local_file_storage.abstract: class: Translation\SymfonyStorage\FileStorage abstract: true - # TODO Update Translation\SymfonyStorage\FileStorage, the 2nd arg should be @translation.reader instead of translation.reader arguments: ["@translation.writer", "@translation.reader", ~, []] php_translation.storage.xlf_loader: From 7391edc8b491e8ee5f12b53201e0be6134238a36 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 21 Dec 2017 12:35:47 +0200 Subject: [PATCH 06/26] Call write() when exists instead of deprecated writeTranslations() --- Catalogue/CatalogueWriter.php | 21 ++++++++++++++++++++- composer.json | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Catalogue/CatalogueWriter.php b/Catalogue/CatalogueWriter.php index 59ea0aa1..0888c97f 100644 --- a/Catalogue/CatalogueWriter.php +++ b/Catalogue/CatalogueWriter.php @@ -53,7 +53,7 @@ public function __construct( public function writeCatalogues(Configuration $config, array $catalogues) { foreach ($catalogues as $catalogue) { - $this->writer->writeTranslations( + $this->writeTranslations( $catalogue, $config->getOutputFormat(), [ @@ -64,4 +64,23 @@ public function writeCatalogues(Configuration $config, array $catalogues) ); } } + + /** + * This method calls the new TranslationWriter::write() if exist, + * otherwise fallback to TranslationWriter::writeTranslations() call + * to avoid BC breaks. + * + * @param MessageCatalogue $catalogue + * @param string $format + * @param array $options + */ + private function writeTranslations(MessageCatalogue $catalogue, $format, array $options) + { + if (method_exists($this->writer, 'write')) { + $this->writer->write($catalogue, $format, $options); + } else { + // This method is deprecated since 3.4, maintained to avoid BC breaks + $this->writer->writeTranslations($catalogue, $format, $options); + } + } } diff --git a/composer.json b/composer.json index 4fd43bb1..4d2bc554 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/intl": "^2.7 || ^3.0 || ^4.0", "php-translation/common": "^0.2.1", - "php-translation/symfony-storage": "^0.3.2", + "php-translation/symfony-storage": "dev-master", "php-translation/extractor": "^1.2" }, "require-dev": { From e114a06c09cd4d0754b81192c41c6a165f49ed9a Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 21 Dec 2017 12:40:01 +0200 Subject: [PATCH 07/26] Make php_translation.cache_clearer service public - we call it in controller --- Resources/config/services.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 4a0a35ab..e636366a 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -35,6 +35,7 @@ services: alias: 'php_translation.importer' php_translation.cache_clearer: + public: true class: Translation\Bundle\Service\CacheClearer arguments: ["%kernel.cache_dir%", "@translator", "@filesystem"] From 4844b40e853a5ec6214e2697384e3ea46225e5f7 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 21 Dec 2017 12:41:24 +0200 Subject: [PATCH 08/26] Revert php-translation/symfony-storage version in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4d2bc554..4fd43bb1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/intl": "^2.7 || ^3.0 || ^4.0", "php-translation/common": "^0.2.1", - "php-translation/symfony-storage": "dev-master", + "php-translation/symfony-storage": "^0.3.2", "php-translation/extractor": "^1.2" }, "require-dev": { From 5887a834621d83b703e8ed25ea3231a2296ee454 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 21 Dec 2017 12:47:21 +0200 Subject: [PATCH 09/26] Revert making php_translation.extractor.php public - use public alias --- Resources/config/extractors.yml | 5 ++++- Tests/Functional/BundleInitializationTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Resources/config/extractors.yml b/Resources/config/extractors.yml index 762cfb83..a99d2050 100644 --- a/Resources/config/extractors.yml +++ b/Resources/config/extractors.yml @@ -1,10 +1,13 @@ services: php_translation.extractor.php: - public: true class: Translation\Extractor\FileExtractor\PHPFileExtractor tags: - { name: 'php_translation.extractor', type: 'php' } + test.php_translation.extractor.php: + public: true + alias: 'php_translation.extractor.php' + php_translation.extractor.twig: public: true class: Translation\Extractor\FileExtractor\TwigFileExtractor diff --git a/Tests/Functional/BundleInitializationTest.php b/Tests/Functional/BundleInitializationTest.php index 62619106..1607f930 100644 --- a/Tests/Functional/BundleInitializationTest.php +++ b/Tests/Functional/BundleInitializationTest.php @@ -37,7 +37,7 @@ public function testRegisterBundle() $services = [ 'php_translation.storage' => StorageService::class, 'php_translation.extractor.twig' => TwigFileExtractor::class, - 'php_translation.extractor.php' => PHPFileExtractor::class, + 'test.php_translation.extractor.php' => PHPFileExtractor::class, 'php_translation.catalogue_fetcher' => CatalogueFetcher::class, 'php_translation.catalogue_writer' => CatalogueWriter::class, 'php_translation.catalogue_manager' => CatalogueManager::class, From 23762ba3ccedc30a1e2a451ea219352351a692a6 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 21 Dec 2017 12:51:16 +0200 Subject: [PATCH 10/26] Revert making php_translation.extractor.twig public - use public alias --- Resources/config/extractors.yml | 5 ++++- Tests/Functional/BundleInitializationTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Resources/config/extractors.yml b/Resources/config/extractors.yml index a99d2050..778b393e 100644 --- a/Resources/config/extractors.yml +++ b/Resources/config/extractors.yml @@ -9,12 +9,15 @@ services: alias: 'php_translation.extractor.php' php_translation.extractor.twig: - public: true class: Translation\Extractor\FileExtractor\TwigFileExtractor arguments: ["@twig"] tags: - { name: 'php_translation.extractor', type: 'twig' } + test.php_translation.extractor.twig: + public: true + alias: 'php_translation.extractor.twig' + # PHP Visitors: php_translation.extractor.php.visitor.ContainerAwareTrans: class: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans diff --git a/Tests/Functional/BundleInitializationTest.php b/Tests/Functional/BundleInitializationTest.php index 1607f930..b1e8032d 100644 --- a/Tests/Functional/BundleInitializationTest.php +++ b/Tests/Functional/BundleInitializationTest.php @@ -36,7 +36,7 @@ public function testRegisterBundle() $services = [ 'php_translation.storage' => StorageService::class, - 'php_translation.extractor.twig' => TwigFileExtractor::class, + 'test.php_translation.extractor.twig' => TwigFileExtractor::class, 'test.php_translation.extractor.php' => PHPFileExtractor::class, 'php_translation.catalogue_fetcher' => CatalogueFetcher::class, 'php_translation.catalogue_writer' => CatalogueWriter::class, From cfa14a15223f81e8e6055d3fc41b39c66e567d66 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 21 Dec 2017 12:55:03 +0200 Subject: [PATCH 11/26] Revert making php_translation.extractor public - use public alias --- Resources/config/services.yml | 5 ++++- Tests/Functional/BundleInitializationTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index e636366a..bab4e2df 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -19,9 +19,12 @@ services: class: Translation\Bundle\Catalogue\CatalogueManager php_translation.extractor: - public: true class: Translation\Extractor\Extractor + test.php_translation.extractor: + public: true + alias: 'php_translation.extractor' + php_translation.configuration_manager: public: true class: Translation\Bundle\Service\ConfigurationManager diff --git a/Tests/Functional/BundleInitializationTest.php b/Tests/Functional/BundleInitializationTest.php index b1e8032d..63f7a07e 100644 --- a/Tests/Functional/BundleInitializationTest.php +++ b/Tests/Functional/BundleInitializationTest.php @@ -41,7 +41,7 @@ public function testRegisterBundle() 'php_translation.catalogue_fetcher' => CatalogueFetcher::class, 'php_translation.catalogue_writer' => CatalogueWriter::class, 'php_translation.catalogue_manager' => CatalogueManager::class, - 'php_translation.extractor' => Extractor::class, + 'test.php_translation.extractor' => Extractor::class, ]; foreach ($services as $id => $class) { From 4f23256e64936bcecbf1765e88df5aad6d795f9e Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 21 Dec 2017 13:21:40 +0200 Subject: [PATCH 12/26] Revert making one more service public in favor of public alias --- Resources/config/edit_in_place.yml | 5 ++++- Tests/Functional/Controller/EditInPlaceTest.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Resources/config/edit_in_place.yml b/Resources/config/edit_in_place.yml index c8a779be..297c4620 100644 --- a/Resources/config/edit_in_place.yml +++ b/Resources/config/edit_in_place.yml @@ -11,10 +11,13 @@ services: - ~ php_translation.edit_in_place.activator: - public: true class: Translation\Bundle\EditInPlace\Activator arguments: ['@session'] + test.php_translation.edit_in_place.activator: + public: true + alias: 'php_translation.edit_in_place.activator' + php_translator.edit_in_place.xtrans_html_translator: class: Translation\Bundle\Translator\EditInPlaceTranslator arguments: diff --git a/Tests/Functional/Controller/EditInPlaceTest.php b/Tests/Functional/Controller/EditInPlaceTest.php index 9a968235..9026b7c6 100644 --- a/Tests/Functional/Controller/EditInPlaceTest.php +++ b/Tests/Functional/Controller/EditInPlaceTest.php @@ -25,7 +25,7 @@ public function testActivatedTest() $request = Request::create('/foobar'); // Activate the feature - $this->getContainer()->get('php_translation.edit_in_place.activator')->activate(); + $this->getContainer()->get('test.php_translation.edit_in_place.activator')->activate(); $response = $this->kernel->handle($request); @@ -57,7 +57,7 @@ public function testIfUntranslatableLabelGetsDisabled() // Activate the feature $this->bootKernel(); - $this->getContainer()->get('php_translation.edit_in_place.activator')->activate(); + $this->getContainer()->get('test.php_translation.edit_in_place.activator')->activate(); $response = $this->kernel->handle($request); From 2931222d37fa5ec24ab498a97f4904530acacb93 Mon Sep 17 00:00:00 2001 From: Deniss Kozickis Date: Sun, 24 Dec 2017 19:00:42 +0400 Subject: [PATCH 13/26] * Translation Loader or Reader (BC SF3.4) --- Catalogue/CatalogueFetcher.php | 26 +++++- .../CompilerPass/LoaderOrReaderPass.php | 26 ++++++ Resources/config/services.yml | 2 +- .../Catalogue/CatalogueFetcherTest.php | 90 +++++++++++++++++++ .../CompilerPass/LoaderOrReaderPassTest.php | 28 ++++++ TranslationBundle.php | 2 + 6 files changed, 169 insertions(+), 5 deletions(-) create mode 100644 DependencyInjection/CompilerPass/LoaderOrReaderPass.php create mode 100644 Tests/Functional/Catalogue/CatalogueFetcherTest.php create mode 100644 Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php diff --git a/Catalogue/CatalogueFetcher.php b/Catalogue/CatalogueFetcher.php index 717f1c62..c0da0845 100644 --- a/Catalogue/CatalogueFetcher.php +++ b/Catalogue/CatalogueFetcher.php @@ -14,6 +14,7 @@ use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\Reader\TranslationReader; use Translation\Bundle\Model\Configuration; +use Translation\SymfonyStorage\TranslationLoader; /** * Fetches catalogues from source files. This will only work with local file storage @@ -26,14 +27,14 @@ final class CatalogueFetcher { /** - * @var TranslationReader + * @var TranslationReader|TranslationLoader */ private $reader; /** - * @param TranslationReader $reader + * @param TranslationReader|TranslationLoader $reader */ - public function __construct(TranslationReader $reader) + public function __construct($reader) { $this->reader = $reader; } @@ -57,7 +58,7 @@ public function getCatalogues(Configuration $config, array $locales = []) $currentCatalogue = new MessageCatalogue($locale); foreach ($dirs as $path) { if (is_dir($path)) { - $this->reader->read($path, $currentCatalogue); + $this->readTranslations($path, $currentCatalogue); } } $catalogues[] = $currentCatalogue; @@ -65,4 +66,21 @@ public function getCatalogues(Configuration $config, array $locales = []) return $catalogues; } + + /** + * This method calls TranslationLoader::loadMessages() for SF < 3.4, + * or TranslationReader::read() for SF >= 3.4 to avoid BC breaks. + * + * @param $path + * @param MessageCatalogue $currentCatalogue + */ + private function readTranslations($path, MessageCatalogue $currentCatalogue) + { + if (method_exists($this->reader, 'read')) { + $this->reader->read($path, $currentCatalogue); + } else { + // This method is deprecated since 3.4, maintained to avoid BC breaks + $this->reader->loadMessages($path, $currentCatalogue); + } + } } diff --git a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php new file mode 100644 index 00000000..d0b9f325 --- /dev/null +++ b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php @@ -0,0 +1,26 @@ +has('translation.reader')) { + $container->setAlias('translation.loader.or.reader', 'translation.reader'); + + return; + } + + if ($container->has('translation.loader')) { + $container->setAlias('translation.loader.or.reader', 'translation.loader'); + + return; + } + + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index bab4e2df..fa1a241b 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -2,7 +2,7 @@ services: php_translation.catalogue_fetcher: public: true class: Translation\Bundle\Catalogue\CatalogueFetcher - arguments: ["@translation.reader"] + arguments: ["@translation.loader.or.reader"] php_translation.catalogue_writer: public: true diff --git a/Tests/Functional/Catalogue/CatalogueFetcherTest.php b/Tests/Functional/Catalogue/CatalogueFetcherTest.php new file mode 100644 index 00000000..30c0f0cb --- /dev/null +++ b/Tests/Functional/Catalogue/CatalogueFetcherTest.php @@ -0,0 +1,90 @@ + + + + + + key0 + trans0 + + + + + key1 + trans1 + + + + + +XML + ); + } + + public function testFetchCatalogue() + { + $this->bootKernel(); + + $this->catalogueFetcher = $this->getContainer()->get('php_translation.catalogue_fetcher'); + + $data = self::getDefaultData(); + $data['external_translations_dirs'] = [__DIR__.'/../app/Resources/translations/']; + + $conf = new Configuration($data); + + /** @var MessageCatalogue[] $catalogues */ + $catalogues = $this->catalogueFetcher->getCatalogues($conf, ['sv']); + + $this->assertEquals('sv', $catalogues[0]->getLocale()); + } + + /** + * @return array + */ + public static function getDefaultData() + { + return [ + 'name' => 'getName', + 'locales' => ['getLocales'], + 'project_root' => 'getProjectRoot', + 'output_dir' => 'getOutputDir', + 'dirs' => ['getDirs'], + 'excluded_dirs' => ['getExcludedDirs'], + 'excluded_names' => ['getExcludedNames'], + 'external_translations_dirs' => ['getExternalTranslationsDirs'], + 'output_format' => 'getOutputFormat', + 'blacklist_domains' => ['getBlacklistDomains'], + 'whitelist_domains' => ['getWhitelistDomains'], + 'xliff_version' => ['getXliffVersion'], + ]; + } + + protected function setUp() + { + parent::setUp(); + + $this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yml'); + } + +} diff --git a/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php new file mode 100644 index 00000000..217f3fb4 --- /dev/null +++ b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php @@ -0,0 +1,28 @@ +addCompilerPass(new LoaderOrReaderPass()); + } + + public function testLoaderOrReader() + { + $def = new Definition(); + $this->setDefinition('translation.reader', $def); + + $this->compile(); + + $this->assertContainerBuilderHasAlias('translation.loader.or.reader'); + } +} diff --git a/TranslationBundle.php b/TranslationBundle.php index 99f997b0..f8976c04 100644 --- a/TranslationBundle.php +++ b/TranslationBundle.php @@ -16,6 +16,7 @@ use Translation\Bundle\DependencyInjection\CompilerPass\EditInPlacePass; use Translation\Bundle\DependencyInjection\CompilerPass\ExternalTranslatorPass; use Translation\Bundle\DependencyInjection\CompilerPass\ExtractorPass; +use Translation\Bundle\DependencyInjection\CompilerPass\LoaderOrReaderPass; use Translation\Bundle\DependencyInjection\CompilerPass\StoragePass; use Translation\Bundle\DependencyInjection\CompilerPass\SymfonyProfilerPass; use Translation\Bundle\DependencyInjection\CompilerPass\ValidatorVisitorPass; @@ -33,5 +34,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new ExtractorPass()); $container->addCompilerPass(new StoragePass()); $container->addCompilerPass(new EditInPlacePass()); + $container->addCompilerPass(new LoaderOrReaderPass()); } } From a54d3d6bfbe313fe44e5c08907cddeb66727472f Mon Sep 17 00:00:00 2001 From: Deniss Kozickis Date: Mon, 25 Dec 2017 17:18:16 +0400 Subject: [PATCH 14/26] * StyleCI --- DependencyInjection/CompilerPass/LoaderOrReaderPass.php | 2 -- Tests/Functional/Catalogue/CatalogueFetcherTest.php | 2 -- .../DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php | 2 -- 3 files changed, 6 deletions(-) diff --git a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php index d0b9f325..6451d835 100644 --- a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php +++ b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php @@ -7,7 +7,6 @@ class LoaderOrReaderPass implements CompilerPassInterface { - public function process(ContainerBuilder $container) { if ($container->has('translation.reader')) { @@ -21,6 +20,5 @@ public function process(ContainerBuilder $container) return; } - } } diff --git a/Tests/Functional/Catalogue/CatalogueFetcherTest.php b/Tests/Functional/Catalogue/CatalogueFetcherTest.php index 30c0f0cb..7756774c 100644 --- a/Tests/Functional/Catalogue/CatalogueFetcherTest.php +++ b/Tests/Functional/Catalogue/CatalogueFetcherTest.php @@ -7,7 +7,6 @@ class CatalogueFetcherTest extends BaseTestCase { - /** * @var CatalogueFetcher */ @@ -86,5 +85,4 @@ protected function setUp() $this->kernel->addConfigFile(__DIR__.'/../app/config/normal_config.yml'); } - } diff --git a/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php index 217f3fb4..646254f4 100644 --- a/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php +++ b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php @@ -7,10 +7,8 @@ use Symfony\Component\DependencyInjection\Definition; use Translation\Bundle\DependencyInjection\CompilerPass\LoaderOrReaderPass; - class LoaderOrReaderPassTest extends AbstractCompilerPassTestCase { - protected function registerCompilerPass(ContainerBuilder $container) { $container->addCompilerPass(new LoaderOrReaderPass()); From d54ee4fc64e627de39d6c14c3b358694fed68c99 Mon Sep 17 00:00:00 2001 From: Deniss Kozickis Date: Mon, 25 Dec 2017 17:35:33 +0400 Subject: [PATCH 15/26] * Legacy wrapper for ChildDefiniton/DefinitionDecorator --- DependencyInjection/TranslationExtension.php | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index ee24aaee..a2b5dd16 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -15,6 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ChildDefinition; +use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -106,7 +107,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config) /* * Configure storage chain service */ - $storageDefinition = new ChildDefinition('php_translation.storage.abstract'); + $storageDefinition = $this->createChildDefinition('php_translation.storage.abstract'); $storageDefinition->replaceArgument(2, new Reference($configurationServiceId)); $storageDefinition->setPublic(true); $container->setDefinition('php_translation.storage.'.$name, $storageDefinition); @@ -123,7 +124,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config) continue; } - $def = new ChildDefinition($serviceId); + $def = $this->createChildDefinition($serviceId); $def->replaceArgument(2, [$c['output_dir']]) ->replaceArgument(3, [$c['local_file_storage_options']]) ->addTag('php_translation.storage', ['type' => 'local', 'name' => $name]); @@ -224,4 +225,20 @@ public function getAlias() { return 'translation'; } + + /** + * To avoid BC break for Symfony 3.3+ + * + * @param $parent + * + * @return ChildDefinition|DefinitionDecorator + */ + private function createChildDefinition($parent) + { + if (class_exists('Symfony\Component\DependencyInjection\ChildDefinition')) { + return new ChildDefinition($parent); + } + + return new DefinitionDecorator($parent); + } } From 2d74ebc99789c1732f2b15ffb65ffcbce1dbc058 Mon Sep 17 00:00:00 2001 From: Deniss Kozickis Date: Mon, 25 Dec 2017 17:37:15 +0400 Subject: [PATCH 16/26] * StyleCI fix --- DependencyInjection/TranslationExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index a2b5dd16..9625a0c5 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -227,7 +227,7 @@ public function getAlias() } /** - * To avoid BC break for Symfony 3.3+ + * To avoid BC break for Symfony 3.3+. * * @param $parent * From 06fc22380d67c7d8a2415501e6a1323043df44a2 Mon Sep 17 00:00:00 2001 From: Deniss Kozickis Date: Mon, 25 Dec 2017 17:47:16 +0400 Subject: [PATCH 17/26] * One more fix for translation loader or reader --- Resources/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/config/services.yml b/Resources/config/services.yml index fa1a241b..84bf20c7 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -45,7 +45,7 @@ services: php_translation.local_file_storage.abstract: class: Translation\SymfonyStorage\FileStorage abstract: true - arguments: ["@translation.writer", "@translation.reader", ~, []] + arguments: ["@translation.writer", "@translation.loader.or.reader", ~, []] php_translation.storage.xlf_loader: class: Translation\SymfonyStorage\Loader\XliffLoader From f40e62ef2ba904652ca76d9037243f36b5eb9909 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Mon, 25 Dec 2017 19:55:32 +0200 Subject: [PATCH 18/26] Tweaked service name to translation.loader_or_reader --- DependencyInjection/CompilerPass/LoaderOrReaderPass.php | 4 ++-- Resources/config/services.yml | 4 ++-- .../CompilerPass/LoaderOrReaderPassTest.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php index 6451d835..d6c8b723 100644 --- a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php +++ b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php @@ -10,13 +10,13 @@ class LoaderOrReaderPass implements CompilerPassInterface public function process(ContainerBuilder $container) { if ($container->has('translation.reader')) { - $container->setAlias('translation.loader.or.reader', 'translation.reader'); + $container->setAlias('translation.loader_or_reader', 'translation.reader'); return; } if ($container->has('translation.loader')) { - $container->setAlias('translation.loader.or.reader', 'translation.loader'); + $container->setAlias('translation.loader_or_reader', 'translation.loader'); return; } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 84bf20c7..096af07b 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -2,7 +2,7 @@ services: php_translation.catalogue_fetcher: public: true class: Translation\Bundle\Catalogue\CatalogueFetcher - arguments: ["@translation.loader.or.reader"] + arguments: ["@translation.loader_or_reader"] php_translation.catalogue_writer: public: true @@ -45,7 +45,7 @@ services: php_translation.local_file_storage.abstract: class: Translation\SymfonyStorage\FileStorage abstract: true - arguments: ["@translation.writer", "@translation.loader.or.reader", ~, []] + arguments: ["@translation.writer", "@translation.loader_or_reader", ~, []] php_translation.storage.xlf_loader: class: Translation\SymfonyStorage\Loader\XliffLoader diff --git a/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php index 646254f4..bd01e359 100644 --- a/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php +++ b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php @@ -21,6 +21,6 @@ public function testLoaderOrReader() $this->compile(); - $this->assertContainerBuilderHasAlias('translation.loader.or.reader'); + $this->assertContainerBuilderHasAlias('translation.loader_or_reader'); } } From f14ee831639adcdc5c955e2d3043a1d3a182ad02 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Mon, 25 Dec 2017 19:56:26 +0200 Subject: [PATCH 19/26] Bump php-translation/symfony-storage version to ^0.3.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4fd43bb1..4282e62a 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/intl": "^2.7 || ^3.0 || ^4.0", "php-translation/common": "^0.2.1", - "php-translation/symfony-storage": "^0.3.2", + "php-translation/symfony-storage": "^0.3.4", "php-translation/extractor": "^1.2" }, "require-dev": { From 271672fb3f26dc019e723b1789f14f10322b7659 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Mon, 25 Dec 2017 19:58:55 +0200 Subject: [PATCH 20/26] Fix styles: Add missing header for new PHP classes --- DependencyInjection/CompilerPass/LoaderOrReaderPass.php | 9 +++++++++ Tests/Functional/Catalogue/CatalogueFetcherTest.php | 9 +++++++++ .../CompilerPass/LoaderOrReaderPassTest.php | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php index d6c8b723..808834ea 100644 --- a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php +++ b/DependencyInjection/CompilerPass/LoaderOrReaderPass.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 Translation\Bundle\DependencyInjection\CompilerPass; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; diff --git a/Tests/Functional/Catalogue/CatalogueFetcherTest.php b/Tests/Functional/Catalogue/CatalogueFetcherTest.php index 7756774c..e7bc5be5 100644 --- a/Tests/Functional/Catalogue/CatalogueFetcherTest.php +++ b/Tests/Functional/Catalogue/CatalogueFetcherTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + use Symfony\Component\Translation\MessageCatalogue; use Translation\Bundle\Catalogue\CatalogueFetcher; use Translation\Bundle\Model\Configuration; diff --git a/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php index bd01e359..ea9b66f0 100644 --- a/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.php +++ b/Tests/Unit/DependencyInjection/CompilerPass/LoaderOrReaderPassTest.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 Translation\Bundle\Tests\Unit\DependencyInjection\CompilerPass; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; From 4469cfed72cad49f143937f18961760adf80aa66 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Mon, 25 Dec 2017 20:33:59 +0200 Subject: [PATCH 21/26] Create LegacyTranslationLoader on compilation to avoid extra checks --- Catalogue/CatalogueFetcher.php | 39 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/Catalogue/CatalogueFetcher.php b/Catalogue/CatalogueFetcher.php index c0da0845..aeac7056 100644 --- a/Catalogue/CatalogueFetcher.php +++ b/Catalogue/CatalogueFetcher.php @@ -11,9 +11,11 @@ namespace Translation\Bundle\Catalogue; +use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader as SymfonyTranslationLoader; use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\Reader\TranslationReader; use Translation\Bundle\Model\Configuration; +use Translation\SymfonyStorage\LegacyTranslationLoader; use Translation\SymfonyStorage\TranslationLoader; /** @@ -27,16 +29,24 @@ final class CatalogueFetcher { /** - * @var TranslationReader|TranslationLoader + * @var TranslationLoader|SymfonyTranslationLoader */ - private $reader; + private $loader; /** - * @param TranslationReader|TranslationLoader $reader + * @param SymfonyTranslationLoader|TranslationLoader|TranslationReader $loader */ - public function __construct($reader) + public function __construct($loader) { - $this->reader = $reader; + // Create a legacy loader which is a wrapper for TranslationReader + if ($loader instanceof TranslationReader) { + $loader = new LegacyTranslationLoader($loader); + } + if (!$loader instanceof SymfonyTranslationLoader && !$loader instanceof TranslationLoader) { + throw new \LogicException('First parameter of CatalogueFetcher must be a Symfony translation loader or implement Translation\SymfonyStorage\TranslationLoader'); + } + + $this->loader = $loader; } /** @@ -58,7 +68,7 @@ public function getCatalogues(Configuration $config, array $locales = []) $currentCatalogue = new MessageCatalogue($locale); foreach ($dirs as $path) { if (is_dir($path)) { - $this->readTranslations($path, $currentCatalogue); + $this->loader->loadMessages($path, $currentCatalogue); } } $catalogues[] = $currentCatalogue; @@ -66,21 +76,4 @@ public function getCatalogues(Configuration $config, array $locales = []) return $catalogues; } - - /** - * This method calls TranslationLoader::loadMessages() for SF < 3.4, - * or TranslationReader::read() for SF >= 3.4 to avoid BC breaks. - * - * @param $path - * @param MessageCatalogue $currentCatalogue - */ - private function readTranslations($path, MessageCatalogue $currentCatalogue) - { - if (method_exists($this->reader, 'read')) { - $this->reader->read($path, $currentCatalogue); - } else { - // This method is deprecated since 3.4, maintained to avoid BC breaks - $this->reader->loadMessages($path, $currentCatalogue); - } - } } From 97671a8f89aa7d4d6dfaa4a3b249ad82830ae181 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 28 Dec 2017 14:40:06 +0200 Subject: [PATCH 22/26] Bump symfony-storage version to v0.4.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4282e62a..56062828 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "symfony/intl": "^2.7 || ^3.0 || ^4.0", "php-translation/common": "^0.2.1", - "php-translation/symfony-storage": "^0.3.4", + "php-translation/symfony-storage": "^0.4.0", "php-translation/extractor": "^1.2" }, "require-dev": { From d922523e56ca71af5cecb9472c75f17485137a47 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 28 Dec 2017 15:06:12 +0200 Subject: [PATCH 23/26] Move test.* services to a separate file and include it for tests --- DependencyInjection/TranslationExtension.php | 4 ++++ Resources/config/edit_in_place.yml | 4 ---- Resources/config/extractors.yml | 8 -------- Resources/config/services.yml | 8 -------- Resources/config/services_test.yml | 20 ++++++++++++++++++++ phpunit.xml.dist | 4 ++++ 6 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 Resources/config/services_test.yml diff --git a/DependencyInjection/TranslationExtension.php b/DependencyInjection/TranslationExtension.php index 9625a0c5..28d11f7b 100644 --- a/DependencyInjection/TranslationExtension.php +++ b/DependencyInjection/TranslationExtension.php @@ -76,6 +76,10 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('auto_translation.yml'); $this->enableFallbackAutoTranslator($container, $config); } + + if ('test' === getenv('ENV')) { + $loader->load('services_test.yml'); + } } /** diff --git a/Resources/config/edit_in_place.yml b/Resources/config/edit_in_place.yml index 297c4620..6d89c949 100644 --- a/Resources/config/edit_in_place.yml +++ b/Resources/config/edit_in_place.yml @@ -14,10 +14,6 @@ services: class: Translation\Bundle\EditInPlace\Activator arguments: ['@session'] - test.php_translation.edit_in_place.activator: - public: true - alias: 'php_translation.edit_in_place.activator' - php_translator.edit_in_place.xtrans_html_translator: class: Translation\Bundle\Translator\EditInPlaceTranslator arguments: diff --git a/Resources/config/extractors.yml b/Resources/config/extractors.yml index 778b393e..efb9c280 100644 --- a/Resources/config/extractors.yml +++ b/Resources/config/extractors.yml @@ -4,20 +4,12 @@ services: tags: - { name: 'php_translation.extractor', type: 'php' } - test.php_translation.extractor.php: - public: true - alias: 'php_translation.extractor.php' - php_translation.extractor.twig: class: Translation\Extractor\FileExtractor\TwigFileExtractor arguments: ["@twig"] tags: - { name: 'php_translation.extractor', type: 'twig' } - test.php_translation.extractor.twig: - public: true - alias: 'php_translation.extractor.twig' - # PHP Visitors: php_translation.extractor.php.visitor.ContainerAwareTrans: class: Translation\Extractor\Visitor\Php\Symfony\ContainerAwareTrans diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 096af07b..957cbdcf 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -21,10 +21,6 @@ services: php_translation.extractor: class: Translation\Extractor\Extractor - test.php_translation.extractor: - public: true - alias: 'php_translation.extractor' - php_translation.configuration_manager: public: true class: Translation\Bundle\Service\ConfigurationManager @@ -33,10 +29,6 @@ services: class: Translation\Bundle\Service\Importer arguments: ["@php_translation.extractor"] - test.php_translation.importer: - public: true - alias: 'php_translation.importer' - php_translation.cache_clearer: public: true class: Translation\Bundle\Service\CacheClearer diff --git a/Resources/config/services_test.yml b/Resources/config/services_test.yml new file mode 100644 index 00000000..82a6eb79 --- /dev/null +++ b/Resources/config/services_test.yml @@ -0,0 +1,20 @@ +services: + test.php_translation.edit_in_place.activator: + public: true + alias: 'php_translation.edit_in_place.activator' + + test.php_translation.extractor.php: + public: true + alias: 'php_translation.extractor.php' + + test.php_translation.extractor.twig: + public: true + alias: 'php_translation.extractor.twig' + + test.php_translation.extractor: + public: true + alias: 'php_translation.extractor' + + test.php_translation.importer: + public: true + alias: 'php_translation.importer' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9ab4f64a..5a93c70c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,6 +13,10 @@ bootstrap="./vendor/autoload.php" > + + + + From 5b0458ee83a67bbb664ba427704619830b78076e Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 28 Dec 2017 15:15:00 +0200 Subject: [PATCH 24/26] Add a description for LoaderOrReaderPass class --- DependencyInjection/CompilerPass/LoaderOrReaderPass.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php index 808834ea..513e13f3 100644 --- a/DependencyInjection/CompilerPass/LoaderOrReaderPass.php +++ b/DependencyInjection/CompilerPass/LoaderOrReaderPass.php @@ -14,6 +14,11 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +/** + * To provide a BC layer for Symfony 2.7 to 3.3 this compiler pass + * registers an alias of whether TranslationReader or TranslationLoader + * to be able to inject it in other services. + */ class LoaderOrReaderPass implements CompilerPassInterface { public function process(ContainerBuilder $container) From 66bd35e338d164b5ceb238b97682b94a75bdb554 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 28 Dec 2017 15:29:01 +0200 Subject: [PATCH 25/26] Use new LegacyTranslationReader and LegacyTranslationWriter classes --- Catalogue/CatalogueFetcher.php | 24 ++++++++++------------- Catalogue/CatalogueWriter.php | 35 ++++++++++------------------------ 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/Catalogue/CatalogueFetcher.php b/Catalogue/CatalogueFetcher.php index aeac7056..4b666307 100644 --- a/Catalogue/CatalogueFetcher.php +++ b/Catalogue/CatalogueFetcher.php @@ -13,9 +13,9 @@ use Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader as SymfonyTranslationLoader; use Symfony\Component\Translation\MessageCatalogue; -use Symfony\Component\Translation\Reader\TranslationReader; +use Symfony\Component\Translation\Reader\TranslationReaderInterface; use Translation\Bundle\Model\Configuration; -use Translation\SymfonyStorage\LegacyTranslationLoader; +use Translation\SymfonyStorage\LegacyTranslationReader; use Translation\SymfonyStorage\TranslationLoader; /** @@ -29,24 +29,20 @@ final class CatalogueFetcher { /** - * @var TranslationLoader|SymfonyTranslationLoader + * @var TranslationReaderInterface */ - private $loader; + private $reader; /** - * @param SymfonyTranslationLoader|TranslationLoader|TranslationReader $loader + * @param SymfonyTranslationLoader|TranslationLoader|TranslationReaderInterface $reader */ - public function __construct($loader) + public function __construct($reader) { - // Create a legacy loader which is a wrapper for TranslationReader - if ($loader instanceof TranslationReader) { - $loader = new LegacyTranslationLoader($loader); - } - if (!$loader instanceof SymfonyTranslationLoader && !$loader instanceof TranslationLoader) { - throw new \LogicException('First parameter of CatalogueFetcher must be a Symfony translation loader or implement Translation\SymfonyStorage\TranslationLoader'); + if (!$reader instanceof TranslationReaderInterface) { + $reader = new LegacyTranslationReader($reader); } - $this->loader = $loader; + $this->reader = $reader; } /** @@ -68,7 +64,7 @@ public function getCatalogues(Configuration $config, array $locales = []) $currentCatalogue = new MessageCatalogue($locale); foreach ($dirs as $path) { if (is_dir($path)) { - $this->loader->loadMessages($path, $currentCatalogue); + $this->reader->read($path, $currentCatalogue); } } $catalogues[] = $currentCatalogue; diff --git a/Catalogue/CatalogueWriter.php b/Catalogue/CatalogueWriter.php index 0888c97f..52bff4c7 100644 --- a/Catalogue/CatalogueWriter.php +++ b/Catalogue/CatalogueWriter.php @@ -13,7 +13,9 @@ use Symfony\Component\Translation\MessageCatalogue; use Symfony\Component\Translation\Writer\TranslationWriter; +use Symfony\Component\Translation\Writer\TranslationWriterInterface; use Translation\Bundle\Model\Configuration; +use Translation\SymfonyStorage\LegacyTranslationWriter; /** * Write catalogues back to disk. @@ -25,7 +27,7 @@ final class CatalogueWriter { /** - * @var TranslationWriter + * @var TranslationWriterInterface */ private $writer; @@ -38,10 +40,12 @@ final class CatalogueWriter * @param TranslationWriter $writer * @param string $defaultLocale */ - public function __construct( - TranslationWriter $writer, - $defaultLocale - ) { + public function __construct(TranslationWriter $writer, $defaultLocale) + { + if (!$writer instanceof TranslationWriterInterface) { + $writer = new LegacyTranslationWriter($writer); + } + $this->writer = $writer; $this->defaultLocale = $defaultLocale; } @@ -53,7 +57,7 @@ public function __construct( public function writeCatalogues(Configuration $config, array $catalogues) { foreach ($catalogues as $catalogue) { - $this->writeTranslations( + $this->writer->write( $catalogue, $config->getOutputFormat(), [ @@ -64,23 +68,4 @@ public function writeCatalogues(Configuration $config, array $catalogues) ); } } - - /** - * This method calls the new TranslationWriter::write() if exist, - * otherwise fallback to TranslationWriter::writeTranslations() call - * to avoid BC breaks. - * - * @param MessageCatalogue $catalogue - * @param string $format - * @param array $options - */ - private function writeTranslations(MessageCatalogue $catalogue, $format, array $options) - { - if (method_exists($this->writer, 'write')) { - $this->writer->write($catalogue, $format, $options); - } else { - // This method is deprecated since 3.4, maintained to avoid BC breaks - $this->writer->writeTranslations($catalogue, $format, $options); - } - } } From b0dddbb78a14d52eac9d7e58a32449f140cf25e7 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Thu, 28 Dec 2017 16:56:49 +0200 Subject: [PATCH 26/26] Make php_translation.importer public and remove its test alias --- Command/ExtractCommand.php | 2 +- Resources/config/services.yml | 1 + Resources/config/services_test.yml | 4 ---- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 6b8b4935..50a0d3ff 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -39,7 +39,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); - $importer = $container->get('test.php_translation.importer'); + $importer = $container->get('php_translation.importer'); $config = $container->get('php_translation.configuration_manager') ->getConfiguration($input->getArgument('configuration')); diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 957cbdcf..69528e73 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -26,6 +26,7 @@ services: class: Translation\Bundle\Service\ConfigurationManager php_translation.importer: + public: true class: Translation\Bundle\Service\Importer arguments: ["@php_translation.extractor"] diff --git a/Resources/config/services_test.yml b/Resources/config/services_test.yml index 82a6eb79..6dc80eae 100644 --- a/Resources/config/services_test.yml +++ b/Resources/config/services_test.yml @@ -14,7 +14,3 @@ services: test.php_translation.extractor: public: true alias: 'php_translation.extractor' - - test.php_translation.importer: - public: true - alias: 'php_translation.importer'