Commit 5e2f2897 authored by Richard Weinhold's avatar Richard Weinhold 🎩

fixes type-casting problem when running Zip::copyTo()

parent fa7347b8
Pipeline #5412 passed with stages
in 9 seconds
......@@ -115,6 +115,21 @@ class File extends FileSystem
* @throws AccessDeniedException|FileNotFoundException
*/
public function copyTo(Storage $destination, ?int $constraints = null): self
{
if (!$this->copyFileTo($destination, $constraints)) {
throw new AccessDeniedException('unable to copy file', 403);
}
return new static($destination);
}
/**
* @param Storage &$destination mutable
* @param int|null $constraints
* @return bool success
* @throws AccessDeniedException|FileNotFoundException
*/
protected function copyFileTo(Storage &$destination, ?int $constraints = null): bool
{
$destination->setConstraints(($constraints !== null) ? $constraints : $this->storage->getConstraints());
......@@ -136,11 +151,7 @@ class File extends FileSystem
}
// actual copy file to file: use native functions if possible
if (!$this->storage->copyFileTo($destination)) {
throw new AccessDeniedException('unable to copy file', 403);
}
return new static($destination);
return $this->storage->copyFileTo($destination);
}
/**
......@@ -151,6 +162,22 @@ class File extends FileSystem
* @throws AccessDeniedException|FileNotFoundException
*/
public function moveTo(Storage $destination, ?int $constraints = null): self
{
// actual move file to file: use native functions if possible
if (!$this->moveFileTo($destination, $constraints)) {
throw new AccessDeniedException('unable to move file', 403);
}
return new static($destination);
}
/**
* @param Storage &$destination mutable
* @param int|null $constraints
* @return bool success
* @throws AccessDeniedException|FileNotFoundException
*/
public function moveFileTo(Storage &$destination, ?int $constraints = null): bool
{
$destination->setConstraints(($constraints !== null) ? $constraints : $this->storage->getConstraints());
......@@ -172,11 +199,7 @@ class File extends FileSystem
}
// actual move file to file: use native functions if possible
if (!$this->storage->moveFileTo($destination)) {
throw new AccessDeniedException('unable to move file', 403);
}
return new static($destination);
return $this->storage->moveFileTo($destination);
}
/**
......
......@@ -8,6 +8,7 @@ use ZipArchive;
use ricwein\FileSystem\Directory;
use ricwein\FileSystem\Exceptions\ConstraintsException;
use ricwein\FileSystem\Exceptions\RuntimeException;
use ricwein\FileSystem\Exceptions\AccessDeniedException;
use ricwein\FileSystem\Exceptions\FileNotFoundException;
use ricwein\FileSystem\Exceptions\UnexpectedValueException;
use ricwein\FileSystem\File;
......@@ -561,4 +562,31 @@ class Zip extends File
return null;
}
/**
* @inheritDoc
* @return File
*/
public function copyTo(Storage $destination, ?int $constraints = null): File
{
if (!$this->copyFileTo($destination, $constraints)) {
throw new AccessDeniedException('unable to copy file', 403);
}
return new File($destination);
}
/**
* @inheritDoc
* @return File
*/
public function moveTo(Storage $destination, ?int $constraints = null): File
{
// actual move file to file: use native functions if possible
if (!$this->moveFileTo($destination, $constraints)) {
throw new AccessDeniedException('unable to move file', 403);
}
return new File($destination);
}
}
......@@ -163,4 +163,15 @@ abstract class FileSystem
$this->storage->removeOnFree($activate);
return $this;
}
/**
* cast current object to given class-name,
* reusing internal storage-objects
* @param string $class
* @return self
*/
public function as(string $class): self
{
return new $class($this->storage);
}
}
......@@ -85,7 +85,6 @@ class DirectoryIterator
}
}
/**
* @param int|null $constraints
* @return File[]|Directory[]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment