Explorar o código

use SplFileInfo insteed fgetcsv

stealth35 %!s(int64=14) %!d(string=hai) anos
pai
achega
58cd03cedf
Modificáronse 1 ficheiros con 9 adicións e 4 borrados
  1. 9 4
      src/Symfony/Component/Translation/Loader/CsvFileLoader.php

+ 9 - 4
src/Symfony/Component/Translation/Loader/CsvFileLoader.php

@@ -30,12 +30,17 @@ class CsvFileLoader extends ArrayLoader implements LoaderInterface
     public function load($resource, $locale, $domain = 'messages')
     {
         $messages = array();
-        $file = @fopen($resource, 'rb');
-        if (!$file) {
-            throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
+        
+        try {
+        	$file = new \SplFileObject($resource, 'rb');
+        } catch(\RuntimeException $e) {
+        	throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource));
         }
+        
+        $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY);
+        $file->setCsvControl(';');
 
-        while (($data = fgetcsv($file, 0, ';')) !== false) {
+        foreach($file as $data) {
             if (substr($data[0], 0, 1) === '#') {
                 continue;
             }