1
|
|
|
<?php |
2
|
|
|
namespace midcom\bundle\dependencyInjection; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
5
|
|
|
use midcom_core_manifest; |
6
|
|
|
use midcom_error; |
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
8
|
|
|
use Symfony\Component\Finder\Finder; |
|
|
|
|
9
|
|
|
|
10
|
|
|
class componentPass implements CompilerPassInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private $watches = [ |
16
|
|
|
\MIDCOM_OPERATION_DBA_CREATE => [], |
17
|
|
|
\MIDCOM_OPERATION_DBA_UPDATE => [], |
18
|
|
|
\MIDCOM_OPERATION_DBA_DELETE => [], |
19
|
|
|
\MIDCOM_OPERATION_DBA_IMPORT => [] |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
private $classmap = []; |
23
|
|
|
|
24
|
1 |
|
public function process(ContainerBuilder $container) |
25
|
|
|
{ |
26
|
1 |
|
$paths = $this->find_builtin_components(); |
27
|
|
|
|
28
|
|
|
// now we look for extra components the user may have registered |
29
|
1 |
|
foreach ($container->getParameter('midcom.midcom_components') as $path) { |
30
|
1 |
|
if (!file_exists($path . '/config/manifest.inc')) { |
31
|
|
|
throw new midcom_error('No manifest found in path ' . $path); |
32
|
|
|
} |
33
|
1 |
|
$paths[] = $path . '/config/manifest.inc'; |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
$components = []; |
37
|
1 |
|
foreach ($paths as $path) { |
38
|
1 |
|
$manifest = new midcom_core_manifest($path); |
39
|
1 |
|
$components[$manifest->name] = $path; |
40
|
1 |
|
if ($manifest->watches !== null) { |
41
|
1 |
|
$this->add_watches($manifest->name, $manifest->watches); |
42
|
|
|
} |
43
|
|
|
|
44
|
1 |
|
$this->process_manifest($manifest, $container); |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
$cl = $container->getDefinition('componentloader'); |
48
|
1 |
|
$cl->addArgument($components); |
49
|
|
|
|
50
|
1 |
|
$watcher = $container->getDefinition('watcher'); |
51
|
1 |
|
$watcher->addArgument($this->watches); |
52
|
|
|
|
53
|
1 |
|
$dbclassloader = $container->getDefinition('dbclassloader'); |
54
|
1 |
|
$dbclassloader->addArgument($this->classmap); |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
private function find_builtin_components() : array |
58
|
|
|
{ |
59
|
1 |
|
$components = []; |
60
|
1 |
|
$finder = (new Finder()) |
61
|
1 |
|
->files() |
62
|
1 |
|
->in([MIDCOM_ROOT, dirname(MIDCOM_ROOT) . '/src']) |
63
|
1 |
|
->name('manifest.inc'); |
64
|
1 |
|
foreach ($finder as $file) { |
65
|
1 |
|
$components[] = $file->getPathname(); |
66
|
|
|
} |
67
|
1 |
|
return $components; |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
private function add_watches(string $component, array $watches) |
71
|
|
|
{ |
72
|
1 |
|
foreach ($watches as $watch) { |
73
|
1 |
|
foreach (array_keys($this->watches) as $operation_id) { |
74
|
|
|
// Check whether the operations flag list from the component |
75
|
|
|
// contains the operation_id we're checking a watch for. |
76
|
1 |
|
if ($watch['operations'] & $operation_id) { |
77
|
1 |
|
$this->watches[$operation_id][] = [ |
78
|
1 |
|
$component => $watch['classes'] |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Register manifest data. |
87
|
|
|
* |
88
|
|
|
* All default privileges are made known to ACL, the watches are registered |
89
|
|
|
*/ |
90
|
1 |
|
private function process_manifest(midcom_core_manifest $manifest, ContainerBuilder $container) |
91
|
|
|
{ |
92
|
|
|
// Register Privileges |
93
|
1 |
|
if ($manifest->privileges) { |
|
|
|
|
94
|
1 |
|
$acl = $container->getDefinition('auth.acl'); |
95
|
1 |
|
$acl->addMethodCall('register_default_privileges', [$manifest->privileges]); |
96
|
|
|
} |
97
|
1 |
|
$this->classmap[$manifest->name] = $manifest->class_mapping; |
98
|
1 |
|
if ($manifest->name == 'midcom') { |
99
|
1 |
|
$this->classmap['midcom'][$container->getParameter('midcom.person_class')] = \midcom_db_person::class; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths