Skip to content

Commit

Permalink
Filesystem Updates (#219)
Browse files Browse the repository at this point in the history
## Description



## Checklist
- [ ] Updated CHANGELOG files
- [ ] Updated Documentation
- [ ] Unit Tests Created
- [ ] php-cs-fixer
  • Loading branch information
JoshuaEstes authored Aug 24, 2024
1 parent f8681b2 commit 1ee9102
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}

0 comments on commit 1ee9102

Please sign in to comment.