|
1
|
|
|
<?php |
|
2
|
|
|
namespace WebStream\Core; |
|
3
|
|
|
|
|
4
|
|
|
use WebStream\Annotation\Attributes\Filter; |
|
5
|
|
|
use WebStream\Annotation\Base\IAnnotatable; |
|
6
|
|
|
use WebStream\Container\Container; |
|
7
|
|
|
use WebStream\DI\Injector; |
|
8
|
|
|
use WebStream\Template\ITemplateEngine; |
|
9
|
|
|
use WebStream\Util\CommonUtils; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* CoreViewクラス |
|
13
|
|
|
* @author Ryuichi TANAKA. |
|
14
|
|
|
* @since 2011/09/12 |
|
15
|
|
|
* @version 0.7 |
|
16
|
|
|
*/ |
|
17
|
|
|
class CoreView implements CoreInterface, IAnnotatable |
|
18
|
|
|
{ |
|
19
|
|
|
use Injector, CommonUtils; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Container 依存コンテナ |
|
23
|
|
|
*/ |
|
24
|
|
|
private $container; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ITemplateEngine テンプレートエンジン |
|
28
|
|
|
*/ |
|
29
|
|
|
private $templateEngine; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var LoggerAdapter ロガー |
|
|
|
|
|
|
33
|
|
|
*/ |
|
34
|
|
|
private $logger; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __destruct() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->logger->debug("View end."); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
* @Filter(type="initialize") |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __initialize(Container $container) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->container = $container; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __customAnnotation(array $annotation) |
|
57
|
|
|
{ |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* テンプレートエンジンを設定する |
|
62
|
|
|
* @param ITemplateEngine テンプレートエンジン |
|
63
|
|
|
*/ |
|
|
|
|
|
|
64
|
|
|
public function setTemplateEngine(ITemplateEngine $templateEngine = null) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->templateEngine = $templateEngine; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* テンプレートを描画する |
|
71
|
|
|
* @param array<string> パラメータ |
|
72
|
|
|
*/ |
|
|
|
|
|
|
73
|
|
|
public function draw(array $params) |
|
74
|
|
|
{ |
|
75
|
|
|
$mimeType = $params["mimeType"]; |
|
76
|
|
|
$this->outputHeader($mimeType); |
|
77
|
|
|
|
|
78
|
|
|
// HTML,XML以外はテンプレートを使用しない |
|
79
|
|
|
if ($mimeType !== 'html' && $mimeType !== 'xml') { |
|
80
|
|
|
$this->logger->debug("Only html or xml draw view template."); |
|
81
|
|
|
|
|
82
|
|
|
return; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if ($this->templateEngine !== null) { |
|
86
|
|
|
$this->templateEngine->render($params); |
|
87
|
|
|
if ($this->templateEngine instanceof \WebStream\Template\Basic) { |
|
88
|
|
|
$this->templateEngine->renderHelper($params); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* テンプレートキャッシュを作成する |
|
95
|
|
|
* @param string テンプレートファイルパス |
|
96
|
|
|
* @param string 保存データ |
|
97
|
|
|
* @param integer 有効期限 |
|
98
|
|
|
*/ |
|
|
|
|
|
|
99
|
|
|
public function templateCache($filepath, $cacheData, $cacheTime) |
|
100
|
|
|
{ |
|
101
|
|
|
if ($this->templateEngine instanceof \WebStream\Template\Basic) { |
|
102
|
|
|
$this->templateEngine->cache($filepath, $cacheData, $cacheTime); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* 共通ヘッダを出力する |
|
108
|
|
|
* @param String ファイルタイプ |
|
109
|
|
|
*/ |
|
|
|
|
|
|
110
|
|
|
private function outputHeader($type) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->container->response->setType($type); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* publicディレクトリにある静的ファイルを表示する |
|
117
|
|
|
* @param String ファイルパス |
|
118
|
|
|
*/ |
|
|
|
|
|
|
119
|
|
|
final public function __file($filepath) |
|
120
|
|
|
{ |
|
121
|
|
|
$publicDir = $this->container->applicationInfo->publicDir; |
|
|
|
|
|
|
122
|
|
|
if (preg_match('/\/views\/' . $publicDir . '\/img\/.+\.(?:jp(?:e|)g|png|bmp|(?:tif|gi)f)$/i', $filepath) || |
|
123
|
|
|
preg_match('/\/views\/' . $publicDir . '\/css\/.+\.css$/i', $filepath) || |
|
124
|
|
|
preg_match('/\/views\/' . $publicDir . '\/js\/.+\.js$/i', $filepath)) { // 画像,css,jsの場合 |
|
125
|
|
|
$this->display($filepath); |
|
126
|
|
|
} elseif (preg_match('/\/views\/' . $publicDir . '\/file\/.+$/i', $filepath)) { // それ以外のファイル |
|
127
|
|
|
$this->download($filepath); |
|
128
|
|
|
} else { // 全てのファイル |
|
129
|
|
|
$this->display($filepath); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* 画像、CSS、JavaScriptファイルを表示する |
|
135
|
|
|
* @param string ファイルパス |
|
136
|
|
|
*/ |
|
|
|
|
|
|
137
|
|
|
final private function display($filename) |
|
138
|
|
|
{ |
|
139
|
|
|
$this->container->response->displayFile($filename); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* ファイルをダウンロードする |
|
144
|
|
|
* @param string ファイルパス |
|
145
|
|
|
*/ |
|
|
|
|
|
|
146
|
|
|
final private function download($filename) |
|
147
|
|
|
{ |
|
148
|
|
|
$userAgent = $this->container->request->userAgent(); |
|
|
|
|
|
|
149
|
|
|
$this->container->response->downloadFile($filename, $userAgent); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths