download() public method

file download from storage
public download ( File $file, string | null $name = null ) : void
$file File file instance
$name string | null name of be downloaded file
return void
Ejemplo n.º 1
0
 public function testDownloadThrownExceptionWhenFileNotExists()
 {
     list($handler, $repo, $auth, $keygen) = $this->getMocks();
     $mockFile = m::mock('Xpressengine\\Storage\\File');
     $handler->shouldReceive('exists')->once()->with($mockFile)->andReturn(false);
     $instance = new Storage($handler, $repo, $auth, $keygen);
     try {
         $instance->download($mockFile);
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertInstanceOf('Xpressengine\\Storage\\Exceptions\\FileDoesNotExistException', $e);
     }
 }
Ejemplo n.º 2
0
 /**
  * file download
  *
  * @param EditorHandler $handler    editor handler
  * @param Storage       $storage    storage
  * @param string        $instanceId instance id
  * @param string        $id
  * @return void
  */
 public function fileDownload(EditorHandler $handler, Storage $storage, $instanceId, $id)
 {
     if (empty($id) || !($file = File::find($id))) {
         throw new InvalidArgumentException();
     }
     if (Gate::denies('download', new Instance($handler->getPermKey($instanceId)))) {
         throw new AccessDeniedHttpException();
     }
     $storage->download($file);
 }