Skip to content

Commit 4baead1

Browse files
authored
feat(storage): add storage component (#1149)
1 parent 9aeb727 commit 4baead1

36 files changed

+1866
-8
lines changed

.github/workflows/integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: shivammathur/setup-php@v2
2929
with:
3030
php-version: ${{ matrix.php }}
31-
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql
31+
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, ftp, zip
3232
coverage: pcov
3333

3434
- name: Setup Bun
@@ -71,7 +71,7 @@ jobs:
7171
uses: shivammathur/setup-php@v2
7272
with:
7373
php-version: ${{ matrix.php }}
74-
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql
74+
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, pdo, sqlite, pdo_sqlite, pdo_mysql, ftp, zip
7575
coverage: pcov
7676

7777
- name: Setup problem matchers

composer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"giggsey/libphonenumber-for-php-lite": "^9.0",
1717
"guzzlehttp/guzzle": "^7.8",
1818
"laminas/laminas-diactoros": "^3.3",
19+
"league/flysystem": "^3.29.1",
1920
"monolog/monolog": "^3.7.0",
2021
"nette/php-generator": "^4.1.6",
2122
"nikic/php-parser": "^5.3",
@@ -42,6 +43,14 @@
4243
"carthage-software/mago": "0.22.2",
4344
"guzzlehttp/psr7": "^2.6.1",
4445
"illuminate/view": "~11.7.0",
46+
"league/flysystem-aws-s3-v3": "^3.0",
47+
"league/flysystem-azure-blob-storage": "^3.0",
48+
"league/flysystem-ftp": "^3.0",
49+
"league/flysystem-google-cloud-storage": "^3.0",
50+
"league/flysystem-memory": "^3.0",
51+
"league/flysystem-read-only": "^3.0",
52+
"league/flysystem-sftp-v3": "^3.0",
53+
"league/flysystem-ziparchive": "^3.0",
4554
"masterminds/html5": "^2.9",
4655
"mikey179/vfsstream": "^2.0@dev",
4756
"nesbot/carbon": "^3.8",
@@ -77,6 +86,7 @@
7786
"tempest/mapper": "self.version",
7887
"tempest/reflection": "self.version",
7988
"tempest/router": "self.version",
89+
"tempest/storage": "self.version",
8090
"tempest/support": "self.version",
8191
"tempest/validation": "self.version",
8292
"tempest/view": "self.version",
@@ -110,6 +120,7 @@
110120
"Tempest\\Mapper\\": "src/Tempest/Mapper/src",
111121
"Tempest\\Reflection\\": "src/Tempest/Reflection/src",
112122
"Tempest\\Router\\": "src/Tempest/Router/src",
123+
"Tempest\\Storage\\": "src/Tempest/Storage/src",
113124
"Tempest\\Support\\": "src/Tempest/Support/src",
114125
"Tempest\\Validation\\": "src/Tempest/Validation/src",
115126
"Tempest\\View\\": "src/Tempest/View/src",
@@ -161,6 +172,7 @@
161172
"Tempest\\Mapper\\Tests\\": "src/Tempest/Mapper/tests",
162173
"Tempest\\Reflection\\Tests\\": "src/Tempest/Reflection/tests",
163174
"Tempest\\Router\\Tests\\": "src/Tempest/Router/tests",
175+
"Tempest\\Storage\\Tests\\": "src/Tempest/Storage/tests",
164176
"Tempest\\Support\\Tests\\": "src/Tempest/Support/tests",
165177
"Tempest\\Validation\\Tests\\": "src/Tempest/Validation/tests",
166178
"Tempest\\View\\Tests\\": "src/Tempest/View/tests",

mago.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ paths = ["src", "tests"]
55
includes = ["vendor"]
66
excludes = [
77
"./vendor/symfony/cache/Traits/ValueWrapper.php",
8+
"./vendor/google/common-protos/metadata",
9+
"./vendor/google/gax/metadata",
10+
"./vendor/google/longrunning/metadata",
811
"./vendor/composer",
912
"**/.cache",
1013
"**/*.stub.php",

src/Tempest/Framework/Testing/IntegrationTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
use Tempest\Http\Method;
2020
use Tempest\Router\GenericRequest;
2121
use Tempest\Router\Request;
22+
use Tempest\Storage\Testing\StorageTester;
2223

2324
use function Tempest\Support\Path\normalize;
2425

26+
/** @mago-expect maintainability/too-many-properties */
2527
abstract class IntegrationTest extends TestCase
2628
{
2729
protected string $root;
@@ -45,6 +47,8 @@ abstract class IntegrationTest extends TestCase
4547

4648
protected EventBusTester $eventBus;
4749

50+
protected StorageTester $storage;
51+
4852
protected function setUp(): void
4953
{
5054
parent::setUp();
@@ -62,11 +66,12 @@ protected function setUp(): void
6266
$this->console = $this->container->get(ConsoleTester::class);
6367
$this->http = $this->container->get(HttpRouterTester::class);
6468
$this->installer = $this->container->get(InstallerTester::class);
69+
$this->eventBus = $this->container->get(EventBusTester::class);
70+
$this->storage = $this->container->get(StorageTester::class);
6571

6672
$this->vite = $this->container->get(ViteTester::class);
6773
$this->vite->preventTagResolution();
68-
69-
$this->eventBus = $this->container->get(EventBusTester::class);
74+
$this->vite->clearCaches();
7075

7176
$request = new GenericRequest(Method::GET, '/', []);
7277
$this->container->singleton(Request::class, fn () => $request);

src/Tempest/Storage/.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Exclude build/test files from the release
2+
.github/ export-ignore
3+
tests/ export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
phpunit.xml export-ignore
7+
README.md export-ignore
8+
9+
# Configure diff output for .php and .phar files.
10+
*.php diff=php

src/Tempest/Storage/LICENCE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Brent Roose [email protected]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

src/Tempest/Storage/composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "tempest/storage",
3+
"description": "A component for working with storage.",
4+
"license": "MIT",
5+
"minimum-stability": "dev",
6+
"require": {
7+
"php": "^8.4",
8+
"league/flysystem": "^3.29.1"
9+
},
10+
"require-dev": {
11+
"league/flysystem-aws-s3-v3": "^3.0",
12+
"league/flysystem-read-only": "^3.0",
13+
"league/flysystem-ftp": "^3.0",
14+
"league/flysystem-memory": "^3.0",
15+
"league/flysystem-ziparchive": "^3.0",
16+
"league/flysystem-sftp-v3": "^3.0",
17+
"league/flysystem-azure-blob-storage": "^3.0",
18+
"league/flysystem-google-cloud-storage": "^3.0"
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"Tempest\\Storage\\": "src"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"Tempest\\Storage\\Tests\\": "tests"
28+
}
29+
}
30+
}

src/Tempest/Storage/phpunit.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" displayDetailsOnPhpunitDeprecations="true" failOnPhpunitDeprecation="false" failOnRisky="true" failOnWarning="true">
3+
<testsuites>
4+
<testsuite name="Tempest Vite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
9+
<include>
10+
<directory>src</directory>
11+
</include>
12+
</source>
13+
</phpunit>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Tempest\Storage\Config;
4+
5+
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
6+
use League\Flysystem\FilesystemAdapter;
7+
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
8+
9+
final class AzureStorageConfig implements StorageConfig
10+
{
11+
public string $adapter = AzureBlobStorageAdapter::class;
12+
13+
public function __construct(
14+
/**
15+
* Connection string to the Azure Blob Storage account.
16+
*/
17+
public string $dsn,
18+
19+
/**
20+
* Name of the container to use.
21+
*/
22+
public string $container,
23+
24+
/**
25+
* Prefix to be used for all paths.
26+
*/
27+
public string $prefix = '',
28+
29+
/**
30+
* Whether the storage is read-only.
31+
*/
32+
public bool $readonly = false,
33+
) {}
34+
35+
public function createAdapter(): FilesystemAdapter
36+
{
37+
return new AzureBlobStorageAdapter(
38+
client: BlobRestProxy::createBlobService($this->dsn),
39+
container: $this->container,
40+
prefix: $this->prefix,
41+
);
42+
}
43+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Tempest\Storage\Config;
4+
5+
use League\Flysystem\FilesystemAdapter;
6+
7+
use function Tempest\get;
8+
9+
final class CustomStorageConfig implements StorageConfig
10+
{
11+
public function __construct(
12+
/**
13+
* FQCN of the custom Flysystem adapter, resolved through the container.
14+
*
15+
* @var class-string<FilesystemAdapter>
16+
*/
17+
public string $adapter,
18+
19+
/**
20+
* Whether the storage is read-only.
21+
*/
22+
public bool $readonly = false,
23+
) {}
24+
25+
public function createAdapter(): FilesystemAdapter
26+
{
27+
return get($this->adapter);
28+
}
29+
}

0 commit comments

Comments
 (0)