1 | <?php |
||
15 | class ApplicationTrait extends \Silex\Application |
||
16 | { |
||
17 | /** |
||
18 | * Application Shortcut Methods |
||
19 | */ |
||
20 | 9 | public function addSuccess($message, $namespace = 'front') |
|
24 | |||
25 | 2 | public function addError($message, $namespace = 'front') |
|
29 | |||
30 | public function addDanger($message, $namespace = 'front') |
||
34 | |||
35 | 1 | public function addWarning($message, $namespace = 'front') |
|
39 | |||
40 | public function addInfo($message, $namespace = 'front') |
||
44 | |||
45 | public function addRequestError($message, $namespace = 'front') |
||
49 | |||
50 | public function clearMessage() |
||
54 | |||
55 | public function deleteMessage() |
||
56 | { |
||
57 | $this->clearMessage(); |
||
58 | $this->addWarning('admin.delete.warning', 'admin'); |
||
59 | } |
||
60 | |||
61 | public function setLoginTargetPath($targetPath) |
||
62 | { |
||
63 | $this['session']->getFlashBag()->set('eccube.login.target.path', $targetPath); |
||
64 | } |
||
65 | |||
66 | /* |
||
67 | * 注意!以下コードはSilexのコードのコピーなので触らないコト |
||
68 | * |
||
69 | * 以下のコードの著作権について |
||
70 | * |
||
71 | * (c) Fabien Potencier <[email protected]> |
||
72 | * |
||
73 | * For the full copyright and license information, please view the silex |
||
74 | * LICENSE file that was distributed with this source code. |
||
75 | */ |
||
76 | |||
77 | /** FormTrait */ |
||
78 | /** |
||
79 | * Creates and returns a form builder instance |
||
80 | * |
||
81 | * @param mixed $data The initial data for the form |
||
82 | * @param array $options Options for the form |
||
83 | * |
||
84 | * @return FormBuilder |
||
85 | */ |
||
86 | public function form($data = null, array $options = array()) |
||
90 | |||
91 | /** MonologTrait */ |
||
92 | /** |
||
93 | * Adds a log record. |
||
94 | * |
||
95 | * @param string $message The log message |
||
96 | * @param array $context The log context |
||
97 | * @param int $level The logging level |
||
98 | * |
||
99 | * @return bool Whether the record has been processed |
||
100 | */ |
||
101 | 8 | public function log($message, array $context = array(), $level = Logger::INFO) |
|
105 | |||
106 | /** SecurityTrait */ |
||
107 | /** |
||
108 | * Gets a user from the Security context. |
||
109 | * |
||
110 | * @return mixed |
||
111 | * |
||
112 | * @see TokenInterface::getUser() |
||
113 | * |
||
114 | */ |
||
115 | public function user() |
||
119 | |||
120 | /** |
||
121 | * Encodes the raw password. |
||
122 | * |
||
123 | * @param UserInterface $user A UserInterface instance |
||
124 | * @param string $password The password to encode |
||
125 | * |
||
126 | * @return string The encoded password |
||
127 | * |
||
128 | * @throws \RuntimeException when no password encoder could be found for the user |
||
129 | */ |
||
130 | 1 | public function encodePassword(UserInterface $user, $password) |
|
134 | |||
135 | /** |
||
136 | * Checks if the attributes are granted against the current authentication token and optionally supplied object. |
||
137 | * |
||
138 | * @param mixed $attributes |
||
139 | * @param mixed $object |
||
140 | * |
||
141 | * @return bool |
||
142 | * |
||
143 | * @throws AuthenticationCredentialsNotFoundException when the token storage has no authentication token. |
||
144 | */ |
||
145 | 16 | public function isGranted($attributes, $object = null) |
|
149 | |||
150 | /** SwiftmailerTrait */ |
||
151 | /** |
||
152 | * Sends an email. |
||
153 | * |
||
154 | * @param \Swift_Message $message A \Swift_Message instance |
||
155 | * @param array $failedRecipients An array of failures by-reference |
||
156 | * |
||
157 | * @return int The number of sent messages |
||
158 | */ |
||
159 | 21 | public function mail(\Swift_Message $message, &$failedRecipients = null) |
|
163 | |||
164 | /** TranslationTrait */ |
||
165 | /** |
||
166 | * Translates the given message. |
||
167 | * |
||
168 | * @param string $id The message id |
||
169 | * @param array $parameters An array of parameters for the message |
||
170 | * @param string $domain The domain for the message |
||
171 | * @param string $locale The locale |
||
172 | * |
||
173 | * @return string The translated string |
||
174 | */ |
||
175 | public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null) |
||
179 | |||
180 | /** |
||
181 | * Translates the given choice message by choosing a translation according to a number. |
||
182 | * |
||
183 | * @param string $id The message id |
||
184 | * @param int $number The number to use to find the indice of the message |
||
185 | * @param array $parameters An array of parameters for the message |
||
186 | * @param string $domain The domain for the message |
||
187 | * @param string $locale The locale |
||
188 | * |
||
189 | * @return string The translated string |
||
190 | */ |
||
191 | public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null) |
||
195 | |||
196 | /** TwigTrait */ |
||
197 | /** |
||
198 | * Renders a view and returns a Response. |
||
199 | * |
||
200 | * To stream a view, pass an instance of StreamedResponse as a third argument. |
||
201 | * |
||
202 | * @param string $view The view name |
||
203 | * @param array $parameters An array of parameters to pass to the view |
||
204 | * @param Response $response A Response instance |
||
205 | * |
||
206 | * @return Response A Response instance |
||
207 | */ |
||
208 | 39 | public function render($view, array $parameters = array(), Response $response = null) |
|
209 | { |
||
210 | $twig = $this['twig']; |
||
211 | |||
212 | 39 | if ($response instanceof StreamedResponse) { |
|
213 | $response->setCallback(function () use ($twig, $view, $parameters) { |
||
214 | $twig->display($view, $parameters); |
||
215 | }); |
||
216 | } else { |
||
217 | 38 | if (null === $response) { |
|
218 | $response = new Response(); |
||
219 | } |
||
220 | $response->setContent($twig->render($view, $parameters)); |
||
221 | 1 | } |
|
222 | |||
223 | 39 | return $response; |
|
224 | 38 | } |
|
225 | |||
226 | /** |
||
227 | * Renders a view. |
||
228 | * |
||
229 | * @param string $view The view name |
||
230 | * @param array $parameters An array of parameters to pass to the view |
||
231 | * |
||
232 | * @return Response A Response instance |
||
233 | */ |
||
234 | 28 | public function renderView($view, array $parameters = array()) |
|
238 | |||
239 | /** |
||
240 | * Response xml. |
||
241 | * |
||
242 | * @param string $view The view name |
||
243 | * @param array $parameters An array of parameters to pass to the view |
||
244 | * |
||
245 | * @return Response A Response instance |
||
246 | */ |
||
247 | public function xml($view, array $parameters = array()) |
||
258 | |||
259 | /** UrlGeneratorTrait */ |
||
260 | /** |
||
261 | * Generates a path from the given parameters. |
||
262 | * |
||
263 | * @param string $route The name of the route |
||
264 | * @param mixed $parameters An array of parameters |
||
265 | * |
||
266 | * @return string The generated path |
||
267 | */ |
||
268 | 32 | public function path($route, $parameters = array()) |
|
272 | |||
273 | /** |
||
274 | * Generates an absolute URL 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 URL |
||
280 | */ |
||
281 | 41 | public function url($route, $parameters = array()) |
|
285 | } |
||
286 |