Completed
Push — master ( 583713...989906 )
by WEBEWEB
05:28
created

JQueryDataTablesCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
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
 * @final
26
 */
27
final class JQueryDataTablesCompilerPass implements CompilerPassInterface {
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function process(ContainerBuilder $container) {
33
34
        // Check if the storage manager is defined.
35
        if (false === $container->has(DataTablesManager::SERVICE_NAME)) {
36
            return;
37
        }
38
39
        // Get the storage manager.
40
        $manager = $container->findDefinition(DataTablesManager::SERVICE_NAME);
41
42
        // Find all service IDs with DataTables provider tag.
43
        $providers = $container->findTaggedServiceIds(DataTablesProviderInterface::TAG_NAME);
44
45
        // Register each provider.
46
        foreach ($providers as $id => $tag) {
47
            $manager->addMethodCall("registerProvider", [new Reference($id)]);
48
        }
49
    }
50
51
}
52