Skip to content

Commit 4d5feb7

Browse files
committed
Upgrade to league/flysystem v3
1 parent 002333a commit 4d5feb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+282
-395
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Storage Factories for Flysystem
22

3+
[![CI](https://github.com/php-collective/file-storage-factories/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/php-collective/file-storage-factories/actions/workflows/ci.yml)
34
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
45

56
In the underlying Flysystem implementation some adapters are more or less complex to build. Sometimes you have to compose multiple objects and feed them to an adapter. The factories take this burden away from you and provide you the same interface for all adapters. Just their config array options differ.

composer.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@
3030
"prefer-stable": true,
3131
"require": {
3232
"php": ">=8.1",
33-
"league/flysystem": "^1.0",
33+
"league/flysystem": "^3.22",
3434
"psr/container": "^1.0|^2.0"
3535
},
3636
"require-dev": {
3737
"phpunit/phpunit": "^10.3",
3838
"phpstan/phpstan": "^1.10",
3939
"php-collective/code-sniffer": "^0.2.1",
4040
"instituteweb/composer-scripts": "^1.1",
41-
"league/flysystem-aws-s3-v3": "^1.0.29",
42-
"league/flysystem-azure": "^1.0",
43-
"league/flysystem-azure-blob-storage": "^1.0",
44-
"league/flysystem-gridfs": "^1.0",
45-
"league/flysystem-memory": "^1.0",
46-
"league/flysystem-rackspace": "^1.0",
47-
"league/flysystem-replicate-adapter": "^1.0",
48-
"league/flysystem-sftp": "^1.0",
49-
"league/flysystem-webdav": "^1.0",
50-
"league/flysystem-ziparchive": "^1.0",
51-
"spatie/flysystem-dropbox": "^1.2"
41+
"league/flysystem-aws-s3-v3": "^3.22",
42+
"league/flysystem-azure-blob-storage": "^3.22",
43+
"league/flysystem-memory": "^3.0",
44+
"league/flysystem-sftp": "^3.22",
45+
"league/flysystem-webdav": "^3.21",
46+
"league/flysystem-ziparchive": "^3.21",
47+
"spatie/flysystem-dropbox": "^3.0.1"
5248
},
5349
"autoload": {
5450
"psr-4": {

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ parameters:
55
checkMissingIterableValueType: false
66
checkGenericClassInNonGenericObjectType: false
77
ignoreErrors:
8-
- '#Call to an undefined static method .+BlobRestProxy::createBlobService\(\).#'
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?php
2+
3+
namespace PhpCollective\Infrastructure\Storage\Adapter;
4+
5+
use League\Flysystem\Config;
6+
use League\Flysystem\FileAttributes;
7+
use League\Flysystem\FilesystemAdapter;
8+
9+
class NullFilesystemAdapter implements FilesystemAdapter
10+
{
11+
/**
12+
* @param string $path
13+
*
14+
* @return bool
15+
*/
16+
public function fileExists(string $path): bool
17+
{
18+
return false;
19+
}
20+
21+
/**
22+
* @param string $path
23+
* @param string $contents
24+
* @param \League\Flysystem\Config $config
25+
*
26+
* @return void
27+
*/
28+
public function write(string $path, string $contents, Config $config): void
29+
{
30+
}
31+
32+
/**
33+
* @param string $path
34+
* @param $contents
35+
* @param \League\Flysystem\Config $config
36+
*
37+
* @return void
38+
*/
39+
public function writeStream(string $path, $contents, Config $config): void
40+
{
41+
}
42+
43+
/**
44+
* @param string $path
45+
*
46+
* @return string
47+
*/
48+
public function read(string $path): string
49+
{
50+
return '';
51+
}
52+
53+
/**
54+
* @param string $path
55+
*
56+
* @return resource
57+
*/
58+
public function readStream(string $path)
59+
{
60+
/** @var resource $stream */
61+
$stream = fopen('php://temp', 'w+b');
62+
fwrite($stream, '');
63+
rewind($stream);
64+
65+
return $stream;
66+
}
67+
68+
/**
69+
* @param string $path
70+
*
71+
* @return void
72+
*/
73+
public function delete(string $path): void
74+
{
75+
}
76+
77+
/**
78+
* @param string $path
79+
*
80+
* @return void
81+
*/
82+
public function deleteDirectory(string $path): void
83+
{
84+
}
85+
86+
/**
87+
* @param string $path
88+
* @param \League\Flysystem\Config $config
89+
*
90+
* @return void
91+
*/
92+
public function createDirectory(string $path, Config $config): void
93+
{
94+
}
95+
96+
/**
97+
* @param string $path
98+
* @param string $visibility
99+
*
100+
* @return void
101+
*/
102+
public function setVisibility(string $path, string $visibility): void
103+
{
104+
}
105+
106+
/**
107+
* @param string $path
108+
*
109+
* @return \League\Flysystem\FileAttributes
110+
*/
111+
public function visibility(string $path): FileAttributes
112+
{
113+
return new FileAttributes('');
114+
}
115+
116+
/**
117+
* @param string $path
118+
*
119+
* @return \League\Flysystem\FileAttributes
120+
*/
121+
public function mimeType(string $path): FileAttributes
122+
{
123+
return new FileAttributes('');
124+
}
125+
126+
/**
127+
* @param string $path
128+
*
129+
* @return \League\Flysystem\FileAttributes
130+
*/
131+
public function lastModified(string $path): FileAttributes
132+
{
133+
return new FileAttributes('');
134+
}
135+
136+
/**
137+
* @param string $path
138+
*
139+
* @return \League\Flysystem\FileAttributes
140+
*/
141+
public function fileSize(string $path): FileAttributes
142+
{
143+
return new FileAttributes('');
144+
}
145+
146+
/**
147+
* @param string $path
148+
* @param bool $deep
149+
*
150+
* @return iterable
151+
*/
152+
public function listContents(string $path, bool $deep): iterable
153+
{
154+
return [];
155+
}
156+
157+
/**
158+
* @param string $source
159+
* @param string $destination
160+
* @param \League\Flysystem\Config $config
161+
*
162+
* @return void
163+
*/
164+
public function move(string $source, string $destination, Config $config): void
165+
{
166+
}
167+
168+
/**
169+
* @param string $source
170+
* @param string $destination
171+
* @param \League\Flysystem\Config $config
172+
*
173+
* @return void
174+
*/
175+
public function copy(string $source, string $destination, Config $config): void
176+
{
177+
}
178+
179+
/**
180+
* @param string $path
181+
*
182+
* @return bool
183+
*/
184+
public function directoryExists(string $path): bool
185+
{
186+
return true;
187+
}
188+
}

src/Exception/AdapterFactoryNotFoundException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/**
44
* Copyright (c) Florian Krämer (https://florian-kraemer.net)
@@ -12,8 +12,6 @@
1212
* @license https://opensource.org/licenses/MIT MIT License
1313
*/
1414

15-
declare(strict_types=1);
16-
1715
namespace PhpCollective\Infrastructure\Storage\Exception;
1816

1917
/**

src/Exception/PackageRequiredException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
* @license https://opensource.org/licenses/MIT MIT License
1313
*/
1414

15-
declare(strict_types=1);
16-
1715
namespace PhpCollective\Infrastructure\Storage\Exception;
1816

1917
/**

src/Exception/StorageException.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
* @license https://opensource.org/licenses/MIT MIT License
1313
*/
1414

15-
declare(strict_types=1);
16-
1715
namespace PhpCollective\Infrastructure\Storage\Exception;
1816

1917
use RuntimeException;

src/Factories/AbstractFactory.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
* @license https://opensource.org/licenses/MIT MIT License
1313
*/
1414

15-
declare(strict_types=1);
16-
1715
namespace PhpCollective\Infrastructure\Storage\Factories;
1816

19-
use League\Flysystem\Adapter\Local;
20-
use League\Flysystem\AdapterInterface;
17+
use League\Flysystem\FilesystemAdapter;
18+
use League\Flysystem\Local\LocalFilesystemAdapter;
2119
use PhpCollective\Infrastructure\Storage\Exception\PackageRequiredException;
2220

2321
/**
@@ -38,7 +36,7 @@ abstract class AbstractFactory implements FactoryInterface
3836
/**
3937
* @var string
4038
*/
41-
protected string $className = Local::class;
39+
protected string $className = LocalFilesystemAdapter::class;
4240

4341
/**
4442
* @return string
@@ -74,5 +72,5 @@ public function availabilityCheck(): void
7472
/**
7573
* @inheritDoc
7674
*/
77-
abstract public function build(array $config): AdapterInterface;
75+
abstract public function build(array $config): FilesystemAdapter;
7876
}

src/Factories/AwsS3v3Factory.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
* @license https://opensource.org/licenses/MIT MIT License
1313
*/
1414

15-
declare(strict_types=1);
16-
1715
namespace PhpCollective\Infrastructure\Storage\Factories;
1816

1917
use Aws\S3\S3Client;
20-
use League\Flysystem\AdapterInterface;
21-
use League\Flysystem\AwsS3v3\AwsS3Adapter;
18+
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
2219

2320
/**
2421
* AwsS3Factory
@@ -29,7 +26,7 @@ class AwsS3v3Factory extends AbstractFactory
2926

3027
protected string $package = 'league/flysystem-aws-s3-v3';
3128

32-
protected string $className = AwsS3Adapter::class;
29+
protected string $className = AwsS3V3Adapter::class;
3330

3431
protected array $defaults = [
3532
'bucket' => null,
@@ -43,18 +40,17 @@ class AwsS3v3Factory extends AbstractFactory
4340
/**
4441
* @inheritDoc
4542
*/
46-
public function build(array $config): AdapterInterface
43+
public function build(array $config): AwsS3V3Adapter
4744
{
4845
$this->availabilityCheck();
4946
$config += $this->defaults;
5047

51-
return new AwsS3Adapter(
48+
return new AwsS3V3Adapter(
5249
S3Client::factory(
5350
$config['client'],
5451
),
5552
$config['bucket'],
5653
$config['prefix'],
57-
$config,
5854
);
5955
}
6056
}

src/Factories/AzureFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
* @license https://opensource.org/licenses/MIT MIT License
1313
*/
1414

15-
declare(strict_types=1);
16-
1715
namespace PhpCollective\Infrastructure\Storage\Factories;
1816

19-
use League\Flysystem\AdapterInterface;
2017
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
18+
use League\Flysystem\FilesystemAdapter;
2119
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
2220
use PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryConfigException;
2321

@@ -42,7 +40,7 @@ class AzureFactory extends AbstractFactory
4240
/**
4341
* @inheritDoc
4442
*/
45-
public function build($config): AdapterInterface
43+
public function build($config): FilesystemAdapter
4644
{
4745
$this->availabilityCheck();
4846
$this->checkConfig($config);
@@ -59,6 +57,8 @@ public function build($config): AdapterInterface
5957
}
6058

6159
/**
60+
* @param array<string, mixed> $config
61+
*
6262
* @throws \PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryConfigException
6363
*
6464
* @return void

0 commit comments

Comments
 (0)