Skip to content

Init league/flysystem-v3 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
"ext-fileinfo": "*",
"ext-json": "*",
"ext-mbstring": "*",
"php-collective/file-storage-factories": "dev-master as 1.0",
"php-collective/file-storage-factories": "dev-league/flysystem-v3 as 1.0",
"psr/http-message": "^1.0|^2.0"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.3",
"php-collective/code-sniffer": "^0.2.1",
"php-collective/file-storage-image-processor": "dev-master as 1.0"
"php-collective/code-sniffer": "^0.2.1"
},
"suggest": {
"php-collective/file-storage-image-processor": "For image processing"
Expand Down
10 changes: 5 additions & 5 deletions src/AdapterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use ArrayIterator;
use Iterator;
use League\Flysystem\AdapterInterface;
use League\Flysystem\FilesystemAdapter;
use RuntimeException;

/**
Expand All @@ -38,13 +38,13 @@ public function __construct()

/**
* @param string $name Name
* @param \League\Flysystem\AdapterInterface $adapter Adapter
* @param \League\Flysystem\FilesystemAdapter $adapter Adapter
*
* @throws \RuntimeException
*
* @return void
*/
public function add($name, AdapterInterface $adapter)
public function add($name, FilesystemAdapter $adapter)
{
if ($this->has($name)) {
throw new RuntimeException(sprintf(
Expand Down Expand Up @@ -81,9 +81,9 @@ public function has(string $name): bool
*
* @throws \RuntimeException
*
* @return \League\Flysystem\AdapterInterface
* @return \League\Flysystem\FilesystemAdapter
*/
public function get(string $name): AdapterInterface
public function get(string $name): FilesystemAdapter
{
if (!$this->has($name)) {
throw new RuntimeException(sprintf(
Expand Down
10 changes: 5 additions & 5 deletions src/AdapterCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace PhpCollective\Infrastructure\Storage;

use IteratorAggregate;
use League\Flysystem\AdapterInterface;
use League\Flysystem\FilesystemAdapter;

/**
* Factory Collection Interface
Expand All @@ -23,11 +23,11 @@ interface AdapterCollectionInterface extends IteratorAggregate
{
/**
* @param string $name Name
* @param \League\Flysystem\AdapterInterface $adapter Adapter
* @param \League\Flysystem\FilesystemAdapter $adapter Adapter
*
* @return void
*/
public function add($name, AdapterInterface $adapter);
public function add($name, FilesystemAdapter $adapter);

/**
* @param string $name Name
Expand All @@ -46,9 +46,9 @@ public function has(string $name): bool;
/**
* @param string $name
*
* @return \League\Flysystem\AdapterInterface
* @return \League\Flysystem\FilesystemAdapter
*/
public function get(string $name): AdapterInterface;
public function get(string $name): FilesystemAdapter;

/**
* Empties the collection
Expand Down
6 changes: 3 additions & 3 deletions src/FileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
namespace PhpCollective\Infrastructure\Storage;

use InvalidArgumentException;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\FilesystemAdapter;
use PhpCollective\Infrastructure\Storage\PathBuilder\PathBuilderInterface;
use PhpCollective\Infrastructure\Storage\Processor\Exception\VariantDoesNotExistException;
use PhpCollective\Infrastructure\Storage\Processor\Exception\VariantException;
Expand Down Expand Up @@ -203,9 +203,9 @@ public function removeVariant(FileInterface $file, string $name): FileInterface
*
* @param string $storage Storage name to use
*
* @return \League\Flysystem\AdapterInterface
* @return \League\Flysystem\FilesystemAdapter
*/
public function getStorage(string $storage): AdapterInterface
public function getStorage(string $storage): FilesystemAdapter
{
return $this->storageService->adapter($storage);
}
Expand Down
6 changes: 3 additions & 3 deletions src/FileStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

namespace PhpCollective\Infrastructure\Storage;

use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\FilesystemAdapter;

/**
* FileStorageInterface
Expand Down Expand Up @@ -55,7 +55,7 @@ public function removeVariant(FileInterface $file, string $name): FileInterface;
*
* @param string $storage Storage name to use
*
* @return \League\Flysystem\AdapterInterface
* @return \League\Flysystem\FilesystemAdapter
*/
public function getStorage(string $storage): AdapterInterface;
public function getStorage(string $storage): FilesystemAdapter;
}
50 changes: 12 additions & 38 deletions src/StorageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

namespace PhpCollective\Infrastructure\Storage;

use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use PhpCollective\Infrastructure\Storage\Exception\StorageException;
use League\Flysystem\FilesystemAdapter;
use PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryNotFoundException;
use RuntimeException;

Expand Down Expand Up @@ -81,7 +80,7 @@ public function adapters(): AdapterCollectionInterface
*
* @throws \PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryNotFoundException
*/
public function adapter(string $name): AdapterInterface
public function adapter(string $name): FilesystemAdapter
{
if ($this->adapterCollection->has($name)) {
return $this->adapterCollection->get($name);
Expand All @@ -103,9 +102,9 @@ public function adapter(string $name): AdapterInterface
* @param string $adapter Adapter
* @param array $options
*
* @return \League\Flysystem\AdapterInterface
* @return \League\Flysystem\FilesystemAdapter
*/
public function loadAdapter(string $name, string $adapter, array $options): AdapterInterface
public function loadAdapter(string $name, string $adapter, array $options): FilesystemAdapter
{
$adapter = $this->adapterFactory->buildStorageAdapter(
$adapter,
Expand Down Expand Up @@ -174,45 +173,20 @@ protected function makeConfigIfNeeded(?Config $config)

/**
* @inheritDoc
*
* @throws \PhpCollective\Infrastructure\Storage\Exception\StorageException
*/
public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): array
public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): void
{
$config = $this->makeConfigIfNeeded($config);
$result = $this->adapter($adapter)->writeStream($path, $resource, $config);

if ($result === false) {
throw new StorageException(sprintf(
'Failed to store resource stream to in `%s` with path `%s`',
$adapter,
$path,
));
}

return $result;
$this->adapter($adapter)->writeStream($path, $resource, $config);
}

/**
* @inheritDoc
*
* @throws \PhpCollective\Infrastructure\Storage\Exception\StorageException
*/
public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): array
public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): void
{
$config = $this->makeConfigIfNeeded($config);
$result = $this->adapter($adapter)->write($path, (string)file_get_contents($file), $config);

if ($result === false) {
throw new StorageException(sprintf(
'Failed to store file `%s` in `%s` with path `%s`',
$file,
$adapter,
$path,
));
}

return $result;
$this->adapter($adapter)->write($path, (string)file_get_contents($file), $config);
}

/**
Expand All @@ -223,17 +197,17 @@ public function storeFile(string $adapter, string $path, string $file, ?Config $
*/
public function fileExists(string $adapter, string $path): bool
{
return $this->adapter($adapter)->has($path);
return $this->adapter($adapter)->fileExists($path);
}

/**
* @param string $adapter Name
* @param string $path File to delete
*
* @return bool
* @return void
*/
public function removeFile(string $adapter, string $path): bool
public function removeFile(string $adapter, string $path): void
{
return $this->adapter($adapter)->delete($path);
$this->adapter($adapter)->delete($path);
}
}
18 changes: 9 additions & 9 deletions src/StorageServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

namespace PhpCollective\Infrastructure\Storage;

use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\FilesystemAdapter;

/**
* StorageServiceInterface
Expand All @@ -41,9 +41,9 @@ public function adapters(): AdapterCollectionInterface;
*
* @param string $name
*
* @return \League\Flysystem\AdapterInterface
* @return \League\Flysystem\FilesystemAdapter
*/
public function adapter(string $name): AdapterInterface;
public function adapter(string $name): FilesystemAdapter;

/**
* Adds an adapter config
Expand All @@ -64,9 +64,9 @@ public function addAdapterConfig(string $name, string $class, array $options);
* @param resource $resource Resource to store
* @param \League\Flysystem\Config|null $config
*
* @return array
* @return void
*/
public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): array;
public function storeResource(string $adapter, string $path, $resource, ?Config $config = null): void;

/**
* Stores a file in a storage backend
Expand All @@ -76,9 +76,9 @@ public function storeResource(string $adapter, string $path, $resource, ?Config
* @param string $file File to store
* @param \League\Flysystem\Config|null $config
*
* @return array
* @return void
*/
public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): array;
public function storeFile(string $adapter, string $path, string $file, ?Config $config = null): void;

/**
* Checks if a file exists in a store
Expand All @@ -96,7 +96,7 @@ public function fileExists(string $adapter, string $path): bool;
* @param string $adapter Name
* @param string $path File to delete
*
* @return bool
* @return void
*/
public function removeFile(string $adapter, string $path): bool;
public function removeFile(string $adapter, string $path): void;
}