Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
AppTemplate | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
buildTemplate | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
createMailTemplate | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 |
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\AppTemplateOptions; |
9 | use PeServer\Core\Http\HttpStatus; |
10 | use PeServer\Core\Mvc\Template\ITemplateFactory; |
11 | use PeServer\Core\Mvc\Template\TemplateParameter; |
12 | use PeServer\Core\ProgramContext; |
13 | use PeServer\Core\Web\UrlHelper; |
14 | use PeServer\Core\Web\WebSecurity; |
15 | |
16 | /** |
17 | * アプリ用汎用テンプレート処理。 |
18 | */ |
19 | final class AppTemplate |
20 | { |
21 | public function __construct( |
22 | private ProgramContext $programContext, |
23 | private AppConfiguration $config, |
24 | private ITemplateFactory $templateFactory, |
25 | private WebSecurity $webSecurity, |
26 | ) { |
27 | } |
28 | |
29 | #region function |
30 | |
31 | /** |
32 | * テンプレートを適用。 |
33 | * |
34 | * @param string $baseName |
35 | * @param string $templateName |
36 | * @param array<string,mixed> $params |
37 | * @return string |
38 | */ |
39 | private function buildTemplate(string $baseName, string $templateName, array $params, HttpStatus $status): string |
40 | { |
41 | $template = $this->templateFactory->createTemplate(new AppTemplateOptions('template' . DIRECTORY_SEPARATOR . $baseName, $this->programContext, new UrlHelper(''), $this->webSecurity)); |
42 | $result = $template->build($templateName . '.tpl', new TemplateParameter($status, $params, [])); |
43 | |
44 | return $result; |
45 | } |
46 | |
47 | /** |
48 | * メール用テンプレートの作成。 |
49 | * |
50 | * @param string $templateName |
51 | * @param string $subject |
52 | * @param array<string,mixed> $params |
53 | * @return string |
54 | */ |
55 | public function createMailTemplate(string $templateName, string $subject, array $params): string |
56 | { |
57 | $families = $this->config->setting->config->address->families; |
58 | |
59 | $params['app'] = [ |
60 | 'subject' => $subject, |
61 | 'server_url' => $families->serverUrl, |
62 | 'contact_url' => $families->contactUrl, |
63 | 'app_project_url' => $families->appProjectUrl, |
64 | 'server_project_url' => $families->serverProjectUrl, |
65 | 'forum_url' => $families->forumUrl, |
66 | 'website_url' => $families->websiteUrl, |
67 | ]; |
68 | |
69 | return $this->buildTemplate('email', $templateName, $params, HttpStatus::None); |
70 | } |
71 | |
72 | #endregion |
73 | } |