42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace KupShop\FeedsBundle\DependencyInjection\Compiler;
|
|
|
|
use KupShop\FeedGeneratorBundle\Feed\IConfigurableFeed;
|
|
use KupShop\FeedsBundle\FeedLocator;
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
/**
|
|
* Check out https://symfony.com/doc/current/service_container/tags.html.
|
|
*/
|
|
class FeedPass implements CompilerPassInterface
|
|
{
|
|
public function process(ContainerBuilder $container)
|
|
{
|
|
// always first check if the primary service is defined
|
|
if (!$container->has(FeedLocator::class)) {
|
|
return;
|
|
}
|
|
|
|
$definition = $container->findDefinition(FeedLocator::class);
|
|
|
|
// find all service IDs with the kupshop.feed tag
|
|
$taggedServices = $container->findTaggedServiceIds('kupshop.feed');
|
|
|
|
foreach ($taggedServices as $id => $tags) {
|
|
$class = $container->findDefinition($id)->getClass();
|
|
$interfaces = class_implements($class);
|
|
$definition->addMethodCall('addFeed', [
|
|
$id,
|
|
$class::getType(),
|
|
$class::getAlias(),
|
|
isset($interfaces[IConfigurableFeed::class]),
|
|
$class::isAllowed(),
|
|
]);
|
|
}
|
|
|
|
$definition->addMethodCall('sortAliases');
|
|
}
|
|
}
|