Skip to content

Commit

Permalink
Type Flysystem
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinArtus committed Apr 21, 2023
1 parent 17fb146 commit 79eda31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
7 changes: 1 addition & 6 deletions src/Gaufrette/Adapter/FileFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ interface FileFactory
{
/**
* Creates a new File instance and returns it.
*
* @param string $key
* @param Filesystem $filesystem
*
* @return File
*/
public function createFile($key, Filesystem $filesystem);
public function createFile(string $key, Filesystem $filesystem): File;
}
35 changes: 13 additions & 22 deletions src/Gaufrette/Adapter/Flysystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,52 @@
use Gaufrette\Exception\UnsupportedAdapterMethodException;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Util;
use League\Flysystem\Config;

class Flysystem implements Adapter, ListKeysAware
{
/**
* @var AdapterInterface
*/
private $adapter;

/**
* @var Config
*/
private $config;
private Config $config;

/**
* @param AdapterInterface $adapter
* @param \League\Flysystem\Config|array|null $config
* @param Config|array|null $config
*/
public function __construct(AdapterInterface $adapter, $config = null)
public function __construct(private readonly AdapterInterface $adapter, $config = null)
{
if (!interface_exists(AdapterInterface::class)) {
throw new \LogicException('You need to install package "league/flysystem" to use this adapter');
}

$this->adapter = $adapter;
$this->config = Util::ensureConfig($config);
}

/**
* {@inheritdoc}
*/
public function read($key)
public function read(string $key): string|bool
{
return $this->adapter->read($key)['contents'];
}

/**
* {@inheritdoc}
*/
public function write($key, $content)
public function write(string $key, mixed $content): int|bool
{
return $this->adapter->write($key, $content, $this->config);
}

/**
* {@inheritdoc}
*/
public function exists($key)
public function exists(string $key): bool
{
return (bool) $this->adapter->has($key);
}

/**
* {@inheritdoc}
*/
public function keys()
public function keys(): array
{
return array_map(function ($content) {
return $content['path'];
Expand All @@ -70,7 +61,7 @@ public function keys()
/**
* {@inheritdoc}
*/
public function listKeys($prefix = '')
public function listKeys(string $prefix = ''): array
{
$dirs = [];
$keys = [];
Expand All @@ -94,31 +85,31 @@ public function listKeys($prefix = '')
/**
* {@inheritdoc}
*/
public function mtime($key)
public function mtime(string $key): int|bool
{
return $this->adapter->getTimestamp($key);
}

/**
* {@inheritdoc}
*/
public function delete($key)
public function delete(string $key): bool
{
return $this->adapter->delete($key);
}

/**
* {@inheritdoc}
*/
public function rename($sourceKey, $targetKey)
public function rename(string $sourceKey, string $targetKey): bool
{
return $this->adapter->rename($sourceKey, $targetKey);
}

/**
* {@inheritdoc}
*/
public function isDirectory($key)
public function isDirectory(string $key): bool
{
throw new UnsupportedAdapterMethodException('isDirectory is not supported by this adapter.');
}
Expand Down

0 comments on commit 79eda31

Please sign in to comment.