Skip to content

Commit

Permalink
Use compiler passes to override vendor services
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Apr 19, 2017
1 parent 679c7a4 commit 8aed180
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 14 deletions.
29 changes: 29 additions & 0 deletions DependencyInjection/CompilerPass/LegacyCachePurgerPass.php
@@ -0,0 +1,29 @@
<?php

namespace Netgen\Bundle\EzSyliusBundle\DependencyInjection\CompilerPass;

use Netgen\Bundle\EzSyliusBundle\Cache\LegacyCachePurger;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class LegacyCachePurgerPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
if (!$container->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);
}
}
37 changes: 37 additions & 0 deletions DependencyInjection/CompilerPass/SecurityPass.php
@@ -0,0 +1,37 @@
<?php

namespace Netgen\Bundle\EzSyliusBundle\DependencyInjection\CompilerPass;

use Netgen\Bundle\EzSyliusBundle\Authentication\AuthenticationSuccessHandler;
use Netgen\Bundle\EzSyliusBundle\Authentication\DaoAuthenticationProvider;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class SecurityPass implements CompilerPassInterface
{
/**
* You can modify the container here before it is dumped to PHP code.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
if ($container->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);
}
}
}
1 change: 0 additions & 1 deletion DependencyInjection/NetgenEzSyliusExtension.php
Expand Up @@ -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');
Expand Down
17 changes: 17 additions & 0 deletions NetgenEzSyliusBundle.php
Expand Up @@ -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());
}
}
13 changes: 0 additions & 13 deletions Resources/config/override.yml

This file was deleted.

0 comments on commit 8aed180

Please sign in to comment.