1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Event; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\EventDispatcher\Event; |
17
|
|
|
use Symfony\Component\HttpFoundation\Response; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class TemplateEvent |
21
|
|
|
*/ |
22
|
|
|
class TemplateEvent extends Event |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private $view; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $source; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private $parameters; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var null|Response |
41
|
|
|
*/ |
42
|
|
|
private $response; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
private $assets = []; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
private $snippets = []; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* TemplateEvent constructor. |
56
|
|
|
* |
57
|
|
|
* @param string $view |
|
|
|
|
58
|
|
|
* @param string $source |
|
|
|
|
59
|
|
|
* @param array $parameters |
|
|
|
|
60
|
|
|
* @param Response|null $response |
61
|
|
|
*/ |
62
|
274 |
|
public function __construct($view, $source, array $parameters = [], Response $response = null) |
63
|
|
|
{ |
64
|
274 |
|
$this->view = $view; |
65
|
274 |
|
$this->source = $source; |
66
|
274 |
|
$this->parameters = $parameters; |
67
|
274 |
|
$this->response = $response; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
1 |
|
public function getView() |
74
|
|
|
{ |
75
|
1 |
|
return $this->view; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $view |
80
|
|
|
*/ |
81
|
1 |
|
public function setView($view) |
82
|
|
|
{ |
83
|
1 |
|
$this->view = $view; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
271 |
|
public function getSource() |
90
|
|
|
{ |
91
|
271 |
|
return $this->source; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $source |
96
|
|
|
*/ |
97
|
1 |
|
public function setSource($source) |
98
|
|
|
{ |
99
|
1 |
|
$this->source = $source; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
|
|
|
|
103
|
|
|
* @param $key |
|
|
|
|
104
|
|
|
* |
105
|
|
|
* @return mixed |
106
|
|
|
*/ |
107
|
|
|
public function getParameter($key) |
108
|
|
|
{ |
109
|
|
|
return $this->parameters[$key]; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
|
|
|
|
113
|
|
|
* @param $key |
|
|
|
|
114
|
|
|
* @param $value |
|
|
|
|
115
|
|
|
*/ |
116
|
|
|
public function setParameter($key, $value) |
117
|
|
|
{ |
118
|
|
|
$this->parameters[$key] = $value; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
|
|
|
|
122
|
|
|
* @param $key |
|
|
|
|
123
|
|
|
* |
124
|
|
|
* @return bool |
125
|
|
|
*/ |
126
|
|
|
public function hasParameter($key) |
127
|
|
|
{ |
128
|
|
|
return isset($this->parameters[$key]); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return array |
133
|
|
|
*/ |
134
|
271 |
|
public function getParameters() |
135
|
|
|
{ |
136
|
271 |
|
return $this->parameters; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param array $parameters |
141
|
|
|
*/ |
142
|
1 |
|
public function setParameters($parameters) |
143
|
|
|
{ |
144
|
1 |
|
$this->parameters = $parameters; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return null|Response |
149
|
|
|
*/ |
150
|
1 |
|
public function getResponse() |
151
|
|
|
{ |
152
|
1 |
|
return $this->response; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param null|Response $response |
157
|
|
|
*/ |
158
|
1 |
|
public function setResponse($response) |
159
|
|
|
{ |
160
|
1 |
|
$this->response = $response; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
|
|
|
|
164
|
|
|
* アセットを追加する |
165
|
|
|
* |
166
|
|
|
* ここで追加したコードは, <head></head>内に出力される |
167
|
|
|
* javascriptの読み込みやcssの読み込みに利用する. |
168
|
|
|
* |
169
|
|
|
* @param $asset |
|
|
|
|
170
|
|
|
* @param bool $include twigファイルとしてincludeするかどうか |
|
|
|
|
171
|
|
|
* |
172
|
|
|
* @return $this |
173
|
|
|
*/ |
174
|
|
|
public function addAsset($asset, $include = true) |
175
|
|
|
{ |
176
|
|
|
$this->assets[$asset] = $include; |
177
|
|
|
|
178
|
|
|
$this->setParameter('plugin_assets', $this->assets); |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
|
|
|
|
184
|
|
|
* スニペットを追加する. |
185
|
|
|
* |
186
|
|
|
* ここで追加したコードは, </body>タグ直前に出力される |
187
|
|
|
* |
188
|
|
|
* @param $snippet |
|
|
|
|
189
|
|
|
* @param bool $include twigファイルとしてincludeするかどうか |
|
|
|
|
190
|
|
|
* |
191
|
|
|
* @return $this |
192
|
|
|
*/ |
193
|
|
|
public function addSnippet($snippet, $include = true) |
194
|
|
|
{ |
195
|
|
|
$this->snippets[$snippet] = $include; |
196
|
|
|
|
197
|
|
|
$this->setParameter('plugin_snippets', $this->snippets); |
198
|
|
|
|
199
|
|
|
return $this; |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|