Skip to content

Commit a1c4be3

Browse files
[Serializer][Translation] Deprecate passing a non-empty CSV escape char
1 parent a50ed69 commit a1c4be3

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add `lint:translations` command
8+
* Deprecate passing an escape character to `CsvFileLoader::setCsvControl()`
89

910
7.1
1011
---

Loader/CsvFileLoader.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class CsvFileLoader extends FileLoader
2222
{
2323
private string $delimiter = ';';
2424
private string $enclosure = '"';
25+
/**
26+
* @deprecated since Symfony 7.2, to be removed in 8.0
27+
*/
2528
private string $escape = '';
2629

2730
protected function loadResource(string $resource): array
@@ -57,6 +60,10 @@ public function setCsvControl(string $delimiter = ';', string $enclosure = '"',
5760
{
5861
$this->delimiter = $delimiter;
5962
$this->enclosure = $enclosure;
63+
if ('' !== $escape) {
64+
trigger_deprecation('symfony/translation', '7.2', 'The "escape" parameter of the "%s" method is deprecated. It will be removed in 8.0.', __METHOD__);
65+
}
66+
6067
$this->escape = $escape;
6168
}
6269
}

Tests/Loader/CsvFileLoaderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
namespace Symfony\Component\Translation\Tests\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1516
use Symfony\Component\Config\Resource\FileResource;
1617
use Symfony\Component\Translation\Exception\InvalidResourceException;
1718
use Symfony\Component\Translation\Exception\NotFoundResourceException;
1819
use Symfony\Component\Translation\Loader\CsvFileLoader;
1920

2021
class CsvFileLoaderTest extends TestCase
2122
{
23+
use ExpectDeprecationTrait;
24+
2225
public function testLoad()
2326
{
2427
$loader = new CsvFileLoader();
@@ -54,4 +57,15 @@ public function testLoadNonLocalResource()
5457

5558
(new CsvFileLoader())->load('http://example.com/resources.csv', 'en', 'domain1');
5659
}
60+
61+
/**
62+
* @group legacy
63+
*/
64+
public function testEscapeCharInCsvControlIsDeprecated()
65+
{
66+
$loader = new CsvFileLoader();
67+
68+
$this->expectDeprecation('Since symfony/translation 7.2: The "escape" parameter of the "Symfony\Component\Translation\Loader\CsvFileLoader::setCsvControl" method is deprecated. It will be removed in 8.0.');
69+
$loader->setCsvControl(';', '"', '\\');
70+
}
5771
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"require": {
1919
"php": ">=8.2",
2020
"symfony/polyfill-mbstring": "~1.0",
21-
"symfony/translation-contracts": "^2.5|^3.0"
21+
"symfony/translation-contracts": "^2.5|^3.0",
22+
"symfony/deprecation-contracts": "^2.5|^3"
2223
},
2324
"require-dev": {
2425
"nikic/php-parser": "^4.18|^5.0",

0 commit comments

Comments
 (0)