Skip to content

Commit 6ed869e

Browse files
committed
Initial commit
0 parents  commit 6ed869e

14 files changed

Lines changed: 460 additions & 0 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vendor
2+
composer.lock
3+
tests/Fixtures/*/cache
4+
tests/Fixtures/*/logs
5+
.php_cs.cache

.php_cs.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
;
6+
7+
return PhpCsFixer\Config::create()
8+
->setRules(array(
9+
'@Symfony' => true,
10+
'phpdoc_annotation_without_dot' => false,
11+
))
12+
->setFinder($finder)
13+
;

.rmt.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
vcs:
2+
name: git
3+
sign-tag: true
4+
5+
version-generator:
6+
name: semantic
7+
allow-label: true
8+
9+
version-persister: vcs-tag
10+
11+
prerequisites:
12+
display-last-changes: ~
13+
14+
pre-release-actions:
15+
vcs-commit: ~
16+
17+
post-release-actions:
18+
vcs-publish:
19+
ask-confirmation: true

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: php
2+
dist: trusty
3+
sudo: false
4+
5+
matrix:
6+
include:
7+
- php: 7.1
8+
env: SYMFONY_VERSION="4.1.*" COMPOSER_FLAGS="--prefer-lowest"
9+
- php: 7.2
10+
env: SYMFONY_VERSION="4.1.*" CS_FIXER=1
11+
- php: 7.3
12+
env: SYMFONY_VERSION="4.2.*"
13+
fast_finish: true
14+
15+
cache:
16+
directories:
17+
- $HOME/.composer/cache
18+
19+
before_script:
20+
- composer self-update
21+
- composer require --no-update symfony/framework-bundle=$SYMFONY_VERSION
22+
- composer require --no-update --dev symfony/form=$SYMFONY_VERSION symfony/twig-bundle=$SYMFONY_VERSION
23+
- composer update $COMPOSER_FLAGS --prefer-dist
24+
25+
script:
26+
- stty cols 120
27+
- if [ "$CS_FIXER" == 1 ]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.13.1/php-cs-fixer.phar && php php-cs-fixer.phar fix --dry-run --diff; fi
28+
- php vendor/bin/phpunit

LICENSE

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# flysystem-bundle

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "thephpleague/flysystem-bundle",
3+
"description": "",
4+
"type": "symfony-bundle",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Titouan Galopin",
9+
"email": "galopintitouan@gmail.com"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"League\\FlysystemBundle\\": "src"
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"Tests\\League\\FlysystemBundle\\": "tests"
20+
}
21+
},
22+
"require": {
23+
"php": ">=7.1",
24+
"symfony/framework-bundle": "^4.2",
25+
"league/flysystem": "^1.0"
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "^7.4",
29+
"league/flysystem-memory": "^1.0",
30+
"league/flysystem-cached-adapter": "^1.0",
31+
"symfony/var-dumper": "^4.1"
32+
}
33+
}

