1 | <?php |
||
16 | class ApplicationTrait extends \Silex\Application |
||
17 | { |
||
18 | /** |
||
19 | * Application Shortcut Methods |
||
20 | */ |
||
21 | 19 | public function addSuccess($message, $namespace = 'front') |
|
25 | |||
26 | 2 | public function addError($message, $namespace = 'front') |
|
30 | |||
31 | public function addDanger($message, $namespace = 'front') |
||
35 | |||
36 | 1 | public function addWarning($message, $namespace = 'front') |
|
40 | |||
41 | public function addInfo($message, $namespace = 'front') |
||
45 | |||
46 | public function addRequestError($message, $namespace = 'front') |
||
50 | |||
51 | public function clearMessage() |
||
55 | |||
56 | public function deleteMessage() |
||
61 | |||
62 | public function setLoginTargetPath($targetPath) |
||
66 | |||
67 | public function isAdminRequest() |
||
71 | |||
72 | public function isFrontRequest() |
||
76 | |||
77 | /* |
||
78 | * 注意!以下コードはSilexのコードのコピーなので触らないコト |
||
79 | * |
||
80 | * 以下のコードの著作権について |
||
81 | * |
||
82 | * (c) Fabien Potencier <[email protected]> |
||
83 | * |
||
84 | * For the full copyright and license information, please view the silex |
||
85 | * LICENSE file that was distributed with this source code. |
||
86 | */ |
||
87 | |||
88 | /** FormTrait */ |
||
89 | /** |
||
90 | * Creates and returns a form builder instance |
||
91 | * |
||
92 | * @param mixed $data The initial data for the form |
||
93 | * @param array $options Options for the form |
||
94 | * |
||
95 | * @return FormBuilder |
||
96 | */ |
||
97 | public function form($data = null, array $options = array()) |
||
101 | |||
102 | /** MonologTrait */ |
||
103 | /** |
||
104 | * Adds a log record. |
||
105 | * |
||
106 | * @param string $message The log message |
||
107 | * @param array $context The log context |
||
108 | * @param int $level The logging level |
||
109 | * |
||
110 | * @return bool Whether the record has been processed |
||
111 | */ |
||
112 | 8 | public function log($message, array $context = array(), $level = Logger::INFO) |
|
116 | |||
117 | /** SecurityTrait */ |
||
118 | /** |
||
119 | * Gets a user from the Security context. |
||
120 | * |
||
121 | * @return mixed |
||
122 | * |
||
123 | * @see TokenInterface::getUser() |
||
124 | * |
||
125 | */ |
||
126 | public function user() |
||
130 | |||
131 | /** |
||
132 | * Encodes the raw password. |
||
133 | * |
||
134 | * @param UserInterface $user A UserInterface instance |
||
135 | * @param string $password The password to encode |
||
136 | * |
||
137 | * @return string The encoded password |
||
138 | * |
||
139 | * @throws \RuntimeException when no password encoder could be found for the user |
||
140 | */ |
||
141 | 1 | public function encodePassword(UserInterface $user, $password) |
|
145 | |||
146 | /** |
||
147 | * Checks if the attributes are granted against the current authentication token and optionally supplied object. |
||
148 | * |
||
149 | * @param mixed $attributes |
||
150 | * @param mixed $object |
||
151 | * |
||
152 | * @return bool |
||
153 | * |
||
154 | * @throws AuthenticationCredentialsNotFoundException when the token storage has no authentication token. |
||
155 | */ |
||
156 | 23 | public function isGranted($attributes, $object = null) |
|
160 | |||
161 | /** SwiftmailerTrait */ |
||
162 | /** |
||
163 | * Sends an email. |
||
164 | * |
||
165 | * @param \Swift_Message $message A \Swift_Message instance |
||
166 | * @param array $failedRecipients An array of failures by-reference |
||
167 | * |
||
168 | * @return int The number of sent messages |
||
169 | */ |
||
170 | 21 | public function mail(\Swift_Message $message, &$failedRecipients = null) |
|
174 | |||
175 | /** TranslationTrait */ |
||
176 | /** |
||
177 | * Translates the given message. |
||
178 | * |
||
179 | * @param string $id The message id |
||
180 | * @param array $parameters An array of parameters for the message |
||
181 | * @param string $domain The domain for the message |
||
182 | * @param string $locale The locale |
||
183 | * |
||
184 | * @return string The translated string |
||
185 | */ |
||
186 | public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null) |
||
190 | |||
191 | /** |
||
192 | * Translates the given choice message by choosing a translation according to a number. |
||
193 | * |
||
194 | * @param string $id The message id |
||
195 | * @param int $number The number to use to find the indice of the message |
||
196 | * @param array $parameters An array of parameters for the message |
||
197 | * @param string $domain The domain for the message |
||
198 | * @param string $locale The locale |
||
199 | * |
||
200 | * @return string The translated string |
||
201 | */ |
||
202 | public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null) |
||
206 | |||
207 | /** TwigTrait */ |
||
208 | /** |
||
209 | * Renders a view and returns a Response. |
||
210 | * |
||
211 | * To stream a view, pass an instance of StreamedResponse as a third argument. |
||
212 | * |
||
213 | * @param string $view The view name |
||
214 | * @param array $parameters An array of parameters to pass to the view |
||
215 | * @param Response $response A Response instance |
||
216 | * |
||
217 | * @return Response A Response instance |
||
218 | */ |
||
219 | 63 | public function render($view, array $parameters = array(), Response $response = null) |
|
220 | { |
||
221 | $twig = $this['twig']; |
||
222 | |||
223 | // twigファイルのソースコードを読み込み, 文字列化. |
||
224 | $source = $twig->getLoader()->getSource($view); |
||
225 | |||
226 | // イベントの実行. |
||
227 | // プラグインにはテンプレートファイル名、文字列化されたtwigファイル、パラメータを渡す |
||
228 | $event = new TemplateEvent($view, $source, $parameters, $response); |
||
229 | |||
230 | 63 | $eventName = $view; |
|
231 | if ($this->isAdminRequest()) { |
||
232 | // 管理画面の場合、event名に「admin.」を付ける |
||
233 | 60 | $eventName = 'admin.' . $view; |
|
234 | } |
||
235 | $this['monolog']->debug('Template Event Name : ' . $eventName); |
||
236 | |||
237 | $this['eccube.event.dispatcher']->dispatch($eventName, $event); |
||
238 | |||
239 | 63 | if ($response instanceof StreamedResponse) { |
|
240 | $response->setCallback(function () use ($twig, $view, $parameters) { |
||
241 | $twig->display($view, $parameters); |
||
242 | }); |
||
243 | } else { |
||
244 | 62 | if (null === $response) { |
|
245 | $response = new Response(); |
||
246 | } |
||
247 | |||
248 | // プラグインで変更された文字列から, テンプレートオブジェクトを生成 |
||
249 | $template = $twig->createTemplate($event->getSource()); |
||
250 | |||
251 | // レンダリング実行. |
||
252 | $content = $template->render($event->getParameters()); |
||
253 | $response->setContent($content); |
||
254 | 1 | } |
|
255 | |||
256 | 63 | return $response; |
|
257 | 60 | } |
|
258 | |||
259 | /** |
||
260 | * Renders a view. |
||
261 | * |
||
262 | * @param string $view The view name |
||
263 | * @param array $parameters An array of parameters to pass to the view |
||
264 | * |
||
265 | * @return string The rendered view |
||
266 | */ |
||
267 | 20 | public function renderView($view, array $parameters = array()) |
|
271 | |||
272 | /** UrlGeneratorTrait */ |
||
273 | /** |
||
274 | * Generates a path from the given parameters. |
||
275 | * |
||
276 | * @param string $route The name of the route |
||
277 | * @param mixed $parameters An array of parameters |
||
278 | * |
||
279 | * @return string The generated path |
||
280 | */ |
||
281 | 42 | public function path($route, $parameters = array()) |
|
285 | |||
286 | /** |
||
287 | * Generates an absolute URL from the given parameters. |
||
288 | * |
||
289 | * @param string $route The name of the route |
||
290 | * @param mixed $parameters An array of parameters |
||
291 | * |
||
292 | * @return string The generated URL |
||
293 | */ |
||
294 | 55 | public function url($route, $parameters = array()) |
|
298 | } |
||
299 |