Skip to content

Commit 8880840

Browse files
committed
Add cache adapter based on lustmored/flysystem-v2-simple-cache-adapter
1 parent beb8e13 commit 8880840

10 files changed

Lines changed: 125 additions & 12 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"async-aws/flysystem-s3": "^1.0",
3232
"league/flysystem-aws-s3-v3": "^2.0",
3333
"league/flysystem-memory": "^2.0",
34+
"lustmored/flysystem-v2-simple-cache-adapter": "^0.1.0",
3435
"phpunit/phpunit": "^7.4",
3536
"symfony/dotenv": "^4.2|^5.0",
3637
"symfony/framework-bundle": "^4.2|^5.0",

src/Adapter/AdapterDefinitionFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function __construct()
3131
$this->builders = [
3232
new Builder\AsyncAwsAdapterDefinitionBuilder(),
3333
new Builder\AwsAdapterDefinitionBuilder(),
34+
new Builder\CacheAdapterDefinitionBuilder(),
3435
new Builder\FtpAdapterDefinitionBuilder(),
3536
new Builder\LocalAdapterDefinitionBuilder(),
3637
new Builder\MemoryAdapterDefinitionBuilder(),
Lines changed: 53 additions & 0 deletions
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 <galopintitouan@gmail.com>
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 Lustmored\Flysystem\Cache\CacheAdapter;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
19+
/**
20+
* @author Titouan Galopin <galopintitouan@gmail.com>
21+
*
22+
* @internal
23+
*/
24+
class CacheAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
25+
{
26+
public function getName(): string
27+
{
28+
return 'cache';
29+
}
30+
31+
protected function getRequiredPackages(): array
32+
{
33+
return [
34+
CacheAdapter::class => 'lustmored/flysystem-v2-simple-cache-adapter',
35+
];
36+
}
37+
38+
protected function configureOptions(OptionsResolver $resolver)
39+
{
40+
$resolver->setRequired('store');
41+
$resolver->setAllowedTypes('store', 'string');
42+
43+
$resolver->setRequired('source');
44+
$resolver->setAllowedTypes('source', 'string');
45+
}
46+
47+
protected function configureDefinition(Definition $definition, array $options)
48+
{
49+
$definition->setClass(CacheAdapter::class);
50+
$definition->setArgument(0, new Reference('flysystem.adapter.'.$options['source']));
51+
$definition->setArgument(1, new Reference($options['store']));
52+
}
53+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/*
3+
* This file is part of the flysystem-bundle project.
4+
*
5+
* (c) Titouan Galopin <galopintitouan@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Tests\League\FlysystemBundle\Adapter\Builder;
12+
13+
use League\FlysystemBundle\Adapter\Builder\CacheAdapterDefinitionBuilder;
14+
use Lustmored\Flysystem\Cache\CacheAdapter;
15+
use PHPUnit\Framework\TestCase;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
class CacheAdapterDefinitionBuilderTest extends TestCase
19+
{
20+
public function createBuilder()
21+
{
22+
return new CacheAdapterDefinitionBuilder();
23+
}
24+
25+
public function provideValidOptions()
26+
{
27+
yield 'minimal' => [[
28+
'store' => 'my_store',
29+
'source' => 'my_source',
30+
]];
31+
}
32+
33+
/**
34+
* @dataProvider provideValidOptions
35+
*/
36+
public function testCreateDefinition($options)
37+
{
38+
$this->assertSame(CacheAdapter::class, $this->createBuilder()->createDefinition($options)->getClass());
39+
}
40+
41+
public function testOptionsBehavior()
42+
{
43+
$definition = $this->createBuilder()->createDefinition([
44+
'store' => 'my_store',
45+
'source' => 'my_source',
46+
]);
47+
48+
$this->assertSame(CacheAdapter::class, $definition->getClass());
49+
$this->assertInstanceOf(Reference::class, $definition->getArgument(0));
50+
$this->assertSame('flysystem.adapter.my_source', (string) $definition->getArgument(0));
51+
$this->assertInstanceOf(Reference::class, $definition->getArgument(1));
52+
$this->assertSame('my_store', (string) $definition->getArgument(1));
53+
}
54+
}

tests/Adapter/options.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ fs_aws:
1919
# container: 'container_name'
2020
# prefix: 'optional/path/prefix'
2121

22-
#fs_cache:
23-
# adapter: 'cache'
24-
# options:
25-
# store: 'memory'
26-
# source: 'fs_local'
22+
fs_cache:
23+
adapter: 'cache'
24+
options:
25+
store: 'memory'
26+
source: 'fs_local'
2727

2828
#fs_dropbox:
2929
# adapter: 'dropbox'

tests/DependencyInjection/FlysystemExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function provideFilesystems()
2626
$fsNames = [
2727
'fs_aws',
2828
// 'fs_azure',
29-
// 'fs_cache',
29+
'fs_cache',
3030
// 'fs_custom',
3131
// 'fs_dropbox',
3232
'fs_ftp',

tests/Kernel/FlysystemAppKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3939
}
4040
});
4141

42+
$loader->load(__DIR__.'/config/cache.yaml', 'yaml');
4243
$loader->load(__DIR__.'/config/framework.yaml', 'yaml');
4344
$loader->load(__DIR__.'/config/flysystem.yaml', 'yaml');
4445
$loader->load(__DIR__.'/config/services.yaml', 'yaml');

tests/Kernel/config/cache.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework:
2+
cache:
3+
app: cache.adapter.array

tests/Kernel/config/flysystem.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ flysystem:
1414
# container: 'container_name'
1515
# prefix: 'optional/path/prefix'
1616

17-
# fs_cache:
18-
# adapter: 'cache'
19-
# options:
20-
# store: 'cache.app'
21-
# source: 'fs_local'
17+
fs_cache:
18+
adapter: 'cache'
19+
options:
20+
store: 'cache.app'
21+
source: 'fs_local'
2222

2323
# fs_custom:
2424
# adapter: 'custom_adapter'

tests/Kernel/config/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ services:
88
# Aliases used to test the services construction
99
flysystem.test.fs_aws: { alias: 'fs_aws' }
1010
# flysystem.test.fs_azure: { alias: 'fs_azure' }
11-
# flysystem.test.fs_cache: { alias: 'fs_cache' }
11+
flysystem.test.fs_cache: { alias: 'fs_cache' }
1212
# flysystem.test.fs_custom: { alias: 'fs_custom' }
1313
# flysystem.test.fs_dropbox: { alias: 'fs_dropbox' }
1414
flysystem.test.fs_ftp: { alias: 'fs_ftp' }

0 commit comments

Comments
 (0)