phpunit.xml.dist

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
bootstrap="vendor/autoload.php">
9+
<php>
10+
<ini name="error_reporting" value="-1" />
11+
<env name="SHELL_VERBOSITY" value="-1" />
12+
</php>
13+
14+
<testsuites>
15+
<testsuite name="FlysystemBundle Test Suite">
16+
<directory>tests/</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<filter>
21+
<whitelist>
22+
<directory>./src/</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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\DependencyInjection;
13+
14+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
17+
/**
18+
* @author Titouan Galopin <galopintitouan@gmail.com>
19+
*
20+
* @internal
21+
*/
22+
class Configuration implements ConfigurationInterface
23+
{
24+
public function getConfigTreeBuilder()
25+
{
26+
$treeBuilder = new TreeBuilder('flysystem');
27+
$rootNode = $this->getRootNode($treeBuilder, 'flysystem');
28+
29+
$rootNode
30+
->children()
31+
->scalarNode('default_filesystem')->isRequired()->end()
32+
->scalarNode('default_local_directory')->defaultNull()->end()
33+
->arrayNode('filesystems')
34+
->arrayPrototype()
35+
->children()
36+
->scalarNode('adapter')->defaultNull()->end()
37+
->arrayNode('mounts')
38+
->scalarPrototype()
39+
->end()
40+
->end()
41+
->scalarNode('cache')->defaultNull()->end()
42+
->arrayNode('config')
43+
->variablePrototype()
44+
->end()
45+
->defaultValue([])
46+
->end()
47+
->end()
48+
->end()
49+
->defaultValue([])
50+
->end()
51+
->end()
52+
;
53+
54+
return $treeBuilder;
55+
}
56+
57+
private function getRootNode(TreeBuilder $treeBuilder, $name)
58+
{
59+
// BC layer for symfony/config 4.1 and older
60+
if (!\method_exists($treeBuilder, 'getRootNode')) {
61+
return $treeBuilder->root($name);
62+
}
63+
64+
return $treeBuilder->getRootNode();
65+
}
66+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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\DependencyInjection;
13+
14+
use League\Flysystem\Cached\CachedAdapter;
15+
use League\Flysystem\Filesystem;
16+
use League\Flysystem\FilesystemInterface;
17+
use Symfony\Component\Config\FileLocator;
18+
use Symfony\Component\DependencyInjection\Alias;
19+
use Symfony\Component\DependencyInjection\ContainerBuilder;
20+
use Symfony\Component\DependencyInjection\Definition;
21+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
22+
use Symfony\Component\DependencyInjection\Reference;
23+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
24+
25+
/**
26+
* @author Titouan Galopin <galopintitouan@gmail.com>
27+
*
28+
* @final
29+
*/
30+
class FlysystemExtension extends Extension
31+
{
32+
public function load(array $configs, ContainerBuilder $container)
33+
{
34+
$configuration = new Configuration();
35+
$config = $this->processConfiguration($configuration, $configs);
36+
37+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
38+
$loader->load('services.xml');
39+
40+
if (!isset($config['filesystems'][$config['default_filesystem']])) {
41+
throw new \LogicException('Default filesystem "'.$config['default_filesystem'].'" is not defined in the "flysystem.filesystems" configuration key.');
42+
}
43+
44+
$container->setParameter(
45+
'flysystem.default_local_directory',
46+
$config['default_local_directory'] ?: $container->getParameter('kernel.project_dir').'/storage'
47+
);
48+
49+
foreach ($config['filesystems'] as $fsName => $fsConfig) {
50+
if (!$fsConfig['adapter'] && !$fsConfig['mounts']) {
51+
throw new \LogicException('Definition of the filesystem "'.$fsName.'" is invalid: one of the "adapter" and "mounts" keys is required.');
52+
}
53+
54+
if ($fsConfig['adapter'] && $fsConfig['mounts']) {
55+
throw new \LogicException('Definition of the filesystem "'.$fsName.'" is invalid: configuring both "adapter" and "mounts" keys is not allowed.');
56+
}
57+
58+
// Create adapter definition
59+
if ($fsConfig['cache']) {
60+
$adapterDefinition = new Definition(CachedAdapter::class);
61+
$adapterDefinition->setPublic(false);
62+
$adapterDefinition->setArgument(0, new Reference($fsConfig['adapter']));
63+
$adapterDefinition->setArgument(1, new Reference($fsConfig['cache']));
64+
65+
$container->setDefinition('flysystem.filesystem.'.$fsName.'.adapter', $adapterDefinition);
66+
} else {
67+
$container->setAlias('flysystem.filesystem.'.$fsName.'.adapter', new Alias($fsConfig['adapter']));
68+
}
69+
70+
$definition = new Definition(Filesystem::class);
71+
$definition->setPublic(false);
72+
$definition->setArgument(0, new Reference('flysystem.filesystem.'.$fsName.'.adapter'));
73+
$definition->setArgument(1, $fsConfig['config']);
74+
75+
$container->setDefinition('flysystem.filesystem.'.$fsName, $definition);
76+
77+
$container
78+
->registerAliasForArgument('flysystem.filesystem.'.$fsName, FilesystemInterface::class, $fsName)
79+
->setPublic(false);
80+
81+
if ($config['default_filesystem'] === $fsName) {
82+
$container->setAlias(FilesystemInterface::class, 'flysystem.filesystem.'.$fsName)->setPublic(false);
83+
}
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)