1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Minotaur |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
7
|
|
|
* use this file except in compliance with the License. You may obtain a copy of |
8
|
|
|
* the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations under |
16
|
|
|
* the License. |
17
|
|
|
* |
18
|
|
|
* @copyright 2015-2017 Appertly |
19
|
|
|
* @license Apache-2.0 |
20
|
|
|
*/ |
21
|
|
|
namespace Minotaur; |
22
|
|
|
|
23
|
|
|
use Caridea\Container\Properties; |
24
|
|
|
use Caridea\Container\Objects; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* A bootstrapper that reads configuration and creates backend and frontend containers. |
28
|
|
|
* |
29
|
|
|
* This class expects a `Traversable` full of class names in the |
30
|
|
|
* `system.modules` configuration setting. Each class name *must* extend |
31
|
|
|
* `Minotaur\Module` or an `UnexpectedValueException` will be thrown. |
32
|
|
|
*/ |
33
|
|
|
class System extends Configuration |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var Objects The backend container |
37
|
|
|
*/ |
38
|
|
|
protected $backend; |
39
|
|
|
/** |
40
|
|
|
* @var Objects The frontend container |
41
|
|
|
*/ |
42
|
|
|
protected $frontend; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Creates a new System. |
46
|
|
|
* |
47
|
|
|
* This constructor expects a `Traversable` full of class names in the |
48
|
|
|
* `system.modules` configuration setting. Each class name *must* extend |
49
|
|
|
* `Minotaur\Module` or an `UnexpectedValueException` will be thrown. |
50
|
|
|
* |
51
|
|
|
* @param array<string,mixed> $config The system configuration |
52
|
|
|
* @throws \UnexpectedValueException if a module class doesn't extend `Minotaur\Module` |
53
|
|
|
*/ |
54
|
|
|
public function __construct(array $config) |
55
|
|
|
{ |
56
|
|
|
parent::__construct($config); |
57
|
|
|
$this->backend = $this->createBackendContainer($this->config); |
58
|
|
|
$this->frontend = $this->createFrontendContainer($this->backend); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private function createBackendContainer(Properties $parent): Objects |
62
|
|
|
{ |
63
|
|
|
$builder = Objects::builder(); |
64
|
|
|
foreach ($this->modules as $module) { |
65
|
|
|
$module->setupBackend($builder, $parent); |
66
|
|
|
} |
67
|
|
|
return $builder->build($parent); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
private function createFrontendContainer(Objects $parent): Objects |
71
|
|
|
{ |
72
|
|
|
$builder = Objects::builder(); |
73
|
|
|
foreach ($this->modules as $module) { |
74
|
|
|
$module->setupFrontend($builder, $this->config); |
75
|
|
|
} |
76
|
|
|
return $builder->build($parent); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Gets the container with backend classes. |
81
|
|
|
* |
82
|
|
|
* @return - The backend container |
|
|
|
|
83
|
|
|
*/ |
84
|
|
|
public function getBackendContainer(): Objects |
85
|
|
|
{ |
86
|
|
|
return $this->backend; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Gets the container with frontend classes. |
91
|
|
|
* |
92
|
|
|
* @return - The frontend container |
|
|
|
|
93
|
|
|
*/ |
94
|
|
|
public function getFrontendContainer(): Objects |
95
|
|
|
{ |
96
|
|
|
return $this->frontend; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.