Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
95.00% |
38 / 40 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
AppStartup | |
95.00% |
38 / 40 |
|
66.67% |
2 / 3 |
5 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setupCommon | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
2 | |||
setupWebService | |
86.67% |
13 / 15 |
|
0.00% |
0 / 1 |
2.01 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace PeServer\App\Models; |
6 | |
7 | use PeServer\App\Models\AppConfiguration; |
8 | use PeServer\App\Models\AppCryptography; |
9 | use PeServer\App\Models\AppDatabaseCache; |
10 | use PeServer\App\Models\AppDatabaseConnection; |
11 | use PeServer\App\Models\AppEmailInformation; |
12 | use PeServer\App\Models\AppErrorHandler; |
13 | use PeServer\App\Models\AppMailer; |
14 | use PeServer\App\Models\AppRouteSetting; |
15 | use PeServer\App\Models\AppRouting; |
16 | use PeServer\App\Models\AppTemplate; |
17 | use PeServer\App\Models\AppTemplateFactory; |
18 | use PeServer\App\Models\AppUrl; |
19 | use PeServer\App\Models\Domain\AccessLogManager; |
20 | use PeServer\App\Models\Domain\AppArchiver; |
21 | use PeServer\App\Models\Domain\AppEraser; |
22 | use PeServer\Core\Collection\Arr; |
23 | use PeServer\Core\ProgramContext; |
24 | use PeServer\Core\CoreStartup; |
25 | use PeServer\Core\Database\IDatabaseConnection; |
26 | use PeServer\Core\StartupOptions; |
27 | use PeServer\Core\DI\DiItem; |
28 | use PeServer\Core\DI\IDiRegisterContainer; |
29 | use PeServer\Core\Environment; |
30 | use PeServer\Core\Http\HttpMethod; |
31 | use PeServer\Core\Http\RequestPath; |
32 | use PeServer\Core\IO\Path; |
33 | use PeServer\Core\Log\ILogProvider; |
34 | use PeServer\Core\Mail\Mailer; |
35 | use PeServer\Core\Mvc\RouteRequest; |
36 | use PeServer\Core\Mvc\RouteSetting; |
37 | use PeServer\Core\Mvc\Routing; |
38 | use PeServer\Core\Mvc\Template\ITemplateFactory; |
39 | use PeServer\Core\Web\WebSecurity; |
40 | use PeServer\Core\Store\SpecialStore; |
41 | use PeServer\Core\Text; |
42 | use PeServer\Core\Web\UrlHelper; |
43 | |
44 | class AppStartup extends CoreStartup |
45 | { |
46 | /** |
47 | * 初期化。 |
48 | * |
49 | * @param StartupOptions $startupOptions |
50 | */ |
51 | public function __construct( |
52 | StartupOptions $startupOptions, |
53 | ) { |
54 | parent::__construct($startupOptions); |
55 | } |
56 | |
57 | #region CoreStartup |
58 | |
59 | protected function setupCommon(array $options, IDiRegisterContainer $container): void |
60 | { |
61 | parent::setupCommon($options, $container); |
62 | |
63 | /** @var ILogProvider */ |
64 | $logProvider = $container->get(ILogProvider::class); |
65 | |
66 | $appConfig = new AppConfiguration( |
67 | $container->get(ProgramContext::class), |
68 | $options['url_helper'] ?? new UrlHelper(''), |
69 | $container->get(WebSecurity::class), |
70 | $options['special_store'] ?? new SpecialStore(), |
71 | $container->get(Environment::class) |
72 | ); |
73 | $container->registerValue($appConfig); |
74 | |
75 | $logging = $appConfig->setting->logging; |
76 | foreach ($logging->loggers as $name => $value) { |
77 | $logProvider->add($name, $value->loggerClass, $value->level, $value->format, $value->configuration); |
78 | } |
79 | |
80 | $container->registerMapping(ITemplateFactory::class, AppTemplateFactory::class); |
81 | $container->registerMapping(IDatabaseConnection::class, AppDatabaseConnection::class); |
82 | $container->registerClass(AppCryptography::class); |
83 | $container->registerClass(AppDatabaseCache::class); |
84 | $container->registerMapping(Mailer::class, AppMailer::class); |
85 | $container->registerClass(AppTemplate::class); |
86 | $container->registerClass(AppArchiver::class); |
87 | $container->registerClass(AppEraser::class); |
88 | $container->registerClass(AppEmailInformation::class); |
89 | $container->registerClass(AppUrl::class); |
90 | $container->registerClass(AccessLogManager::class); |
91 | } |
92 | |
93 | protected function setupWebService(array $options, IDiRegisterContainer $container): void |
94 | { |
95 | parent::setupWebService($options, $container); |
96 | |
97 | /** @var AppConfiguration */ |
98 | $appConfig = $container->get(AppConfiguration::class); |
99 | $container->registerValue($appConfig->stores); |
100 | |
101 | /** @var SpecialStore */ |
102 | $specialStore = $container->get(SpecialStore::class); |
103 | |
104 | $method = HttpMethod::from(Text::toUpper(Text::trim($specialStore->getServer('REQUEST_METHOD')))); |
105 | $requestPath = new RequestPath( |
106 | $specialStore->getServer('REQUEST_URI'), |
107 | $options['url_helper'] ?? new UrlHelper('') |
108 | ); |
109 | $container->registerValue(new RouteRequest($method, $requestPath)); |
110 | |
111 | $container->add(RouteSetting::class, DiItem::value($container->new(AppRouteSetting::class))); |
112 | $container->registerMapping(Routing::class, AppRouting::class); |
113 | |
114 | if ($this->startupOptions->errorHandling) { |
115 | /** @var AppErrorHandler */ |
116 | $appErrorHandler = $container->new(AppErrorHandler::class, [RequestPath::class => $requestPath]); |
117 | $appErrorHandler->register(); |
118 | } |
119 | } |
120 | |
121 | #endregion |
122 | } |