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