diff --git a/Filesystem.php b/Filesystem.php index 521eecc..c4984a6 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -20,32 +20,52 @@ public function __construct( private AdapterInterface $adapter, ) {} - public function write(string $path, mixed $contents, ?ContextInterface $context = null): void + public function write(string $path, mixed $contents, ContextInterface|array $context = null): void { if (!is_string($contents) && !is_resource($contents)) { throw new FilesystemException(sprintf('Argument "$contents" must be of type "string" or "resource". Type "%s" given.', gettype($contents))); } + if (is_array($context)) { + $context = new Context($context); + } + $this->adapter->add($path, $contents, $context); } - public function read(string $path, ?ContextInterface $context = null): string + public function read(string $path, ContextInterface|array $context = null): string { + if (is_array($context)) { + $context = new Context($context); + } + return $this->adapter->get($path, $context); } - public function delete(string $path, ?ContextInterface $context = null): void + public function delete(string $path, ContextInterface|array $context = null): void { + if (is_array($context)) { + $context = new Context($context); + } + $this->adapter->remove($path, $context); } - public function exists(string $path, ?ContextInterface $context = null): bool + public function exists(string $path, ContextInterface|array $context = null): bool { + if (is_array($context)) { + $context = new Context($context); + } + return $this->adapter->has($path, $context); } - public function copy(string $source, string $destination, ?ContextInterface $context = null): void + public function copy(string $source, string $destination, ContextInterface|array $context = null): void { + if (is_array($context)) { + $context = new Context($context); + } + if ($this->adapter instanceof CopyAwareInterface) { $this->adapter->copy($source, $destination); return; @@ -54,8 +74,12 @@ public function copy(string $source, string $destination, ?ContextInterface $con $this->write($destination, $this->get($source, $context), $context); } - public function move(string $source, string $destination, ?ContextInterface $context = null): void + public function move(string $source, string $destination, ContextInterface|array $context = null): void { + if (is_array($context)) { + $context = new Context($context); + } + if ($this->adapter instanceof MoveAwareInterface) { $this->adapter->move($source, $destination, $context); return; @@ -65,8 +89,12 @@ public function move(string $source, string $destination, ?ContextInterface $con $this->delete($source, $context); } - public function mimeType(string $path, ?ContextInterface $context = null): string + public function mimeType(string $path, ContextInterface|array $context = null): string { + if (is_array($context)) { + $context = new Context($context); + } + return $this->adapter->mimeType($path, $context); } }