Skip to content

Commit 4587fe0

Browse files
FluffyDiscordmaxhelias
authored andcommitted
feat: add BunnyCDN Storage adapter
1 parent bd6432e commit 4587fe0

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ to interact with your storage.
112112
5. [Creating a custom adapter](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/5-creating-a-custom-adapter.md)
113113
6. [MongoDB GridFS](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/6-gridfs.md)
114114
7. [WebDAV](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/7-webdav.md)
115+
8. [BunnyCDN](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/8-bunnycdn.md)
115116

116117
* [Security issue disclosure procedure](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/A-security-disclosure-procedure.md)
117118
* [Configuration reference](https://github.com/thephpleague/flysystem-bundle/blob/master/docs/B-configuration-reference.md)

Diff for: composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"league/flysystem-read-only": "^3.15",
4747
"league/flysystem-sftp-v3": "^3.1",
4848
"league/flysystem-webdav": "^3.29",
49+
"platformcommunity/flysystem-bunnycdn": "^3.3",
4950
"symfony/dotenv": "^5.4 || ^6.0 || ^7.0",
5051
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
5152
"symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0",

Diff for: docs/8-bunnycdn.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# BunnyCDN Storage
2+
3+
Flysystem is able to [interact with BunnyCDN Storage servers](https://bunny.net/storage/).
4+
To configure this bundle for such usage, you can rely on adapters in the same way you would
5+
for other storages.
6+
7+
### Installation
8+
9+
```
10+
composer require platformcommunity/flysystem-bunnycdn
11+
```
12+
13+
### Usage
14+
15+
```yaml
16+
# config/packages/flysystem.yaml
17+
18+
services:
19+
bunny_client:
20+
class: PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient
21+
arguments:
22+
$storage_zone_name: 'storage-zone'
23+
$api_key: 'api-key'
24+
$region: '!php/const:PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion::FALKENSTEIN'
25+
26+
flysystem:
27+
storages:
28+
bunny.storage:
29+
adapter: 'bunnycdn'
30+
options:
31+
client: 'bunny_client'
32+
pull_zone: 'https://testing.b-cdn.net/' # optional
33+
```

Diff for: src/Adapter/AdapterDefinitionFactory.php

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function __construct()
3939
new Builder\MemoryAdapterDefinitionBuilder(),
4040
new Builder\SftpAdapterDefinitionBuilder(),
4141
new Builder\WebDAVAdapterDefinitionBuilder(),
42+
new Builder\BunnyCDNAdapterDefinitionBuilder(),
4243
];
4344
}
4445

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace League\FlysystemBundle\Adapter\Builder;
13+
14+
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @internal
21+
*/
22+
final class BunnyCDNAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
23+
{
24+
public function getName(): string
25+
{
26+
return 'bunnycdn';
27+
}
28+
29+
protected function getRequiredPackages(): array
30+
{
31+
return [
32+
BunnyCDNAdapter::class => 'platformcommunity/flysystem-bunnycdn',
33+
];
34+
}
35+
36+
protected function configureOptions(OptionsResolver $resolver): void
37+
{
38+
$resolver->setRequired('client');
39+
$resolver->setAllowedTypes('client', 'string');
40+
41+
$resolver->setDefault('pull_zone', '');
42+
$resolver->setAllowedTypes('pull_zone', 'string');
43+
}
44+
45+
protected function configureDefinition(Definition $definition, array $options, ?string $defaultVisibilityForDirectories): void
46+
{
47+
$definition->setClass(BunnyCDNAdapter::class);
48+
$definition->setArguments([
49+
new Reference($options['client']),
50+
$options['pull_zone'],
51+
]);
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the flysystem-bundle project.
5+
*
6+
* (c) Titouan Galopin <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\League\FlysystemBundle\Adapter\Builder;
13+
14+
use League\Flysystem\Visibility;
15+
use League\FlysystemBundle\Adapter\Builder\BunnyCDNAdapterDefinitionBuilder;
16+
use PHPUnit\Framework\TestCase;
17+
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNAdapter;
18+
19+
class BunnyCDNAdapterDefinitionBuilderTest extends TestCase
20+
{
21+
public function createBuilder(): BunnyCDNAdapterDefinitionBuilder
22+
{
23+
return new BunnyCDNAdapterDefinitionBuilder();
24+
}
25+
26+
public static function provideValidOptions(): \Generator
27+
{
28+
yield 'minimal' => [[
29+
'client' => 'bunny_client',
30+
]];
31+
32+
yield 'full' => [[
33+
'client' => 'bunny_client',
34+
'pull_zone' => 'z1',
35+
]];
36+
}
37+
38+
/**
39+
* @dataProvider provideValidOptions
40+
*/
41+
public function testCreateDefinition(array $options): void
42+
{
43+
$this->assertSame(BunnyCDNAdapter::class, $this->createBuilder()->createDefinition($options, null)->getClass());
44+
}
45+
46+
public function testOptionsBehavior(): void
47+
{
48+
$definition = $this->createBuilder()->createDefinition([
49+
'client' => 'bunny_client',
50+
'pull_zone' => 'z1',
51+
], Visibility::PUBLIC);
52+
53+
$this->assertSame(BunnyCDNAdapter::class, $definition->getClass());
54+
$this->assertSame('bunny_client', (string) $definition->getArgument(0));
55+
$this->assertSame('z1', $definition->getArgument(1));
56+
}
57+
}

0 commit comments

Comments
 (0)