37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\FeedGeneratorBundle\DependencyInjection\Compiler;
|
|
|
|
use KupShop\FeedGeneratorBundle\ContextPropertiesLocator;
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
/**
|
|
* Check out https://symfony.com/doc/current/service_container/tags.html.
|
|
*/
|
|
class ContextPropertiesPass implements CompilerPassInterface
|
|
{
|
|
public function process(ContainerBuilder $container)
|
|
{
|
|
// always first check if the primary service is defined
|
|
if (!$container->has(ContextPropertiesLocator::class)) {
|
|
return;
|
|
}
|
|
|
|
$definition = $container->findDefinition(ContextPropertiesLocator::class);
|
|
|
|
// find all service IDs with the kupshop.feed.expression.functions tag
|
|
$taggedServices = $container->findTaggedServiceIds('kupshop.feed.context.property');
|
|
|
|
foreach ($taggedServices as $id => $tags) {
|
|
$class = $container->findDefinition($id)->getClass();
|
|
$definition->addMethodCall('addContextProperty', [
|
|
$id,
|
|
$class::getName(),
|
|
]);
|
|
}
|
|
|
|
$definition->addMethodCall('sortContexts');
|
|
}
|
|
}
|