diff --git a/DependencyInjection/CompilerPass/FileDumperBackupPass.php b/DependencyInjection/CompilerPass/FileDumperBackupPass.php new file mode 100644 index 00000000..0b7b48ed --- /dev/null +++ b/DependencyInjection/CompilerPass/FileDumperBackupPass.php @@ -0,0 +1,34 @@ + + * + * 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; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Kernel; + +/** + * The FileDumper::setBackup is deprecated since Symfony 4.1. + * This compiler pass assures our service definition remains unchanged for older symfony versions (3 or lower) + * while keeping the latest version clean of deprecation notices. + */ +class FileDumperBackupPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + if (Kernel::MAJOR_VERSION >= 4) { + return; + } + + $definition = $container->getDefinition('php_translation.storage.xlf_dumper'); + $definition->addMethodCall('setBackup', [false]); + } +} diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 355ca6ec..5ef264e9 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -53,8 +53,6 @@ services: class: Translation\SymfonyStorage\Dumper\XliffDumper tags: - { name: translation.dumper, alias: xlf, legacy-alias: xliff } - calls: - - [setBackup, [false]] php_translation.catalogue_counter: public: true diff --git a/TranslationBundle.php b/TranslationBundle.php index f8976c04..2c4cfff8 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\FileDumperBackupPass; use Translation\Bundle\DependencyInjection\CompilerPass\LoaderOrReaderPass; use Translation\Bundle\DependencyInjection\CompilerPass\StoragePass; use Translation\Bundle\DependencyInjection\CompilerPass\SymfonyProfilerPass; @@ -35,5 +36,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new StoragePass()); $container->addCompilerPass(new EditInPlacePass()); $container->addCompilerPass(new LoaderOrReaderPass()); + $container->addCompilerPass(new FileDumperBackupPass()); } }