Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4fde2f1

Browse filesBrowse files
committed
[Translation] add a BackupAwareDumperInterface
1 parent 243e59c commit 4fde2f1
Copy full SHA for 4fde2f1

File tree

4 files changed

+74
-2
lines changed
Filter options

4 files changed

+74
-2
lines changed
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Translation\Dumper;
13+
14+
/**
15+
* Interface to be implemented by dumpers that are able to create a backup
16+
* before dumping translations.
17+
*
18+
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
19+
*/
20+
interface BackupAwareDumperInterface
21+
{
22+
/**
23+
* Sets the value of the dumper's backup flag.
24+
*
25+
* @param bool
26+
*/
27+
public function setBackup($backup);
28+
}

‎src/Symfony/Component/Translation/Dumper/FileDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Dumper/FileDumper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
* @author Michel Salib <michelsalib@hotmail.com>
2424
*/
25-
abstract class FileDumper implements DumperInterface
25+
abstract class FileDumper implements BackupAwareDumperInterface, DumperInterface
2626
{
2727
/**
2828
* A template for the relative paths to files.

‎src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/Writer/TranslationWriterTest.php
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Translation\Tests\Writer;
1313

14+
use Symfony\Component\Translation\Dumper\DumperInterface;
1415
use Symfony\Component\Translation\MessageCatalogue;
1516
use Symfony\Component\Translation\Writer\TranslationWriter;
1617

@@ -28,6 +29,9 @@ public function testWriteTranslations()
2829
$writer->writeTranslations(new MessageCatalogue(array()), 'test');
2930
}
3031

32+
/**
33+
* @group legacy
34+
*/
3135
public function testDisableBackup()
3236
{
3337
$dumper = $this->getMock('Symfony\Component\Translation\Dumper\DumperInterface');
@@ -44,4 +48,40 @@ public function testDisableBackup()
4448
$writer->addDumper('php', $phpDumper);
4549
$writer->disableBackup();
4650
}
51+
52+
public function testBackupDumperNotImplementingInterfaceTriggersDeprecation()
53+
{
54+
$deprecations = array();
55+
set_error_handler(function ($type, $msg) use (&$deprecations) {
56+
if (E_USER_DEPRECATED === $type) {
57+
$deprecations[] = $msg;
58+
} else {
59+
throw new \RuntimeException($msg);
60+
}
61+
});
62+
63+
$dumper = new NonBackupDumper();
64+
$writer = new TranslationWriter();
65+
$writer->addDumper('non_backup', $dumper);
66+
$writer->disableBackup();
67+
68+
restore_error_handler();
69+
70+
$this->assertCount(1, $deprecations);
71+
$this->assertContains('Calling the setBackup() method of dumpers that do not implement the BackupAwareDumperInterface is deprecated since Symfony 3.1 and they will no longer be called in 4.0.', $deprecations[0]);
72+
}
73+
}
74+
75+
class NonBackupDumper implements DumperInterface
76+
{
77+
public $backupEnabled = true;
78+
79+
public function dump(MessageCatalogue $messages, $options = array())
80+
{
81+
}
82+
83+
public function setBackup($backupEnabled)
84+
{
85+
$this->backupEnabled = $backupEnabled;
86+
}
4787
}

‎src/Symfony/Component/Translation/Writer/TranslationWriter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Writer/TranslationWriter.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Translation\Writer;
1313

14+
use Symfony\Component\Translation\Dumper\BackupAwareDumperInterface;
1415
use Symfony\Component\Translation\MessageCatalogue;
1516
use Symfony\Component\Translation\Dumper\DumperInterface;
1617

@@ -45,7 +46,10 @@ public function addDumper($format, DumperInterface $dumper)
4546
public function disableBackup()
4647
{
4748
foreach ($this->dumpers as $dumper) {
48-
if (method_exists($dumper, 'setBackup')) {
49+
if ($dumper instanceof BackupAwareDumperInterface) {
50+
$dumper->setBackup(false);
51+
} elseif (method_exists($dumper, 'setBackup')) {
52+
@trigger_error('Calling the setBackup() method of dumpers that do not implement the BackupAwareDumperInterface is deprecated since Symfony 3.1 and they will no longer be called in 4.0.', E_USER_DEPRECATED);
4953
$dumper->setBackup(false);
5054
}
5155
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.