Skip to content

Commit

Permalink
feat(Storage): Delegate provider responsibility to a new storage model
Browse files Browse the repository at this point in the history
  • Loading branch information
loicsapone committed Apr 24, 2024
1 parent 25fb503 commit cc49ce7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,50 @@

namespace Mezcalito\FileManagerBundle\Filesystem;

use Mezcalito\FileManagerBundle\Provider\ProviderInterface;

readonly class Filesystem implements FilesystemInterface
{
public function __construct(
private ProviderInterface $provider,
private StorageInterface $storage,
) {
}

public function read(string $id): string
{
return $this->provider->read($id);
return $this->storage->getProvider()->read($id);
}

public function write(string $id, string $contents): void
{
$this->provider->write($id, $contents);
$this->storage->getProvider()->write($id, $contents);
}

public function delete(string $id): void
{
$this->provider->delete($id);
$this->storage->getProvider()->delete($id);
}

public function move(string $id, string $source, string $destination): void
{
$this->provider->copy($id, $source, $destination);
$this->storage->getProvider()->copy($id, $source, $destination);
}

public function copy(string $id, string $source, string $destination): void
{
$this->provider->copy($id, $source, $destination);
$this->storage->getProvider()->copy($id, $source, $destination);
}

public function listDirectory(string $id, bool $recursive = false): \Generator
{
return $this->provider->listDirectory($id);
return $this->storage->getProvider()->listDirectory($id);
}

public function createDirectory(string $id, int $permissions = 0o777): void
{
$this->provider->createDirectory($id, $permissions);
$this->storage->getProvider()->createDirectory($id, $permissions);
}

public function deleteDirectory(string $id): void
{
$this->provider->deleteDirectory($id);
$this->storage->getProvider()->deleteDirectory($id);
}
}
29 changes: 29 additions & 0 deletions src/Filesystem/Storage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
* This file is part of the Mezcalito UX FileManager project.
*
* (c) Mezcalito <dev@mezcalito.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Mezcalito\FileManagerBundle\Filesystem;

use Mezcalito\FileManagerBundle\Provider\ProviderInterface;

readonly class Storage implements StorageInterface
{
public function __construct(
private ProviderInterface $provider,
) {
}

public function getProvider(): ProviderInterface
{
return $this->provider;
}
}
21 changes: 21 additions & 0 deletions src/Filesystem/StorageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Mezcalito UX FileManager project.
*
* (c) Mezcalito <dev@mezcalito.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Mezcalito\FileManagerBundle\Filesystem;

use Mezcalito\FileManagerBundle\Provider\ProviderInterface;

interface StorageInterface
{
public function getProvider(): ProviderInterface;
}

0 comments on commit cc49ce7

Please sign in to comment.