Skip to content

Commit 689d324

Browse files
nstapelbroekNyholm
authored andcommitted
Fix the FileDumper::setBackup() method deprecation notice (#236)
* Fix the FileDumper::setBackup() method deprecation notice Also adds a compiler pass to assure the service definition remains unchanged on older Symfony versions * Convert logic in compiler pass to fail-fast and fix styleci issues
1 parent 57209e8 commit 689d324

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHP Translation package.
5+
*
6+
* (c) PHP Translation team <tobias.nyholm@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Translation\Bundle\DependencyInjection\CompilerPass;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\HttpKernel\Kernel;
17+
18+
/**
19+
* The FileDumper::setBackup is deprecated since Symfony 4.1.
20+
* This compiler pass assures our service definition remains unchanged for older symfony versions (3 or lower)
21+
* while keeping the latest version clean of deprecation notices.
22+
*/
23+
class FileDumperBackupPass implements CompilerPassInterface
24+
{
25+
public function process(ContainerBuilder $container)
26+
{
27+
if (Kernel::MAJOR_VERSION >= 4) {
28+
return;
29+
}
30+
31+
$definition = $container->getDefinition('php_translation.storage.xlf_dumper');
32+
$definition->addMethodCall('setBackup', [false]);
33+
}
34+
}

Resources/config/services.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ services:
5353
class: Translation\SymfonyStorage\Dumper\XliffDumper
5454
tags:
5555
- { name: translation.dumper, alias: xlf, legacy-alias: xliff }
56-
calls:
57-
- [setBackup, [false]]
5856

5957
php_translation.catalogue_counter:
6058
public: true

TranslationBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Translation\Bundle\DependencyInjection\CompilerPass\EditInPlacePass;
1717
use Translation\Bundle\DependencyInjection\CompilerPass\ExternalTranslatorPass;
1818
use Translation\Bundle\DependencyInjection\CompilerPass\ExtractorPass;
19+
use Translation\Bundle\DependencyInjection\CompilerPass\FileDumperBackupPass;
1920
use Translation\Bundle\DependencyInjection\CompilerPass\LoaderOrReaderPass;
2021
use Translation\Bundle\DependencyInjection\CompilerPass\StoragePass;
2122
use Translation\Bundle\DependencyInjection\CompilerPass\SymfonyProfilerPass;
@@ -35,5 +36,6 @@ public function build(ContainerBuilder $container)
3536
$container->addCompilerPass(new StoragePass());
3637
$container->addCompilerPass(new EditInPlacePass());
3738
$container->addCompilerPass(new LoaderOrReaderPass());
39+
$container->addCompilerPass(new FileDumperBackupPass());
3840
}
3941
}

0 commit comments

Comments
 (0)