Passed
Push — master ( e31e38...b36f9b )
by Andreas
16:51
created

componentPass::process_manifest()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 4
nop 2
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 10
c 1
b 0
f 0
1
<?php
2
namespace midcom\dependencyInjection;
3
4
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use midcom_config;
7
use midcom_core_manifest;
8
use midcom_error;
9
10
class componentPass implements CompilerPassInterface
11
{
12
    /**
13
     * @var midcom_config
14
     */
15
    private $config;
16
17 1
    public function __construct(midcom_config $config)
18
    {
19 1
        $this->config = $config;
20 1
    }
21
22 1
    public function process(ContainerBuilder $container)
23
    {
24 1
        $components = [];
25 1
        foreach ($this->config->get('builtin_components', []) as $path) {
26 1
            $path = dirname(MIDCOM_ROOT) . '/' . $path . '/config/manifest.inc';
27 1
            $manifest = new midcom_core_manifest($path);
28 1
            $components[$manifest->name] = $path;
29 1
            $this->process_manifest($manifest, $container);
30
        }
31
32
        // now we look for extra components the user may have registered
33 1
        foreach ($this->config->get('midcom_components', []) as $path) {
34 1
            if (!file_exists($path . '/config/manifest.inc')) {
35
                throw new midcom_error('No manifest found in path ' . $path);
36
            }
37 1
            $path .= '/config/manifest.inc';
38 1
            $manifest = new midcom_core_manifest($path);
39 1
            $components[$manifest->name] = $path;
40 1
            $this->process_manifest($manifest, $container);
41
        }
42 1
        $cl = $container->getDefinition('componentloader');
43 1
        $cl->addArgument($components);
44 1
    }
45
46
    /**
47
     * Register manifest data.
48
     *
49
     * All default privileges are made known to ACL, the watches are registered
50
     */
51 1
    private function process_manifest(midcom_core_manifest $manifest, ContainerBuilder $container)
52
    {
53
        // Register Privileges
54 1
        if ($manifest->privileges) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $manifest->privileges of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
55 1
            $acl = $container->getDefinition('auth.acl');
56 1
            $acl->addMethodCall('register_default_privileges', [$manifest->privileges]);
57
        }
58
        // Register watches
59 1
        if ($manifest->watches !== null) {
60 1
            $dispatcher = $container->getDefinition('event_dispatcher');
61 1
            $dispatcher->addMethodCall('add_watches', [$manifest->watches, $manifest->name]);
62
        }
63
    }
64
}