From 8aed18090de00b6c4c9784ced0166ba4a958636b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Wed, 19 Apr 2017 09:51:29 +0200 Subject: [PATCH] Use compiler passes to override vendor services --- .../CompilerPass/LegacyCachePurgerPass.php | 29 +++++++++++++++ .../CompilerPass/SecurityPass.php | 37 +++++++++++++++++++ .../NetgenEzSyliusExtension.php | 1 - NetgenEzSyliusBundle.php | 17 +++++++++ Resources/config/override.yml | 13 ------- 5 files changed, 83 insertions(+), 14 deletions(-) create mode 100644 DependencyInjection/CompilerPass/LegacyCachePurgerPass.php create mode 100644 DependencyInjection/CompilerPass/SecurityPass.php delete mode 100644 Resources/config/override.yml diff --git a/DependencyInjection/CompilerPass/LegacyCachePurgerPass.php b/DependencyInjection/CompilerPass/LegacyCachePurgerPass.php new file mode 100644 index 0000000..1cb19fe --- /dev/null +++ b/DependencyInjection/CompilerPass/LegacyCachePurgerPass.php @@ -0,0 +1,29 @@ +has('ezpublish_legacy.legacy_cache_purger')) { + return; + } + + // Overrides Legacy Bridge cache purger to set "quiet" flag to eZCLI, + // since it crashes Sylius installation procedure. + + $container + ->findDefinition('ezpublish_legacy.legacy_cache_purger') + ->setClass(LegacyCachePurger::class); + } +} diff --git a/DependencyInjection/CompilerPass/SecurityPass.php b/DependencyInjection/CompilerPass/SecurityPass.php new file mode 100644 index 0000000..be0693a --- /dev/null +++ b/DependencyInjection/CompilerPass/SecurityPass.php @@ -0,0 +1,37 @@ +has('security.authentication.success_handler')) { + $container + ->findDefinition('security.authentication.success_handler') + ->setClass(AuthenticationSuccessHandler::class); + } + + if ($container->has('security.authentication.provider.dao')) { + $container + ->findDefinition('security.authentication.provider.dao') + ->setClass(DaoAuthenticationProvider::class); + } + + if ($container->has('sylius.authentication.success_handler')) { + $container + ->findDefinition('sylius.authentication.success_handler') + ->setClass(AuthenticationSuccessHandler::class); + } + } +} diff --git a/DependencyInjection/NetgenEzSyliusExtension.php b/DependencyInjection/NetgenEzSyliusExtension.php index 3c0c762..03b3439 100644 --- a/DependencyInjection/NetgenEzSyliusExtension.php +++ b/DependencyInjection/NetgenEzSyliusExtension.php @@ -25,7 +25,6 @@ public function load(array $configs, ContainerBuilder $container) new FileLocator(__DIR__ . '/../Resources/config') ); - $loader->load('override.yml'); $loader->load('doctrine.yml'); $loader->load('fieldtypes.yml'); $loader->load('listeners.yml'); diff --git a/NetgenEzSyliusBundle.php b/NetgenEzSyliusBundle.php index 17d9f48..dc2e7f7 100644 --- a/NetgenEzSyliusBundle.php +++ b/NetgenEzSyliusBundle.php @@ -2,8 +2,25 @@ namespace Netgen\Bundle\EzSyliusBundle; +use Netgen\Bundle\EzSyliusBundle\DependencyInjection\CompilerPass\LegacyCachePurgerPass; +use Netgen\Bundle\EzSyliusBundle\DependencyInjection\CompilerPass\SecurityPass; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; class NetgenEzSyliusBundle extends Bundle { + /** + * Builds the bundle. + * + * It is only ever called once when the cache is empty. + * + * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance + */ + public function build(ContainerBuilder $container) + { + parent::build($container); + + $container->addCompilerPass(new SecurityPass()); + $container->addCompilerPass(new LegacyCachePurgerPass()); + } } diff --git a/Resources/config/override.yml b/Resources/config/override.yml deleted file mode 100644 index 22c7cd6..0000000 --- a/Resources/config/override.yml +++ /dev/null @@ -1,13 +0,0 @@ -parameters: - security.authentication.success_handler.class: Netgen\Bundle\EzSyliusBundle\Authentication\AuthenticationSuccessHandler - security.authentication.provider.dao.class: Netgen\Bundle\EzSyliusBundle\Authentication\DaoAuthenticationProvider - - # Overrides Legacy Bridge cache purger to set "quiet" flag to eZCLI, - # since it crashes Sylius installation procedure. - ezpublish_legacy.legacy_cache_purger.class: Netgen\Bundle\EzSyliusBundle\Cache\LegacyCachePurger - -services: - sylius.authentication.success_handler: - class: Netgen\Bundle\EzSyliusBundle\Authentication\AuthenticationSuccessHandler - parent: security.authentication.success_handler - public: false