CsvFileDumper.php
1 month ago
DumperInterface.php
2 years ago
FileDumper.php
1 month ago
IcuResFileDumper.php
1 month ago
IniFileDumper.php
1 month ago
JsonFileDumper.php
1 month ago
MoFileDumper.php
1 month ago
PhpFileDumper.php
1 month ago
PoFileDumper.php
1 month ago
QtFileDumper.php
1 month ago
XliffFileDumper.php
1 month ago
YamlFileDumper.php
1 month ago
CsvFileDumper.php
54 lines
| 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 | namespace IAWPSCOPED\Symfony\Component\Translation\Dumper; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Component\Translation\MessageCatalogue; |
| 14 | /** |
| 15 | * CsvFileDumper generates a csv formatted string representation of a message catalogue. |
| 16 | * |
| 17 | * @author Stealth35 |
| 18 | * @internal |
| 19 | */ |
| 20 | class CsvFileDumper extends FileDumper |
| 21 | { |
| 22 | private string $delimiter = ';'; |
| 23 | private string $enclosure = '"'; |
| 24 | /** |
| 25 | * {@inheritdoc} |
| 26 | */ |
| 27 | public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []) : string |
| 28 | { |
| 29 | $handle = \fopen('php://memory', 'r+'); |
| 30 | foreach ($messages->all($domain) as $source => $target) { |
| 31 | \fputcsv($handle, [$source, $target], $this->delimiter, $this->enclosure); |
| 32 | } |
| 33 | \rewind($handle); |
| 34 | $output = \stream_get_contents($handle); |
| 35 | \fclose($handle); |
| 36 | return $output; |
| 37 | } |
| 38 | /** |
| 39 | * Sets the delimiter and escape character for CSV. |
| 40 | */ |
| 41 | public function setCsvControl(string $delimiter = ';', string $enclosure = '"') |
| 42 | { |
| 43 | $this->delimiter = $delimiter; |
| 44 | $this->enclosure = $enclosure; |
| 45 | } |
| 46 | /** |
| 47 | * {@inheritdoc} |
| 48 | */ |
| 49 | protected function getExtension() : string |
| 50 | { |
| 51 | return 'csv'; |
| 52 | } |
| 53 | } |
| 54 |