Completed
Push — master ( 064006...20444a )
by WEBEWEB
04:40
created

JQueryDataTablesCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\DataTablesBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
use WBW\Bundle\JQuery\DataTablesBundle\Manager\DataTablesManager;
18
use WBW\Bundle\JQuery\DataTablesBundle\Provider\DataTablesProviderInterface;
19
20
/**
21
 * jQuery DataTables compiler pass.
22
 *
23
 * @author webeweb <https://github.com/webeweb/>
24
 * @package WBW\Bundle\JQuery\DataTablesBundle\DependencyInjection\Compiler
25
 */
26
class JQueryDataTablesCompilerPass implements CompilerPassInterface {
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process(ContainerBuilder $container) {
32
33
        // Check if the storage manager is defined.
34
        if (false === $container->has(DataTablesManager::SERVICE_NAME)) {
35
            return;
36
        }
37
38
        // Get the storage manager.
39
        $manager = $container->findDefinition(DataTablesManager::SERVICE_NAME);
40
41
        // Find all service IDs with DataTables provider tag.
42
        $providers = $container->findTaggedServiceIds(DataTablesProviderInterface::TAG_NAME);
43
44
        // Register each provider.
45
        foreach ($providers as $id => $tag) {
46
            $manager->addMethodCall("registerProvider", [new Reference($id)]);
47
        }
48
    }
49
50
}
51