Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Jan 10, 2021
1 parent 1b21a6a commit defbd0d
Show file tree
Hide file tree
Showing 30 changed files with 167 additions and 958 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"league/flysystem-aws-s3-v3": "^1.0",
"league/flysystem-sftp": "^1.0",
"symfony/dotenv": "^5.2",
"nelexa/zip": "^3.3"
"nelexa/zip": "^3.3",
"superbalist/flysystem-google-storage": "^7.2"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
Expand Down
4 changes: 4 additions & 0 deletions src/Bundle/Command/ReconfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ protected function rebuild(InputInterface $input, OutputInterface $output)
$discovery = [];
foreach ($rootPackage->getRequires() as $require) {
$package = $composer->getRepositoryManager()->findPackage($require->getTarget(), $require->getConstraint());
if (!$package) {
continue;
}

$bundleClasses = $package->getExtra()['nanbando']['bundle-classes'] ?? [];

foreach ($bundleClasses as $bundleClass) {
Expand Down
128 changes: 36 additions & 92 deletions src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Webmozart\PathUtil\Path;

/*
nanbando:
storage:
remote:
s3:
client:
version: 'latest'
region: 'region-id'
credentials:
key: 's3-key'
secret: 's3-secret'
bucket: 'my-bucket'
prefix: '/my-prefix'
googlecloudstorage:
client:
projectId: 'your-project-id'
keyFilePath: '/path/to/service-account.json' # optional
storage_api_url: ~
bucket: 'my-bucket'
prefix: '/my-prefix'
local:
directory: '/nanbando'
*/

class Configuration implements ConfigurationInterface
{
const ENV_ENVIRONMENT = 'NANBANDO_ENVIRONMENT';
Expand All @@ -35,8 +59,7 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder('nanbando');

$rootNode = $treeBuilder->getRootNode();
$this->addAdapterSection($rootNode);
$this->addFilesystemSection($rootNode);
$this->addStorageSection($rootNode);

$rootNode->children()
->scalarNode('name')->defaultValue('nanbando')->end()
Expand Down Expand Up @@ -69,15 +92,6 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->arrayNode('storage')
->addDefaultsIfNotSet()
->children()
->scalarNode('local_directory')
->defaultValue(Path::join([Path::getHomeDirectory(), 'nanbando']))
->end()
->scalarNode('remote_service')->end()
->end()
->end()
->arrayNode('servers')
->useAttributeAsKey('name')
->prototype('array')
Expand Down Expand Up @@ -144,93 +158,23 @@ public function getConfigTreeBuilder()
return $treeBuilder;
}

private function addAdapterSection(ArrayNodeDefinition $node)
{
$adapterNodeBuilder = $node
->fixXmlConfig('adapter')
private function addStorageSection(ArrayNodeDefinition $node) {
$remoteNode = $node
->children()
->arrayNode('adapters')
->useAttributeAsKey('name')
->prototype('array')
->performNoDeepMerging()
->children()
->arrayNode('storage')
->addDefaultsIfNotSet()
->children()
->scalarNode('local_directory')
->defaultValue(Path::join([Path::getHomeDirectory(), 'nanbando']))
->end()
->arrayNode('remote')
->children()
;

foreach ($this->adapterFactories as $name => $factory) {
$factoryNode = $adapterNodeBuilder->arrayNode($name)->canBeUnset();
$factoryNode = $remoteNode->arrayNode($name)->canBeUnset();

$factory->addConfiguration($factoryNode);
}
}

private function addFilesystemSection(ArrayNodeDefinition $node)
{
$supportedVisibilities = array(
AdapterInterface::VISIBILITY_PRIVATE,
AdapterInterface::VISIBILITY_PUBLIC,
);

$node
->fixXmlConfig('filesystem')
->children()
->arrayNode('filesystems')
->useAttributeAsKey('name')
->prototype('array')
->children()
->booleanNode('disable_asserts')
->defaultFalse()
->end()
->arrayNode('plugins')->treatNullLike(array())->prototype('scalar')->end()->end()
->scalarNode('adapter')->isRequired()->end()
->scalarNode('alias')->defaultNull()->end()
->scalarNode('mount')->defaultNull()->end()
->arrayNode('stream_wrapper')
->beforeNormalization()
->ifString()->then(function ($protocol) {
return ['protocol' => $protocol];
})
->end()
->children()
->scalarNode('protocol')->isRequired()->end()
->arrayNode('configuration')
->children()
->arrayNode('permissions')
->isRequired()
->children()
->arrayNode('dir')
->isRequired()
->children()
->integerNode('private')->isRequired()->end()
->integerNode('public')->isRequired()->end()
->end()
->end()
->arrayNode('file')
->isRequired()
->children()
->integerNode('private')->isRequired()->end()
->integerNode('public')->isRequired()->end()
->end()
->end()
->end()
->end()
->arrayNode('metadata')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')->cannotBeEmpty()->end()
->end()
->integerNode('public_mask')->isRequired()->end()
->end()
->end()
->end()
->end()
->scalarNode('visibility')
->validate()
->ifNotInArray($supportedVisibilities)
->thenInvalid('The visibility %s is not supported.')
->end()
->end()
->end()
->end()
;
}
}

This file was deleted.

40 changes: 0 additions & 40 deletions src/Bundle/DependencyInjection/Factory/Adapter/AwsS3V2Factory.php

This file was deleted.

32 changes: 24 additions & 8 deletions src/Bundle/DependencyInjection/Factory/Adapter/AwsS3V3Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,54 @@

namespace Nanbando\Bundle\DependencyInjection\Factory\Adapter;

use Aws\S3\S3Client;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Nanbando\Bundle\DependencyInjection\Factory\AdapterFactoryInterface;

class AwsS3V3Factory implements AdapterFactoryInterface
{
public function getKey()
public function getKey(): string
{
return 'awss3v3';
}

public function create(ContainerBuilder $container, $id, array $config)
public function create(ContainerBuilder $container, $id, array $config): void
{
$definition = $container
$container->setDefinition($id . '.client', new Definition(S3Client::class))
->addArgument($config['client']);

$container
->setDefinition($id, new ChildDefinition('nanbando.adapter.awss3v3'))
->replaceArgument(0, new Reference($config['client']))
->replaceArgument(0, new Reference($id . '.client'))
->replaceArgument(1, $config['bucket'])
->replaceArgument(2, $config['prefix'])
->addArgument((array) $config['options'])
;
}

public function addConfiguration(NodeDefinition $node)
public function addConfiguration(NodeDefinition $node): void
{
$node
->children()
->scalarNode('client')->isRequired()->end()
->arrayNode('client')
->isRequired()
->children()
->scalarNode('version')->isRequired()->end()
->scalarNode('region')->isRequired()->end()
->arrayNode('credentials')
->isRequired()
->children()
->scalarNode('key')->isRequired()->end()
->scalarNode('secret')->isRequired()->end()
->end()
->end()
->end()
->end()
->scalarNode('bucket')->isRequired()->end()
->scalarNode('prefix')->defaultNull()->end()
->arrayNode('options')->prototype('scalar')->end()
->end()
;
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit defbd0d

Please sign in to comment.