|
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; |
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
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
|
|
|
} |