Пример #1
0
 private function uploadFile(File $file)
 {
     $file->setName($this->getUniqueFileName($file->getPath(), $file->getName()));
     if (!$this->fileSystem->writeStream($file->getUuid()->toString(), $file->getStream())) {
         throw new \RuntimeException('Failed to process uploaded file.');
     }
     $file->setStream($this->getFileStream($file->getUuid()));
 }
Пример #2
0
 public function create(BinaryFileCreateStruct $binaryFileCreateStruct)
 {
     try {
         $this->filesystem->writeStream($binaryFileCreateStruct->id, $binaryFileCreateStruct->getInputStream(), array('mimetype' => $binaryFileCreateStruct->mimeType, 'visibility' => AdapterInterface::VISIBILITY_PUBLIC));
     } catch (FileExistsException $e) {
         $this->filesystem->updateStream($binaryFileCreateStruct->id, $binaryFileCreateStruct->getInputStream(), array('mimetype' => $binaryFileCreateStruct->mimeType, 'visibility' => AdapterInterface::VISIBILITY_PUBLIC));
     }
 }
Пример #3
0
 /**
  * @param string|FilesystemInterface $moveTo
  * @return $this
  */
 public function move($moveTo)
 {
     if ($this->fileSystem) {
         $this->moveToFile($moveTo);
     } else {
         $fp = fopen($this->getFileName(), 'r+');
         $this->fileSystem->writeStream($moveTo, $fp);
         fclose($fp);
     }
     $this->config[self::FILE_LOC] = $moveTo;
     return $this;
 }
Пример #4
0
 /**
  * @param string $sourcePath
  * @param string $targetPath
  *
  * @return bool
  */
 protected function move($sourcePath, $targetPath)
 {
     if ($this->filesystem->has($targetPath)) {
         return false;
     }
     $stream = fopen($sourcePath, 'r+');
     if ($stream === null) {
         return false;
     }
     $success = $this->filesystem->writeStream($targetPath, $stream);
     if (fclose($stream) === false) {
         return false;
     }
     return $success;
 }
Пример #5
0
 public function it_rolls_back_after_exception(File $file, \PDOStatement $uniqueStatement)
 {
     $uuid = Uuid::uuid4();
     $name = FileNameValue::get('file.name');
     $path = FilePathValue::get('/uploads');
     $stream = tmpfile();
     $file->getUuid()->willReturn($uuid);
     $file->getName()->willReturn($name);
     $file->setName($name)->willReturn($file);
     $file->getPath()->willReturn($path);
     $file->getStream()->willReturn($stream);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->objectRepository->create(File::TYPE, $uuid)->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('name REGEXP :name'))->willReturn($uniqueStatement);
     $uniqueStatement->execute(['path' => $path->toString(), 'name' => 'file(_(?P<idx>[0-9]+))?\\.name'])->shouldBeCalled();
     $uniqueStatement->rowCount()->willReturn(0);
     $this->fileSystem->writeStream($uuid->toString(), $stream)->willReturn(false);
     $this->pdo->rollBack()->shouldBeCalled();
     $this->fileSystem->has($uuid->toString())->willReturn(false);
     $this->shouldThrow(\RuntimeException::class)->duringCreateFromUpload($file);
 }
Пример #6
0
 /**
  * Write a new file using a stream.
  *
  * @param string   $path     The path of the new file.
  * @param resource $resource The file handle.
  * @param array    $config   An optional configuration array.
  *
  * @throws \League\Flysystem\InvalidArgumentException If $resource is not a file handle.
  * @throws FileExistsException
  *
  * @return bool True on success, false on failure.
  */
 public function writeStream($path, $resource, array $config = [])
 {
     return $this->fileSystem->writeStream($path, $resource, $config);
 }
Пример #7
0
 /**
  * @param resource $stream
  */
 public function write($stream)
 {
     $this->_filesystem->delete($this->getPath());
     $this->_filesystem->writeStream($this->getPath(), $stream);
 }