]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
Add tagged services for import
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / ImportCompilerPass.php
diff --git a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
new file mode 100644 (file)
index 0000000..a363a56
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+
+namespace Wallabag\ImportBundle\Import;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+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']]
+                );
+            }
+        }
+    }
+}