1 | <?php |
||
21 | class Application |
||
22 | { |
||
23 | /** |
||
24 | * @var ContainerInterface |
||
25 | */ |
||
26 | protected $dependencyContainer; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $config; |
||
32 | |||
33 | 6 | public static function init(array $config) : Application |
|
34 | { |
||
35 | // Ensure the needed config entries exists |
||
36 | 6 | $config['events'] = $config['events'] ?? []; |
|
37 | 6 | $config['components'] = $config['components'] ?? []; |
|
38 | |||
39 | 6 | return new static($config); |
|
40 | } |
||
41 | |||
42 | 6 | public function __construct(array $config, ContainerInterface $dependencyContainer = null) |
|
43 | { |
||
44 | 6 | $this->initDependencyContainer($config, $dependencyContainer); |
|
45 | |||
46 | // register any events from the config |
||
47 | 6 | $this->registerEvents($config['events']); |
|
48 | |||
49 | // Load components |
||
50 | 6 | $this->loadComponents($config['components']); |
|
51 | |||
52 | // trigger app created event |
||
53 | 6 | $this->dependencyContainer |
|
54 | 6 | ->get('fuel.application.event') |
|
55 | 6 | ->emit(new AppStarted($this)); |
|
56 | 6 | } |
|
57 | |||
58 | 6 | public function setDependencyContainer(ContainerInterface $dependencyContainer) |
|
62 | |||
63 | 6 | public function getDependencyContainer() : ContainerInterface |
|
64 | { |
||
67 | |||
68 | public function run() |
||
82 | |||
83 | /** |
||
84 | * @param array $events |
||
85 | */ |
||
86 | 6 | protected function registerEvents(array $events) |
|
100 | |||
101 | /** |
||
102 | * @param string[] $components |
||
103 | */ |
||
104 | 6 | protected function loadComponents(array $components) |
|
115 | |||
116 | /** |
||
117 | * @param array $config |
||
118 | * @param ContainerInterface $dependencyContainer |
||
119 | */ |
||
120 | 6 | protected function initDependencyContainer(array $config, ContainerInterface $dependencyContainer = null) |
|
132 | |||
133 | } |
||
134 |