コード例 #1
0
 public function writeStream($path, $resource)
 {
     try {
         return $this->filesystem->writeStream($path, $resource);
     } catch (FileExistsException $exception) {
         return $this->filesystem->updateStream($path, $resource);
     }
 }
コード例 #2
0
 /**
  * 1.txt
  * 2.txt.
  */
 public function testUpdateStream()
 {
     $stream = tmpfile();
     fwrite($stream, 'OSS text2');
     rewind($stream);
     $this->assertTrue($this->filesystem->updateStream('2.txt', $stream));
     fclose($stream);
 }
コード例 #3
0
 function it_should_successfully_update_stream($path, Filesystem $filesystem)
 {
     $filesystem->writeStream($path, 'resource2')->willThrow('League\\Flysystem\\FileExistsException');
     $filesystem->updateStream($path, 'resource2')->willReturn(true);
     $this->writeStream($path, 'resource2');
     $filesystem->writeStream($path, 'resource2')->shouldBeCalled();
     $filesystem->updateStream($path, 'resource2')->shouldBeCalled();
 }
コード例 #4
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testUpdateStreamFail()
 {
     $adapter = Mockery::mock('League\\Flysystem\\AdapterInterface');
     $adapter->shouldReceive('has')->andReturn(true);
     $filesystem = new Filesystem($adapter);
     $filesystem->updateStream('file.txt', 'not a resource');
 }
コード例 #5
0
 /**
  * @inheritdoc
  */
 public function updateStream($path, $resource, array $config = [])
 {
     try {
         return $this->fileSystem->updateStream($this->getInnerPath($path), $resource, $config);
     } catch (FileNotFoundException $e) {
         throw $this->exceptionWrapper($e, $path);
     }
 }
コード例 #6
0
 /**
  * Update an existing file using a stream.
  *
  * @param string   $path     The path of the existing file.
  * @param resource $resource The file handle.
  * @param array    $config   An optional configuration array.
  *
  * @throws InvalidArgumentException If $resource is not a file handle.
  * @throws FileNotFoundException
  *
  * @return bool True on success, false on failure.
  */
 public function updateStream($path, $resource, array $config = [])
 {
     $result = parent::updateStream($path, $resource, $config);
     if ($result && ($resource = $this->get($path))) {
         return $this->dispatch(new SyncFile($resource));
     }
     return $result;
 }
コード例 #7
0
 public function testUpdateStreamInvalid()
 {
     $this->setExpectedException('InvalidArgumentException');
     $this->filesystem->updateStream('path.txt', '__INVALID__');
 }
コード例 #8
0
ファイル: FileManager.php プロジェクト: romeoz/rock-file
 /**
  * @inheritdoc
  */
 public function updateStream($path, $resource, array $config = [])
 {
     try {
         return parent::updateStream($path, $resource, $config);
     } catch (\Exception $e) {
         $this->errors[] = $e->getMessage();
     }
     return false;
 }