aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
blob: d7df0a83c06dabb8276b886d6e530e0300a50ba2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

namespace Wallabag\ImportBundle\Import;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class ImportCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('wallabag_import.chain')) {
            return;
        }

        $definition = $container->getDefinition(
            'wallabag_import.chain'
        );

        $taggedServices = $container->findTaggedServiceIds(
            'wallabag_import.import'
        );
        foreach ($taggedServices as $id => $tagAttributes) {
            foreach ($tagAttributes as $attributes) {
                $definition->addMethodCall(
                    'addImport',
                    [new Reference($id), $attributes['alias']]
                );
            }
        }
    }
}