Skip to content

Commit

Permalink
[All] make more use of auto-wiring in symfony 3.4. This will automati…
Browse files Browse the repository at this point in the history
…cally apply tags to classes implementing the needed interface for all kinds of Rule Conditions/Actions, Price Calculators, Index/Filters, Contextes. This also allows auto-wiring of coreshop generated services like repositories and manager by using the name of it. Like productRepository` or `storeRepository`
  • Loading branch information
dpfaffenbauer committed Jun 5, 2019
1 parent 8349b47 commit ab036e0
Show file tree
Hide file tree
Showing 71 changed files with 580 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

final class CompositeCountryContextPass extends PrioritizedCompositeServicePass
{
public const COUNTRY_CONTEXT_SERVICE_TAG = 'coreshop.context.country';

public function __construct()
{
parent::__construct(
'coreshop.context.country',
'coreshop.context.country.composite',
'coreshop.context.country',
self::COUNTRY_CONTEXT_SERVICE_TAG,
'addContext'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

final class CompositeRequestResolverPass extends PrioritizedCompositeServicePass
{
public const COUNTRY_REQUEST_RESOLVER_SERVICE_TAG = 'coreshop.context.country.request_based.resolver';

public function __construct()
{
parent::__construct(
'coreshop.context.country.request_based.resolver',
'coreshop.context.country.request_based.resolver.composite',
'coreshop.context.country.request_based.resolver',
self::COUNTRY_REQUEST_RESOLVER_SERVICE_TAG,
'addResolver'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

namespace CoreShop\Bundle\AddressBundle\DependencyInjection;

use CoreShop\Bundle\AddressBundle\DependencyInjection\Compiler\CompositeCountryContextPass;
use CoreShop\Bundle\AddressBundle\DependencyInjection\Compiler\CompositeRequestResolverPass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractModelExtension;
use CoreShop\Component\Address\Context\CountryContextInterface;
use CoreShop\Component\Address\Context\RequestBased\RequestResolverInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand All @@ -35,5 +39,14 @@ public function load(array $config, ContainerBuilder $container)
}

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

$container
->registerForAutoconfiguration(CountryContextInterface::class)
->addTag(CompositeCountryContextPass::COUNTRY_CONTEXT_SERVICE_TAG)
;
$container
->registerForAutoconfiguration(RequestResolverInterface::class)
->addTag(CompositeRequestResolverPass::COUNTRY_REQUEST_RESOLVER_SERVICE_TAG)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

final class CompositeCurrencyContextPass extends PrioritizedCompositeServicePass
{
public const CURRENCY_CONTEXT_SERVICE_TAG = 'coreshop.context.currency';

public function __construct()
{
parent::__construct(
'coreshop.context.currency',
'coreshop.context.currency.composite',
'coreshop.context.currency',
self::CURRENCY_CONTEXT_SERVICE_TAG,
'addContext'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

namespace CoreShop\Bundle\CurrencyBundle\DependencyInjection;

use CoreShop\Bundle\CurrencyBundle\DependencyInjection\Compiler\CompositeCurrencyContextPass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractModelExtension;
use CoreShop\Component\Currency\Context\CurrencyContextInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand All @@ -34,5 +36,11 @@ public function load(array $config, ContainerBuilder $container)
}

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


$container
->registerForAutoconfiguration(CurrencyContextInterface::class)
->addTag(CompositeCurrencyContextPass::CURRENCY_CONTEXT_SERVICE_TAG)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

final class CompositeCustomerContextPass extends PrioritizedCompositeServicePass
{
public const CUSTOMER_CONTEXT_SERVICE_TAG = 'coreshop.context.customer';

public function __construct()
{
parent::__construct(
'coreshop.context.customer',
'coreshop.context.customer.composite',
'coreshop.context.customer',
self::CUSTOMER_CONTEXT_SERVICE_TAG,
'addContext'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

final class CompositeRequestResolverPass extends PrioritizedCompositeServicePass
{
public const CUSTOMER_REQUEST_RESOLVER_SERVICE_TAG = 'coreshop.context.customer.request_based.resolver';

public function __construct()
{
parent::__construct(
'coreshop.context.customer.request_based.resolver',
'coreshop.context.customer.request_based.resolver.composite',
'coreshop.context.customer.request_based.resolver',
self::CUSTOMER_REQUEST_RESOLVER_SERVICE_TAG,
'addResolver'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

namespace CoreShop\Bundle\CustomerBundle\DependencyInjection;

use CoreShop\Bundle\CustomerBundle\DependencyInjection\Compiler\CompositeCustomerContextPass;
use CoreShop\Bundle\CustomerBundle\DependencyInjection\Compiler\CompositeRequestResolverPass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractModelExtension;
use CoreShop\Component\Customer\Context\CustomerContextInterface;
use CoreShop\Component\Customer\Context\RequestBased\RequestResolverInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand All @@ -39,5 +43,15 @@ public function load(array $config, ContainerBuilder $container)
}

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


$container
->registerForAutoconfiguration(CustomerContextInterface::class)
->addTag(CompositeCustomerContextPass::CUSTOMER_CONTEXT_SERVICE_TAG)
;
$container
->registerForAutoconfiguration(RequestResolverInterface::class)
->addTag(CompositeRequestResolverPass::CUSTOMER_REQUEST_RESOLVER_SERVICE_TAG)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

class RegisterConditionRendererTypesPass extends RegisterSimpleRegistryTypePass
{
public const INDEX_CONDITION_RENDERER_TAG = 'coreshop.index.condition.renderer';

public function __construct()
{
parent::__construct(
'coreshop.registry.index.condition.renderers',
'coreshop.index.condition.renderers',
'coreshop.index.condition.renderer'
self::INDEX_CONDITION_RENDERER_TAG
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

final class RegisterExtensionsPass implements CompilerPassInterface
{
public const INDEX_EXTENSION_TAG = 'coreshop.index.extension';

/**
* {@inheritdoc}
*/
Expand All @@ -29,7 +31,7 @@ public function process(ContainerBuilder $container)

$registry = $container->getDefinition('coreshop.registry.index.extensions');

foreach ($container->findTaggedServiceIds('coreshop.index.extension') as $id => $attributes) {
foreach ($container->findTaggedServiceIds(self::INDEX_EXTENSION_TAG) as $id => $attributes) {
$registry->addMethodCall('register', [$id, new Reference($id)]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

class RegisterFilterConditionTypesPass extends RegisterRegistryTypePass
{
public const INDEX_FILTER_CONDITION_TAG = 'coreshop.filter.condition_type';

public function __construct()
{
parent::__construct(
'coreshop.registry.filter.condition_types',
'coreshop.form_registry.filter.condition_types',
'coreshop.filter.condition_types',
'coreshop.filter.condition_type'
self::INDEX_FILTER_CONDITION_TAG
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

class RegisterGetterPass extends RegisterRegistryTypePass
{
public const INDEX_GETTER_TAG = 'coreshop.index.getter';

public function __construct()
{
parent::__construct(
'coreshop.registry.index.getter',
'coreshop.form_registry.index.getter',
'coreshop.index.getters',
'coreshop.index.getter'
self::INDEX_GETTER_TAG
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

class RegisterIndexWorkerPass extends RegisterRegistryTypePass
{
public const INDEX_WORKER_TAG = 'coreshop.index.worker';

public function __construct()
{
parent::__construct(
'coreshop.registry.index.worker',
'coreshop.form_registry.index.worker',
'coreshop.index.workers',
'coreshop.index.worker'
self::INDEX_WORKER_TAG
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

class RegisterInterpreterPass extends RegisterRegistryTypePass
{
public const INDEX_INTERPRETER_TAG = 'coreshop.index.interpreter';

public function __construct()
{
parent::__construct(
'coreshop.registry.index.interpreter',
'coreshop.form_registry.index.interpreter',
'coreshop.index.interpreters',
'coreshop.index.interpreter'
self::INDEX_INTERPRETER_TAG
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@

namespace CoreShop\Bundle\IndexBundle\DependencyInjection;

use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterConditionRendererTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterExtensionsPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterFilterConditionTypesPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterGetterPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterIndexWorkerPass;
use CoreShop\Bundle\IndexBundle\DependencyInjection\Compiler\RegisterInterpreterPass;
use CoreShop\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractModelExtension;
use CoreShop\Component\Index\Condition\DynamicRendererInterface;
use CoreShop\Component\Index\Extension\IndexExtensionInterface;
use CoreShop\Component\Index\Filter\FilterConditionProcessorInterface;
use CoreShop\Component\Index\Getter\GetterInterface;
use CoreShop\Component\Index\Interpreter\InterpreterInterface;
use CoreShop\Component\Index\Worker\WorkerInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
Expand Down Expand Up @@ -45,5 +57,35 @@ public function load(array $config, ContainerBuilder $container)
}

$this->registerPimcoreResources('coreshop', $config['pimcore_admin'], $container);

$container
->registerForAutoconfiguration(DynamicRendererInterface::class)
->addTag(RegisterConditionRendererTypesPass::INDEX_CONDITION_RENDERER_TAG)
;

$container
->registerForAutoconfiguration(IndexExtensionInterface::class)
->addTag(RegisterExtensionsPass::INDEX_EXTENSION_TAG)
;

$container
->registerForAutoconfiguration(FilterConditionProcessorInterface::class)
->addTag(RegisterFilterConditionTypesPass::INDEX_FILTER_CONDITION_TAG)
;

$container
->registerForAutoconfiguration(GetterInterface::class)
->addTag(RegisterGetterPass::INDEX_GETTER_TAG)
;

$container
->registerForAutoconfiguration(WorkerInterface::class)
->addTag(RegisterIndexWorkerPass::INDEX_WORKER_TAG)
;

$container
->registerForAutoconfiguration(InterpreterInterface::class)
->addTag(RegisterInterpreterPass::INDEX_INTERPRETER_TAG)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
return;
}

if (!$this->formTypeRegistry->has($objectType, 'default')) {
return;
}

$this->addConfigurationFields($event->getForm(), $this->formTypeRegistry->get($objectType, 'default'));
})
->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
Expand All @@ -68,6 +72,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
return;
}

if (!$this->formTypeRegistry->has($data['objectType'], 'default')) {
return;
}

$this->addConfigurationFields($event->getForm(), $this->formTypeRegistry->get($data['objectType'], 'default'));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
return;
}

if (!$this->formTypeRegistry->has($type, 'default')) {
return;
}

$this->addConfigurationFields($event->getForm(), $this->formTypeRegistry->get($type, 'default'));
})
->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
Expand All @@ -75,6 +79,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
return;
}

if (!$this->formTypeRegistry->has($data['type'], 'default')) {
return;
}

$this->addConfigurationFields($event->getForm(), $this->formTypeRegistry->get($data['type'], 'default'));
});
}
Expand Down
9 changes: 9 additions & 0 deletions src/CoreShop/Bundle/IndexBundle/Form/Type/IndexType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$type = $this->getRegistryIdentifier($event->getForm(), $event->getData());

if (null === $type) {
return;
}

if (!$this->formTypeRegistry->has($type, 'default')) {
return;
}

$this->addConfigurationFields($event->getForm(), $this->formTypeRegistry->get($type, 'default'));
})
->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
Expand All @@ -73,6 +78,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
return;
}

if (!$this->formTypeRegistry->has($data['worker'], 'default')) {
return;
}

$this->addConfigurationFields($event->getForm(), $this->formTypeRegistry->get($data['worker'], 'default'));
});
}
Expand Down
Loading

0 comments on commit ab036e0

Please sign in to comment.