/**
  * Loads a Ini, JSON,PHP, XML or YAML file using a FileReader. Throws exception if file cannot be loaded.
  *
  * @param  string $filePath
  * @return array
  * @throws \Sonrisa\Component\FileReader\Exceptions\FileReaderException
  */
 public static function parse($filePath)
 {
     if (File::exists($filePath)) {
         //get file extension
         $ext = File::getExtension($filePath);
         switch ($ext) {
             case 'ini':
                 $data = IniFileReader::parse($filePath);
                 break;
             case 'json':
                 $data = JsonFileReader::parse($filePath);
                 break;
             case 'php':
                 $data = PhpFileReader::parse($filePath);
                 break;
             case 'xml':
                 $data = XmlFileReader::parse($filePath);
                 break;
             case 'yaml':
             case 'yml':
                 $data = YmlFileReader::parse($filePath);
                 break;
             default:
                 throw new FileReaderException("Could not read {$filePath} using a FileReader.");
                 break;
         }
         if (empty($data)) {
             return array();
         } else {
             return $data;
         }
     } else {
         throw new FileReaderException("Could not load {$filePath}. File does not exist.");
     }
 }
 /**
  * Loads the file into memory.
  *
  * @throws \Sonrisa\Component\FileReader\Exceptions\FileReaderException
  */
 protected static function load($filePath)
 {
     try {
         return File::read($filePath);
     } catch (FileSystemException $e) {
         throw new FileReaderException($e);
     }
 }
 /**
  * Loads the file into memory.
  *
  * @param  string                                                            $filePath
  * @return AbstractFileReader
  * @throws \Sonrisa\Component\FileReader\Exceptions\FileReaderException
  */
 protected static function load($filePath)
 {
     if (File::exists($filePath)) {
         $data = (include realpath($filePath));
         if (!empty($data)) {
             return $data;
         }
         return array();
     } else {
         throw new FileReaderException("File {$filePath} does not exists.");
     }
 }
Example #4
0
 public function tearDown()
 {
     if (File::exists($this->filename)) {
         File::delete($this->filename);
     }
     if (File::exists('test.zip')) {
         File::delete('test.zip');
     }
     $this->file = NULL;
 }