diff --git a/src/Bundle/ChillDocStoreBundle/ChillDocStoreBundle.php b/src/Bundle/ChillDocStoreBundle/ChillDocStoreBundle.php index 8dcbe72c3..1cd203c35 100644 --- a/src/Bundle/ChillDocStoreBundle/ChillDocStoreBundle.php +++ b/src/Bundle/ChillDocStoreBundle/ChillDocStoreBundle.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\DocStoreBundle; +use Chill\DocStoreBundle\DependencyInjection\Compiler\StorageConfigurationCompilerPass; use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInterface; use Chill\DocStoreBundle\GenericDoc\GenericDocForPersonProviderInterface; use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface; @@ -27,5 +28,7 @@ class ChillDocStoreBundle extends Bundle ->addTag('chill_doc_store.generic_doc_person_provider'); $container->registerForAutoconfiguration(GenericDocRendererInterface::class) ->addTag('chill_doc_store.generic_doc_renderer'); + + $container->addCompilerPass(new StorageConfigurationCompilerPass()); } } diff --git a/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php b/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php index efeb6362d..6851441e0 100644 --- a/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php +++ b/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php @@ -53,7 +53,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf $this->prependTwig($container); } - protected function prependAuthorization(ContainerBuilder $container) + private function prependAuthorization(ContainerBuilder $container) { $container->prependExtensionConfig('security', [ 'role_hierarchy' => [ @@ -69,7 +69,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf ]); } - protected function prependRoute(ContainerBuilder $container) + private function prependRoute(ContainerBuilder $container) { // declare routes for task bundle $container->prependExtensionConfig('chill_main', [ @@ -81,7 +81,7 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf ]); } - protected function prependTwig(ContainerBuilder $container) + private function prependTwig(ContainerBuilder $container) { $twigConfig = [ 'form_themes' => ['@ChillDocStore/Form/fields.html.twig'], diff --git a/src/Bundle/ChillDocStoreBundle/DependencyInjection/Compiler/StorageConfigurationCompilerPass.php b/src/Bundle/ChillDocStoreBundle/DependencyInjection/Compiler/StorageConfigurationCompilerPass.php new file mode 100644 index 000000000..f36cba2f4 --- /dev/null +++ b/src/Bundle/ChillDocStoreBundle/DependencyInjection/Compiler/StorageConfigurationCompilerPass.php @@ -0,0 +1,60 @@ +getParameterBag() + ->resolveValue($container->getParameter('chill_doc_store')); + + if (array_key_exists('openstack', $config) && array_key_exists('local_storage', $config)) { + throw new InvalidConfigurationException('chill_doc_store: you can either configure a local storage (key local_storage) or openstack storage (key openstack). Choose between them.'); + } + + if (array_key_exists('local_storage', $config)) { + foreach (self::SERVICES_OPENSTACK as $service) { + $container->removeDefinition($service); + } + + $container->setAlias(StoredObjectManagerInterface::class, \Chill\DocStoreBundle\AsyncUpload\Driver\LocalStorage\StoredObjectManager::class); + $container->setAlias(TempUrlGeneratorInterface::class, TempUrlLocalStorageGenerator::class); + } else { + foreach (self::SERVICES_LOCAL_STORAGE as $service) { + $container->removeDefinition($service); + } + + $container->setAlias(StoredObjectManagerInterface::class, \Chill\DocStoreBundle\AsyncUpload\Driver\OpenstackObjectStore\StoredObjectManager::class); + $container->setAlias(TempUrlGeneratorInterface::class, TempUrlOpenstackGenerator::class); + } + } +} diff --git a/src/Bundle/ChillDocStoreBundle/config/services.yaml b/src/Bundle/ChillDocStoreBundle/config/services.yaml index ec8a51832..1ca7fe4b9 100644 --- a/src/Bundle/ChillDocStoreBundle/config/services.yaml +++ b/src/Bundle/ChillDocStoreBundle/config/services.yaml @@ -8,7 +8,6 @@ services: tags: - { name: doctrine.repository_service } - Chill\DocStoreBundle\Security\Authorization\: resource: "./../Security/Authorization" @@ -56,6 +55,3 @@ services: Chill\DocStoreBundle\AsyncUpload\Command\: resource: '../AsyncUpload/Command/' - - Chill\DocStoreBundle\AsyncUpload\TempUrlGeneratorInterface: - alias: Chill\DocStoreBundle\AsyncUpload\Driver\OpenstackObjectStore\TempUrlOpenstackGenerator