diff --git a/StorageBundle/Adaptors/S3Storage.php b/StorageBundle/Adaptors/S3Storage.php index 9f48b61..4376820 100644 --- a/StorageBundle/Adaptors/S3Storage.php +++ b/StorageBundle/Adaptors/S3Storage.php @@ -3,6 +3,7 @@ namespace Bluesquare\StorageBundle\Adaptors; use Aws\S3\S3Client; +use Symfony\Component\Config\Definition\Exception\Exception; /** * Interface de manipulation du stockage S3 @@ -18,10 +19,16 @@ class S3Storage protected $bucket; protected $region; + private $required_config_field = ['bucket', 'region', 'endpoint', 'credientials']; + public function __construct ($storage_name, $config) { // TODO: on check la présence de "bucket", "region", "endpoint", "credentials" ("key", "secret") dans $config + if ($this->configIsNotNormed($config)) + throw new Exception("Error from config file :("); +// if (isset($config['bucket']) && isset($config)) + $this->config = $config; $this->bucket = $config['bucket']; @@ -36,6 +43,12 @@ class S3Storage ]); } + private function configIsNotNormed($config) + { + dump(array_diff($this->required_config_field, $config)); die; +// return () + } + protected function getPrefix($prefix = null) { $ret = ''; diff --git a/StorageBundle/DependencyInjection/Configuration.php b/StorageBundle/DependencyInjection/Configuration.php index b643483..22db9e0 100644 --- a/StorageBundle/DependencyInjection/Configuration.php +++ b/StorageBundle/DependencyInjection/Configuration.php @@ -20,14 +20,14 @@ class Configuration implements ConfigurationInterface $root->useAttributeAsKey('storage_name') ->prototype('array') ->children() - ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('bucket')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('region')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('endpoint')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('type')->end() + ->scalarNode('bucket')->end() + ->scalarNode('region')->end() + ->scalarNode('endpoint')->end() ->arrayNode('credentials') ->children() - ->scalarNode('key')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('secret')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('key')->end() + ->scalarNode('secret')->end() ->end() ->end() ->scalarNode('version')->end()