Skip to content

Commit

Permalink
Merge pull request #1535 from dpfaffenbauer/issues/1532
Browse files Browse the repository at this point in the history
[CompilerPass] rework compiler passes (simplify)
  • Loading branch information
dpfaffenbauer authored Dec 8, 2020
2 parents 9df008e + 19aa31d commit 98cb924
Show file tree
Hide file tree
Showing 68 changed files with 566 additions and 715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\AddressBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\PrioritizedCompositeServicePass;
use CoreShop\Component\Registry\PrioritizedCompositeServicePass;

final class CompositeCountryContextPass extends PrioritizedCompositeServicePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\AddressBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\PrioritizedCompositeServicePass;
use CoreShop\Component\Registry\PrioritizedCompositeServicePass;

final class CompositeRequestResolverPass extends PrioritizedCompositeServicePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ public function process(ContainerBuilder $container)
$formRegistry = $container->getDefinition('coreshop.form_registry.payment.settings');

foreach ($container->findTaggedServiceIds('coreshop.payment.form.settings') as $id => $attributes) {
if (!isset($attributes[0]['payum-factory'])) {
throw new \InvalidArgumentException('Tagged Service `' . $id . '` needs to have `payum-factory` attribute.');
}
foreach ($attributes as $tag) {
if (!isset($tag['payum-factory'])) {
throw new \InvalidArgumentException('Tagged Service `'.$id.'` needs to have `payum-factory` attribute.');
}

$payumFactory = $attributes[0]['payum-factory'];
$payumFactory = $tag['payum-factory'];

if (!array_key_exists($payumFactory, $payumFactories)) {
throw new \InvalidArgumentException(sprintf('You are trying to register a frontend-from for payum-factory %s which does not exist', $payumFactory));
}
if (!array_key_exists($payumFactory, $payumFactories)) {
throw new \InvalidArgumentException(sprintf('You are trying to register a frontend-from for payum-factory %s which does not exist',
$payumFactory));
}

$formRegistry->addMethodCall('add', [$payumFactory, 'default', $container->getDefinition($id)->getClass()]);
$formRegistry
->addMethodCall('add', [$payumFactory, 'default', $container->getDefinition($id)->getClass()]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\CoreBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterSimpleRegistryTypePass;
use CoreShop\Component\Registry\RegisterSimpleRegistryTypePass;

class RegisterPortletsPass extends RegisterSimpleRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\CoreBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterSimpleRegistryTypePass;
use CoreShop\Component\Registry\RegisterSimpleRegistryTypePass;

class RegisterReportsPass extends RegisterSimpleRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\CurrencyBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\PrioritizedCompositeServicePass;
use CoreShop\Component\Registry\PrioritizedCompositeServicePass;

final class CompositeCurrencyContextPass extends PrioritizedCompositeServicePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\CustomerBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\PrioritizedCompositeServicePass;
use CoreShop\Component\Registry\PrioritizedCompositeServicePass;

final class CompositeCustomerContextPass extends PrioritizedCompositeServicePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\CustomerBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\PrioritizedCompositeServicePass;
use CoreShop\Component\Registry\PrioritizedCompositeServicePass;

final class CompositeRequestResolverPass extends PrioritizedCompositeServicePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

class RegisterColumnTypePass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterSimpleRegistryTypePass;
use CoreShop\Component\Registry\RegisterSimpleRegistryTypePass;

class RegisterConditionRendererTypesPass extends RegisterSimpleRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public function process(ContainerBuilder $container)
foreach ($container->findTaggedServiceIds(self::INDEX_FILTER_CONDITION_TAG) as $id => $attributes) {
$definition = $container->findDefinition($id);

$definition->addTag('coreshop.filter.user_condition_type', $attributes[0]);
$definition->addTag('coreshop.filter.pre_condition_type', $attributes[0]);
foreach ($attributes as $tag) {
$definition->addTag('coreshop.filter.user_condition_type', $tag);
$definition->addTag('coreshop.filter.pre_condition_type', $tag);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

class RegisterFilterPreConditionTypesPass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

class RegisterFilterUserConditionTypesPass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

class RegisterGetterPass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

class RegisterIndexWorkerPass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

class RegisterInterpreterPass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterSimpleRegistryTypePass;
use CoreShop\Component\Registry\RegisterSimpleRegistryTypePass;

class RegisterOrderRendererTypesPass extends RegisterSimpleRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\LocaleBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\PrioritizedCompositeServicePass;
use CoreShop\Component\Registry\PrioritizedCompositeServicePass;

final class CompositeLocaleContextPass extends PrioritizedCompositeServicePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ public function process(ContainerBuilder $container)
$map = [];
foreach ($container->findTaggedServiceIds(self::MENU_BUILDER_TAG) as $id => $attributes) {
foreach ($attributes as $tag) {

$definition = $container->findDefinition($id);

if (!isset($attributes[0]['type'])) {
$attributes[0]['type'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
if (!isset($tag['type'])) {
$tag['type'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
}

if (!isset($attributes[0]['menu'])) {
$attributes[0]['menu'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
if (!isset($tag['menu'])) {
$tag['menu'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
}

$type = $tag['menu'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\NotificationBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;
use CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry;
use CoreShop\Component\Registry\ServiceRegistry;
use CoreShop\Component\Rule\Condition\ConditionCheckerInterface;
Expand Down Expand Up @@ -64,8 +64,8 @@ public function process(ContainerBuilder $container)
foreach ($attributes as $tag) {
$definition = $container->findDefinition($id);

if (!isset($attributes[0]['type'])) {
$attributes[0]['type'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
if (!isset($tag['type'])) {
$tag['type'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
}

if (!isset($tag['notification-type'])) {
Expand Down Expand Up @@ -97,7 +97,7 @@ public function process(ContainerBuilder $container)
$registries[$type]->addMethodCall('register', [$tag['type'], new Reference($id)]);
$registry->addMethodCall('register', [$fqtn, new Reference($id)]);

if (isset($attributes[0]['form-type'])) {
if (isset($tag['form-type'])) {
$formRegistries[$type]->addMethodCall('add', [$tag['type'], 'default', $tag['form-type']]);
$formRegistry->addMethodCall('add', [$fqtn, 'default', $tag['form-type']]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,5 @@ public function load(array $config, ContainerBuilder $container)
}

$loader->load('services.yml');

$container
->registerForAutoconfiguration(NotificationRuleProcessorInterface::class)
->addTag(NotificationRuleActionPass::NOTIFICATION_ACTION_TAG);

$container
->registerForAutoconfiguration(NotificationConditionCheckerInterface::class)
->addTag(NotificationRuleConditionPass::NOTIFICATION_CONDITION_TAG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\OrderBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

final class CartPriceRuleActionPass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CoreShop\Bundle\OrderBundle\DependencyInjection\Compiler;

use CoreShop\Bundle\PimcoreBundle\DependencyInjection\Compiler\RegisterRegistryTypePass;
use CoreShop\Component\Registry\RegisterRegistryTypePass;

final class CartPriceRuleConditionPass extends RegisterRegistryTypePass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,18 @@

namespace CoreShop\Bundle\OrderBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use CoreShop\Component\Registry\RegisterSimpleRegistryTypePass;

final class PurchasableDiscountCalculatorsPass implements CompilerPassInterface
final class PurchasableDiscountCalculatorsPass extends RegisterSimpleRegistryTypePass
{
public const PURCHASABLE_DISCOUNT_CALCULATOR_TAG = 'coreshop.order.purchasable.discount_calculator';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function __construct()
{
if (!$container->has('coreshop.registry.order.purchasable.discount_calculators')) {
return;
}

$registry = $container->getDefinition('coreshop.registry.order.purchasable.discount_calculators');

$map = [];
foreach ($container->findTaggedServiceIds(self::PURCHASABLE_DISCOUNT_CALCULATOR_TAG) as $id => $attributes) {
$definition = $container->findDefinition($id);

if (!isset($attributes[0]['type'])) {
$attributes[0]['type'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
}

$map[$attributes[0]['type']] = $attributes[0]['type'];
$registry->addMethodCall('register', [$attributes[0]['type'], $attributes[0]['priority'] ?? 1000, new Reference($id)]);
}

$container->setParameter('coreshop.order.purchasable.discount_calculators', $map);
parent::__construct(
'coreshop.registry.order.purchasable.discount_calculators',
'coreshop.order.purchasable.discount_calculators',
self::PURCHASABLE_DISCOUNT_CALCULATOR_TAG
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,18 @@

namespace CoreShop\Bundle\OrderBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use CoreShop\Component\Registry\RegisterSimpleRegistryTypePass;

final class PurchasableDiscountPriceCalculatorsPass implements CompilerPassInterface
final class PurchasableDiscountPriceCalculatorsPass extends RegisterSimpleRegistryTypePass
{
public const PURCHASABLE_DISCOUNT_PRICE_CALCULATOR_TAG = 'coreshop.order.purchasable.discount_price_calculator';

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
public function __construct()
{
if (!$container->has('coreshop.registry.order.purchasable.discount_price_calculators')) {
return;
}

$registry = $container->getDefinition('coreshop.registry.order.purchasable.discount_price_calculators');

$map = [];
foreach ($container->findTaggedServiceIds(self::PURCHASABLE_DISCOUNT_PRICE_CALCULATOR_TAG) as $id => $attributes) {
$definition = $container->findDefinition($id);

if (!isset($attributes[0]['type'])) {
$attributes[0]['type'] = Container::underscore(substr(strrchr($definition->getClass(), '\\'), 1));
}

$map[$attributes[0]['type']] = $attributes[0]['type'];
$registry->addMethodCall('register', [$attributes[0]['type'], $attributes[0]['priority'] ?? 1000, new Reference($id)]);
}

$container->setParameter('coreshop.order.purchasable.discount_price_calculators', $map);
parent::__construct(
'coreshop.registry.order.purchasable.discount_price_calculators',
'coreshop.order.purchasable.discount_price_calculator',
self::PURCHASABLE_DISCOUNT_PRICE_CALCULATOR_TAG
);
}
}
Loading

0 comments on commit 98cb924

Please sign in to comment.