Esempio n. 1
0
 /**
  *	Получает прямую ссылку
  *
  *	@return	string
  *	@throws	mixed
  */
 public function getLink()
 {
     if (!$this->has()) {
         throw new Exception\NotFoundException('Не возможно скачать, данный ресурс не публичный ?');
     }
     $response = $this->request->get($this->parent_disk->getRequestUrl('public/resources/download', array('public_key' => $this->getPublicKey(), 'path' => (string) $this->path())));
     if (empty($response['href'])) {
         throw new \UnexpectedValueException('Не удалось запросить разрешение на скачивание, повторите заново');
     }
     return $response['href'];
 }
Esempio n. 2
0
 /**
  *	Скачивает файл
  *
  *	@param	$path	Путь, по которому будет сохранён файл
  *	@param	mixed	$overwrite
  *	@param	mixed	$progress
  *	@return	boolean
  *	@throws	mixed
  */
 public function download($path, $overwrite = false, $progress = null)
 {
     if (!$this->has()) {
         throw new Exception\NotFoundException('Не возможно скачать, данный ресурс отсутствует на диске ?');
     }
     if ($overwrite instanceof \Closure) {
         $progress = $overwrite;
         $overwrite = false;
     }
     if (is_file($path) && !$overwrite) {
         throw new \OutOfBoundsException('Такой файл существует, передайте true Чтобы перезаписать его');
     }
     if (!is_writable(dirname($path))) {
         throw new \OutOfBoundsException('Запись в директорию где должен быть располоен файл не возможна');
     }
     $response = $this->request->get($this->parent_disk->getRequestUrl('resources/download', array('path' => $this->resource_path)));
     if (empty($response['href'])) {
         throw new \UnexpectedValueException('Не удалось запросить закачку, повторите заново');
     }
     if ($progress instanceof \Closure) {
         $this->request->progress(function ($curl, $download, $downloaded, $upload, $uploaded) use($progress) {
             return $progress($download, $downloaded, $curl);
         });
     }
     $put_data = $path;
     $this->request->setTimeout(null);
     $this->request->setOpt(CURLOPT_FOLLOWLOCATION, true);
     if ($this->hasEncrypted()) {
         $encrypted = $this->get('custom_properties', []);
         $this->phrase($encrypted['encrypted_phrase'])->vector(base64_decode($encrypted['encrypted_vector']));
         $put_data = function ($instance, $fh) use($path, $encrypted) {
             $fp = fopen($path, 'wb');
             while (!feof($fh)) {
                 fwrite($fp, $this->decrypt(fread($fh, $encrypted['encrypted_block'])));
             }
             fclose($fp);
         };
     }
     $this->request->download($response['href'], $put_data);
     $this->request->setDefaultTimeout();
     $this->request->progress(null);
     if (isset($encrypted['encrypted']) && (($hash_file = $encrypted['encrypted']) || ($hash_file = $md5)) && $hash_file !== md5_file($path)) {
         throw new \RangeException('Файл скачан, но контрольные суммы различаются.');
     }
     return $this->request->http_status_code == 200;
 }
Esempio n. 3
0
 /**
  *	Получить данные контейнера
  *
  *	@return  array  контейнер
  */
 public function getContents()
 {
     if (!parent::getContents()) {
         $response = $this->request->get($this->parent_disk->getRequestUrl('trash/resources', array_merge($this->request_params, array('path' => $this->resource_path))));
         if (isset($response['type'])) {
             $this->resource_type = $response['type'];
         }
         if (isset($response['_embedded']['items'])) {
             $response['items'] = array_map(function ($item) {
                 return new self($item, $this->parent_disk, $this->request);
             }, $response['_embedded']['items']);
         }
         unset($response['_links'], $response['_embedded']);
         parent::__construct($response);
     }
     return parent::getContents();
 }