1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Phoundation package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Nikola Posa |
6
|
|
|
* |
7
|
|
|
* For full copyright and license information, please refer to the LICENSE file, |
8
|
|
|
* located at the package root folder. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace Phoundation\Bootstrap; |
14
|
|
|
|
15
|
|
|
use Phoundation\Config\Loader\ConfigLoaderInterface; |
16
|
|
|
use Phoundation\Di\Container\Factory\DiContainerFactoryInterface; |
17
|
|
|
use Phoundation\Config\Config; |
18
|
|
|
use Psr\Container\ContainerInterface; |
19
|
|
|
use Phoundation\ErrorHandling\RunnerInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Nikola Posa <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Bootstrap |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ConfigLoaderInterface |
28
|
|
|
*/ |
29
|
|
|
protected $configLoader; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var DiContainerFactoryInterface |
33
|
|
|
*/ |
34
|
|
|
protected $diContainerFactory; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Config |
38
|
|
|
*/ |
39
|
|
|
protected $config; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var ContainerInterface |
43
|
|
|
*/ |
44
|
|
|
protected $diContainer; |
45
|
|
|
|
46
|
4 |
|
public function __construct(ConfigLoaderInterface $configLoader, DiContainerFactoryInterface $diContainerFactory) |
47
|
|
|
{ |
48
|
4 |
|
$this->configLoader = $configLoader; |
49
|
4 |
|
$this->diContainerFactory = $diContainerFactory; |
50
|
4 |
|
} |
51
|
|
|
|
52
|
4 |
|
public function __invoke() |
53
|
|
|
{ |
54
|
4 |
|
$this->loadConfig(); |
55
|
4 |
|
$this->buildDiContainer(); |
56
|
|
|
|
57
|
4 |
|
$this->setPhpSettings(); |
58
|
4 |
|
$this->registerErrorHandler(); |
59
|
|
|
|
60
|
4 |
|
return $this->diContainer; |
61
|
|
|
} |
62
|
|
|
|
63
|
4 |
|
protected function loadConfig() |
64
|
|
|
{ |
65
|
4 |
|
$configLoader = $this->configLoader; |
66
|
4 |
|
$this->config = $configLoader(); |
67
|
4 |
|
} |
68
|
|
|
|
69
|
4 |
|
protected function buildDiContainer() |
70
|
|
|
{ |
71
|
4 |
|
$diContainerFactory = $this->diContainerFactory; |
72
|
|
|
|
73
|
4 |
|
$this->diContainer = $diContainerFactory($this->config); |
74
|
4 |
|
} |
75
|
|
|
|
76
|
4 |
|
protected function setPhpSettings() |
77
|
|
|
{ |
78
|
4 |
|
$phpSettings = (array) ($this->config['php_settings'] ?? []); |
79
|
|
|
|
80
|
4 |
|
foreach ($phpSettings as $key => $value) { |
81
|
1 |
|
ini_set($key, $value); |
82
|
|
|
} |
83
|
4 |
|
} |
84
|
|
|
|
85
|
4 |
|
protected function registerErrorHandler() |
86
|
|
|
{ |
87
|
4 |
|
if (!$this->diContainer->has(RunnerInterface::class)) { |
88
|
3 |
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
$this->diContainer->get(RunnerInterface::class)->register(); |
92
|
1 |
|
} |
93
|
|
|
} |
94
|
|
|
|