コード例 #1
0
ファイル: FileDataBackend.php プロジェクト: malkusch/bav
 /**
  * This method works only if your PHP is compiled with cURL.
  *
  * @see DataBackend::update()
  * @throws DataBackendIOException
  * @throws FileException
  * @throws DownloaderException
  */
 public function update()
 {
     $downloader = new Downloader();
     $content = $downloader->downloadContent(self::DOWNLOAD_URI);
     $uriPicker = new FallbackURIPicker();
     $path = $uriPicker->pickURI($content);
     if (strlen($path) > 0 && $path[0] != "/") {
         $path = sprintf("/%s/%s", dirname(self::DOWNLOAD_URI), $path);
     }
     $pathParts = explode('/', $path);
     foreach ($pathParts as $i => $part) {
         switch ($part) {
             case '..':
                 unset($pathParts[$i - 1]);
                 // fall-through as the current part ("..") should be removed as well.
             // fall-through as the current part ("..") should be removed as well.
             case '.':
                 unset($pathParts[$i]);
                 break;
         }
     }
     $path = implode('/', $pathParts);
     $urlParts = parse_url(self::DOWNLOAD_URI);
     $url = sprintf("%s://%s%s", $urlParts["scheme"], $urlParts["host"], $path);
     // download file
     $file = $downloader->downloadFile($url);
     // Validate file format.
     $validator = new FileValidator();
     $validator->validate($file);
     // blz_20100308.txt is not sorted.
     $parser = new FileParser($file);
     $lastBankID = $parser->getBankID($parser->getLines());
     if ($lastBankID < 80000000) {
         $this->sortFile($file);
     }
     $this->fileUtil->safeRename($file, $this->parser->getFile());
     chmod($this->parser->getFile(), 0644);
 }