Test Failed
Push — master ( 350674...c78563 )
by Andreas
22:08
created

componentPass::process_manifest()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 4
nop 2
dl 0
loc 11
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
    public function __construct(midcom_config $config)
18
    {
19
        $this->config = $config;
20
    }
21
22
    public function process(ContainerBuilder $container)
23
    {
24
        $components = [];
25
        foreach ($this->config->get('builtin_components', []) as $path) {
26
            $path = dirname(MIDCOM_ROOT) . '/' . $path . '/config/manifest.inc';
27
            $manifest = new midcom_core_manifest($path);
28
            $components[$manifest->name] = $path;
29
            $this->process_manifest($manifest, $container);
30
        }
31
32
        // now we look for extra components the user may have registered
33
        foreach ($this->config->get('midcom_components', []) as $path) {
34
            if (!file_exists($path . '/config/manifest.inc')) {
35
                throw new midcom_error('No manifest found in path ' . $path);
36
            }
37
            $path .= '/config/manifest.inc';
38
            $components[$manifest->name] = $path;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $manifest seems to be defined by a foreach iteration on line 25. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
39
            $this->process_manifest(new midcom_core_manifest($path), $container);
40
        }
41
        $cl = $container->getDefinition('componentloader');
42
        $cl->addArgument($components);
43
    }
44
45
    /**
46
     * Register manifest data.
47
     *
48
     * All default privileges are made known to ACL, the watches are registered
49
     */
50
    private function process_manifest(midcom_core_manifest $manifest, ContainerBuilder $container)
51
    {
52
        // Register Privileges
53
        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...
54
            $acl = $container->getDefinition('auth.acl');
55
            $acl->addMethodCall('register_default_privileges', [$manifest->privileges]);
56
        }
57
        // Register watches
58
        if ($manifest->watches !== null) {
59
            $dispatcher = $container->getDefinition('event_dispatcher');
60
            $dispatcher->addMethodCall('add_watches', [$manifest->watches, $manifest->name]);
61
        }
62
    }
63
}