CsvFileLoader.php in Plug 7
File
lib/Symfony/translation/Loader/CsvFileLoader.php
View source
<?php
namespace Symfony\Component\Translation\Loader;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
class CsvFileLoader extends FileLoader {
private $delimiter = ';';
private $enclosure = '"';
private $escape = '\\';
protected function loadResource($resource) {
$messages = array();
try {
$file = new \SplFileObject($resource, 'rb');
} catch (\RuntimeException $e) {
throw new NotFoundResourceException(sprintf('Error opening file "%s".', $resource), 0, $e);
}
$file
->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
$file
->setCsvControl($this->delimiter, $this->enclosure, $this->escape);
foreach ($file as $data) {
if (substr($data[0], 0, 1) === '#') {
continue;
}
if (!isset($data[1])) {
continue;
}
if (count($data) == 2) {
$messages[$data[0]] = $data[1];
}
else {
continue;
}
}
return $messages;
}
public function setCsvControl($delimiter = ';', $enclosure = '"', $escape = '\\') {
$this->delimiter = $delimiter;
$this->enclosure = $enclosure;
$this->escape = $escape;
}
}