Skip to content

Commit 5f49be5

Browse files
committed
Implement several adapter builders
1 parent 0aa4241 commit 5f49be5

28 files changed

Lines changed: 1264 additions & 45 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# flysystem-bundle
22

3+
> This bundle is currently in active development and not released yet.
4+
35
[![Build Status](https://travis-ci.org/tgalopin/flysystem-bundle.svg?branch=master)](https://travis-ci.org/tgalopin/flysystem-bundle)
46

57
[![SymfonyInsight](https://insight.symfony.com/projects/525fdfa3-d482-4218-b4b9-3c2efc305fac/big.svg)](https://insight.symfony.com/projects/525fdfa3-d482-4218-b4b9-3c2efc305fac)

composer.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,31 @@
2121
},
2222
"require": {
2323
"php": ">=7.1",
24+
"league/flysystem": "^1.0.26",
2425
"symfony/framework-bundle": "^4.2",
25-
"league/flysystem": "^1.0"
26+
"symfony/options-resolver": "^4.2"
2627
},
2728
"require-dev": {
2829
"phpunit/phpunit": "^7.4",
2930
"league/flysystem-memory": "^1.0",
3031
"league/flysystem-cached-adapter": "^1.0",
31-
"symfony/var-dumper": "^4.1"
32+
"symfony/var-dumper": "^4.1",
33+
"spatie/flysystem-dropbox": "^1.0",
34+
"superbalist/flysystem-google-storage": "^7.2",
35+
"jackalope/jackalope-doctrine-dbal": "^1.3",
36+
"league/flysystem-azure-blob-storage": "^0.1.5",
37+
"league/flysystem-aws-s3-v3": "^1.0",
38+
"league/flysystem-rackspace": "^1.0",
39+
"league/flysystem-replicate-adapter": "^1.0",
40+
"league/flysystem-sftp": "^1.0",
41+
"league/flysystem-webdav": "^1.0",
42+
"league/flysystem-phpcr": "^1.1",
43+
"league/flysystem-ziparchive": "^1.0"
44+
},
45+
"config": {
46+
"preferred-install": {
47+
"*": "dist"
48+
},
49+
"sort-packages": true
3250
}
3351
}

docs/1-getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ flysystem-bundle requires PHP 7.1+ and Symfony 4.2+.
1111
You can install the bundle using Symfony Flex:
1212

1313
```
14-
composer require tgalopin/flysystem-bundle
14+
composer require thephpleague/flysystem-bundle
1515
```
1616

1717
## Basic usage
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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;
13+
14+
use League\FlysystemBundle\Adapter\Builder\AdapterDefinitionBuilderInterface;
15+
use League\FlysystemBundle\Adapter\Builder\LocalAdapterDefinitionBuilder;
16+
use Symfony\Component\DependencyInjection\Definition;
17+
18+
/**
19+
* @author Titouan Galopin <galopintitouan@gmail.com>
20+
*
21+
* @internal
22+
*/
23+
class AdapterDefinitionFactory
24+
{
25+
/**
26+
* @var AdapterDefinitionBuilderInterface[]
27+
*/
28+
private $builders;
29+
30+
public function __construct()
31+
{
32+
$this->builders = [
33+
new LocalAdapterDefinitionBuilder($this),
34+
];
35+
}
36+
37+
public function createDefinition(string $name, array $options): ?Definition
38+
{
39+
foreach ($this->builders as $builder) {
40+
if ($builder->getName() === $name) {
41+
return $builder->createDefinition($options);
42+
}
43+
}
44+
45+
return null;
46+
}
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 League\FlysystemBundle\Adapter\AdapterDefinitionFactory;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\OptionsResolver\OptionsResolver;
17+
18+
/**
19+
* @author Titouan Galopin <galopintitouan@gmail.com>
20+
*
21+
* @internal
22+
*/
23+
abstract class AbstractAdapterDefinitionBuilder implements AdapterDefinitionBuilderInterface
24+
{
25+
protected $definitionFactory;
26+
27+
public function __construct(AdapterDefinitionFactory $definitionFactory)
28+
{
29+
$this->definitionFactory = $definitionFactory;
30+
}
31+
32+
final public function createDefinition(array $options): Definition
33+
{
34+
$resolver = new OptionsResolver();
35+
$this->configureOptions($resolver);
36+
37+
$definition = new Definition();
38+
$definition->setPublic(false);
39+
$this->configureDefinition($definition, $resolver->resolve($options));
40+
41+
return $definition;
42+
}
43+
44+
abstract protected function configureOptions(OptionsResolver $resolver);
45+
46+
abstract protected function configureDefinition(Definition $definition, array $options);
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 Symfony\Component\DependencyInjection\Definition;
15+
16+
/**
17+
* @author Titouan Galopin <galopintitouan@gmail.com>
18+
*/
19+
interface AdapterDefinitionBuilderInterface
20+
{
21+
public function getName(): string;
22+
23+
/**
24+
* Create the definition for this builder's adapter given an array of options.
25+
*
26+
* @param array $options
27+
*
28+
* @return Definition
29+
*/
30+
public function createDefinition(array $options): Definition;
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 League\Flysystem\AwsS3v3\AwsS3Adapter;
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+
class AwsAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
23+
{
24+
public function getName(): string
25+
{
26+
return 'aws';
27+
}
28+
29+
protected function configureOptions(OptionsResolver $resolver)
30+
{
31+
$resolver->setRequired('client');
32+
$resolver->setAllowedTypes('client', 'string');
33+
34+
$resolver->setRequired('bucket');
35+
$resolver->setAllowedTypes('bucket', 'string');
36+
37+
$resolver->setDefault('prefix', '');
38+
$resolver->setAllowedTypes('prefix', 'string');
39+
}
40+
41+
protected function configureDefinition(Definition $definition, array $options)
42+
{
43+
$definition->setClass(AwsS3Adapter::class);
44+
$definition->setArgument(0, new Reference($options['client']));
45+
$definition->setArgument(1, $options['bucket']);
46+
$definition->setArgument(2, $options['prefix']);
47+
}
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter;
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+
class AzureAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
23+
{
24+
public function getName(): string
25+
{
26+
return 'azure';
27+
}
28+
29+
protected function configureOptions(OptionsResolver $resolver)
30+
{
31+
$resolver->setRequired('client');
32+
$resolver->setAllowedTypes('client', 'string');
33+
34+
$resolver->setRequired('container');
35+
$resolver->setAllowedTypes('container', 'string');
36+
37+
$resolver->setDefault('prefix', '');
38+
$resolver->setAllowedTypes('prefix', 'string');
39+
}
40+
41+
protected function configureDefinition(Definition $definition, array $options)
42+
{
43+
$definition->setClass(AzureBlobStorageAdapter::class);
44+
$definition->setArgument(0, new Reference($options['client']));
45+
$definition->setArgument(1, $options['container']);
46+
$definition->setArgument(2, $options['prefix']);
47+
}
48+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 Spatie\FlysystemDropbox\DropboxAdapter;
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+
class DropboxAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
23+
{
24+
public function getName(): string
25+
{
26+
return 'dropbox';
27+
}
28+
29+
protected function configureOptions(OptionsResolver $resolver)
30+
{
31+
$resolver->setRequired('client');
32+
$resolver->setAllowedTypes('client', 'string');
33+
34+
$resolver->setDefault('prefix', '');
35+
$resolver->setAllowedTypes('prefix', 'string');
36+
}
37+
38+
protected function configureDefinition(Definition $definition, array $options)
39+
{
40+
$definition->setClass(DropboxAdapter::class);
41+
$definition->setArgument(0, new Reference($options['client']));
42+
$definition->setArgument(1, $options['prefix']);
43+
}
44+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 Superbalist\Flysystem\GoogleStorage\GoogleStorageAdapter;
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+
class GcloudAdapterDefinitionBuilder extends AbstractAdapterDefinitionBuilder
23+
{
24+
public function getName(): string
25+
{
26+
return 'gcloud';
27+
}
28+
29+
protected function configureOptions(OptionsResolver $resolver)
30+
{
31+
$resolver->setRequired('client');
32+
$resolver->setAllowedTypes('client', 'string');
33+
34+
$resolver->setRequired('bucket');
35+
$resolver->setAllowedTypes('bucket', 'string');
36+
37+
$resolver->setDefault('prefix', '');
38+
$resolver->setAllowedTypes('prefix', 'string');
39+
40+
$resolver->setDefault('api_url', null);
41+
$resolver->setAllowedTypes('api_url', ['string', 'null']);
42+
}
43+
44+
protected function configureDefinition(Definition $definition, array $options)
45+
{
46+
$bucketDefinition = new Definition();
47+
$bucketDefinition->setFactory([new Reference($options['client']), 'bucket']);
48+
$bucketDefinition->setArgument(0, $options['bucket']);
49+
50+
$definition->setClass(GoogleStorageAdapter::class);
51+
$definition->setArgument(0, new Reference($options['client']));
52+
$definition->setArgument(1, $bucketDefinition);
53+
$definition->setArgument(2, $options['prefix']);
54+
$definition->setArgument(3, $options['api_url']);
55+
}
56+
}

0 commit comments

Comments
 (0)