Skip to content

Commit 26a36f3

Browse files
committed
Upgrade to league/flysystem v3
# Conflicts: # src/Factories/AzureFactory.php # src/Factories/FtpFactory.php # src/Factories/LocalFactory.php # src/Factories/RackspaceFactory.php # src/Factories/ReplicateFactory.php # src/Factories/SftpFactory.php # tests/TestCase/Storage/Factories/AbstractFactoryTest.php
1 parent 510af51 commit 26a36f3

21 files changed

+245
-298
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/Factories/AbstractFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
namespace PhpCollective\Infrastructure\Storage\Factories;
1616

17-
use League\Flysystem\Adapter\Local;
18-
use League\Flysystem\AdapterInterface;
17+
use League\Flysystem\FilesystemAdapter;
18+
use League\Flysystem\Local\LocalFilesystemAdapter;
1919
use PhpCollective\Infrastructure\Storage\Exception\PackageRequiredException;
2020

2121
/**
@@ -36,7 +36,7 @@ abstract class AbstractFactory implements FactoryInterface
3636
/**
3737
* @var string
3838
*/
39-
protected string $className = Local::class;
39+
protected string $className = LocalFilesystemAdapter::class;
4040

4141
/**
4242
* @return string
@@ -72,5 +72,5 @@ public function availabilityCheck(): void
7272
/**
7373
* @inheritDoc
7474
*/
75-
abstract public function build(array $config): AdapterInterface;
75+
abstract public function build(array $config): FilesystemAdapter;
7676
}

src/Factories/AwsS3v3Factory.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
namespace PhpCollective\Infrastructure\Storage\Factories;
1616

1717
use Aws\S3\S3Client;
18-
use League\Flysystem\AdapterInterface;
19-
use League\Flysystem\AwsS3v3\AwsS3Adapter;
18+
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
2019

2120
/**
2221
* AwsS3Factory
@@ -27,7 +26,7 @@ class AwsS3v3Factory extends AbstractFactory
2726

2827
protected string $package = 'league/flysystem-aws-s3-v3';
2928

30-
protected string $className = AwsS3Adapter::class;
29+
protected string $className = AwsS3V3Adapter::class;
3130

3231
protected array $defaults = [
3332
'bucket' => null,
@@ -41,18 +40,17 @@ class AwsS3v3Factory extends AbstractFactory
4140
/**
4241
* @inheritDoc
4342
*/
44-
public function build(array $config): AdapterInterface
43+
public function build(array $config): AwsS3V3Adapter
4544
{
4645
$this->availabilityCheck();
4746
$config += $this->defaults;
4847

49-
return new AwsS3Adapter(
48+
return new AwsS3V3Adapter(
5049
S3Client::factory(
5150
$config['client'],
5251
),
5352
$config['bucket'],
5453
$config['prefix'],
55-
$config,
5654
);
5755
}
5856
}

src/Factories/AzureFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
namespace PhpCollective\Infrastructure\Storage\Factories;
1616

17-
use League\Flysystem\AdapterInterface;
1817
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
18+
use League\Flysystem\FilesystemAdapter;
1919
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
2020
use PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryConfigException;
2121

@@ -40,7 +40,7 @@ class AzureFactory extends AbstractFactory
4040
/**
4141
* @inheritDoc
4242
*/
43-
public function build($config): AdapterInterface
43+
public function build($config): FilesystemAdapter
4444
{
4545
$this->availabilityCheck();
4646
$this->checkConfig($config);
@@ -57,7 +57,7 @@ public function build($config): AdapterInterface
5757
}
5858

5959
/**
60-
* @param array $config
60+
* @param array<string, mixed> $config
6161
*
6262
* @throws \PhpCollective\Infrastructure\Storage\Factories\Exception\FactoryConfigException
6363
*

src/Factories/DropboxFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace PhpCollective\Infrastructure\Storage\Factories;
1616

17-
use League\Flysystem\AdapterInterface;
17+
use League\Flysystem\FilesystemAdapter;
1818
use Spatie\Dropbox\Client;
1919
use Spatie\FlysystemDropbox\DropboxAdapter;
2020

@@ -36,7 +36,7 @@ class DropboxFactory extends AbstractFactory
3636
/**
3737
* @inheritDoc
3838
*/
39-
public function build(array $config): AdapterInterface
39+
public function build(array $config): FilesystemAdapter
4040
{
4141
$config += $this->defaults;
4242
$client = new Client($config['authToken']);

src/Factories/FactoryInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace PhpCollective\Infrastructure\Storage\Factories;
1616

17-
use League\Flysystem\AdapterInterface;
17+
use League\Flysystem\FilesystemAdapter;
1818

1919
/**
2020
* Factory Interface
@@ -34,9 +34,9 @@ public function alias(): string;
3434
/**
3535
* @param array<string, mixed> $config
3636
*
37-
* @return \League\Flysystem\AdapterInterface
37+
* @return \League\Flysystem\FilesystemAdapter
3838
*/
39-
public function build(array $config): AdapterInterface;
39+
public function build(array $config): FilesystemAdapter;
4040

4141
/**
4242
* @return void

0 commit comments

Comments
 (0)