composer package updates
[openemr.git] / vendor / symfony / translation / Loader / CsvFileLoader.php
blobf1d3443f4c7ea56bc9571a1568762da4ae79103f
1 <?php
3 /*
4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Loader;
14 use Symfony\Component\Translation\Exception\NotFoundResourceException;
16 /**
17 * CsvFileLoader loads translations from CSV files.
19 * @author Saša Stamenković <umpirsky@gmail.com>
21 class CsvFileLoader extends FileLoader
23 private $delimiter = ';';
24 private $enclosure = '"';
25 private $escape = '\\';
27 /**
28 * {@inheritdoc}
30 protected function loadResource($resource)
32 $messages = array();
34 try {
35 $file = new \SplFileObject($resource, 'rb');
36 } catch (\RuntimeException $e) {
37 throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
40 $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
41 $file->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
43 foreach ($file as $data) {
44 if ('#' !== substr($data[0], 0, 1) && isset($data[1]) && 2 === count($data)) {
45 $messages[$data[0]] = $data[1];
49 return $messages;
52 /**
53 * Sets the delimiter, enclosure, and escape character for CSV.
55 * @param string $delimiter delimiter character
56 * @param string $enclosure enclosure character
57 * @param string $escape escape character
59 public function setCsvControl($delimiter = ';', $enclosure = '"', $escape = '\\')
61 $this->delimiter = $delimiter;
62 $this->enclosure = $enclosure;
63 $this->escape = $escape;