1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Eccube; |
25
|
|
|
|
26
|
|
|
use Eccube\Application\ApplicationTrait; |
27
|
|
|
use Eccube\Common\Constant; |
28
|
|
|
use Eccube\Doctrine\ORM\Mapping\Driver\YamlDriver; |
29
|
|
|
use Eccube\EventListener\TransactionListener; |
30
|
|
|
use Monolog\Logger; |
31
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
32
|
|
|
use Symfony\Component\Finder\Finder; |
33
|
|
|
use Symfony\Component\HttpFoundation\Request; |
34
|
|
|
use Symfony\Component\HttpFoundation\Response; |
35
|
|
|
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
36
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
37
|
|
|
use Symfony\Component\HttpKernel\Event\PostResponseEvent; |
38
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
39
|
|
|
use Symfony\Component\Yaml\Yaml; |
40
|
|
|
|
41
|
|
|
class Application extends ApplicationTrait |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
protected static $instance; |
44
|
|
|
|
45
|
|
|
protected $initialized = false; |
46
|
|
|
protected $initializedPlugin = false; |
47
|
|
|
protected $testMode = false; |
48
|
|
|
|
49
|
998 |
|
public static function getInstance(array $values = array()) |
|
|
|
|
50
|
|
|
{ |
51
|
998 |
|
if (!is_object(self::$instance)) { |
52
|
932 |
|
self::$instance = new Application($values); |
53
|
|
|
} |
54
|
|
|
|
55
|
998 |
|
return self::$instance; |
56
|
|
|
} |
57
|
|
|
|
58
|
933 |
|
public static function clearInstance() |
|
|
|
|
59
|
|
|
{ |
60
|
933 |
|
self::$instance = null; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
final public function __clone() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
throw new \Exception('Clone is not allowed against '.get_class($this)); |
66
|
|
|
} |
67
|
|
|
|
68
|
946 |
|
public function __construct(array $values = array()) |
|
|
|
|
69
|
|
|
{ |
70
|
946 |
|
parent::__construct($values); |
71
|
|
|
|
72
|
946 |
|
if (is_null(self::$instance)) { |
73
|
933 |
|
self::$instance = $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// load config |
77
|
946 |
|
$this->initConfig(); |
78
|
|
|
|
79
|
|
|
// init monolog |
80
|
946 |
|
$this->initLogger(); |
81
|
|
|
} |
82
|
|
|
|
83
|
946 |
|
public function initConfig() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
// load config |
86
|
|
|
$this['config'] = $this->share(function() { |
|
|
|
|
87
|
939 |
|
$ymlPath = __DIR__.'/../../app/config/eccube'; |
88
|
939 |
|
$distPath = __DIR__.'/../../src/Eccube/Resource/config'; |
89
|
|
|
|
90
|
939 |
|
$config = array(); |
91
|
939 |
|
$config_yml = $ymlPath.'/config.yml'; |
92
|
939 |
|
if (file_exists($config_yml)) { |
93
|
939 |
|
$config = Yaml::parse(file_get_contents($config_yml)); |
94
|
|
|
} |
95
|
|
|
|
96
|
939 |
|
$config_dist = array(); |
97
|
939 |
|
$config_yml_dist = $distPath.'/config.yml.dist'; |
98
|
939 |
|
if (file_exists($config_yml_dist)) { |
99
|
939 |
|
$config_dist = Yaml::parse(file_get_contents($config_yml_dist)); |
100
|
|
|
} |
101
|
|
|
|
102
|
939 |
|
$config_path = array(); |
103
|
939 |
|
$path_yml = $ymlPath.'/path.yml'; |
104
|
939 |
|
if (file_exists($path_yml)) { |
105
|
939 |
|
$config_path = Yaml::parse(file_get_contents($path_yml)); |
106
|
|
|
} |
107
|
|
|
|
108
|
939 |
|
$config_constant = array(); |
109
|
939 |
|
$constant_yml = $ymlPath.'/constant.yml'; |
110
|
939 |
|
if (file_exists($constant_yml)) { |
111
|
|
|
$config_constant = Yaml::parse(file_get_contents($constant_yml)); |
112
|
|
|
$config_constant = empty($config_constant) ? array() : $config_constant; |
113
|
|
|
} |
114
|
|
|
|
115
|
939 |
|
$config_constant_dist = array(); |
116
|
939 |
|
$constant_yml_dist = $distPath.'/constant.yml.dist'; |
117
|
939 |
|
if (file_exists($constant_yml_dist)) { |
118
|
939 |
|
$config_constant_dist = Yaml::parse(file_get_contents($constant_yml_dist)); |
119
|
|
|
} |
120
|
|
|
|
121
|
939 |
|
$configAll = array_replace_recursive($config_constant_dist, $config_dist, $config_constant, $config_path, $config); |
122
|
|
|
|
123
|
939 |
|
$database = array(); |
124
|
939 |
|
$yml = $ymlPath.'/database.yml'; |
125
|
939 |
|
if (file_exists($yml)) { |
126
|
939 |
|
$database = Yaml::parse(file_get_contents($yml)); |
127
|
|
|
} |
128
|
|
|
|
129
|
939 |
|
$mail = array(); |
130
|
939 |
|
$yml = $ymlPath.'/mail.yml'; |
131
|
939 |
|
if (file_exists($yml)) { |
132
|
939 |
|
$mail = Yaml::parse(file_get_contents($yml)); |
133
|
|
|
} |
134
|
939 |
|
$configAll = array_replace_recursive($configAll, $database, $mail); |
135
|
|
|
|
136
|
939 |
|
$config_log = array(); |
137
|
939 |
|
$yml = $ymlPath.'/log.yml'; |
138
|
939 |
|
if (file_exists($yml)) { |
139
|
|
|
$config_log = Yaml::parse(file_get_contents($yml)); |
140
|
|
|
} |
141
|
939 |
|
$config_log_dist = array(); |
142
|
939 |
|
$log_yml_dist = $distPath.'/log.yml.dist'; |
143
|
939 |
|
if (file_exists($log_yml_dist)) { |
144
|
939 |
|
$config_log_dist = Yaml::parse(file_get_contents($log_yml_dist)); |
145
|
|
|
} |
146
|
|
|
|
147
|
939 |
|
$configAll = array_replace_recursive($configAll, $config_log_dist, $config_log); |
148
|
|
|
|
149
|
939 |
|
$config_nav = array(); |
150
|
939 |
|
$yml = $ymlPath.'/nav.yml'; |
151
|
939 |
|
if (file_exists($yml)) { |
152
|
|
|
$config_nav = array('nav' => Yaml::parse(file_get_contents($yml))); |
153
|
|
|
} |
154
|
939 |
|
$config_nav_dist = array(); |
155
|
939 |
|
$nav_yml_dist = $distPath.'/nav.yml.dist'; |
156
|
939 |
|
if (file_exists($nav_yml_dist)) { |
157
|
939 |
|
$config_nav_dist = array('nav' => Yaml::parse(file_get_contents($nav_yml_dist))); |
158
|
|
|
} |
159
|
|
|
|
160
|
939 |
|
$configAll = array_replace_recursive($configAll, $config_nav_dist, $config_nav); |
161
|
|
|
|
162
|
939 |
|
return $configAll; |
163
|
946 |
|
}); |
164
|
|
|
} |
165
|
|
|
|
166
|
946 |
|
public function initLogger() |
|
|
|
|
167
|
|
|
{ |
168
|
946 |
|
$app = $this; |
169
|
946 |
|
$this->register(new ServiceProvider\EccubeMonologServiceProvider($app)); |
|
|
|
|
170
|
946 |
|
$this['monolog.logfile'] = __DIR__.'/../../app/log/site.log'; |
171
|
946 |
|
$this['monolog.name'] = 'eccube'; |
172
|
|
|
} |
173
|
|
|
|
174
|
936 |
|
public function initialize() |
|
|
|
|
175
|
|
|
{ |
176
|
936 |
|
if ($this->initialized) { |
177
|
|
|
return; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
// init locale |
181
|
936 |
|
$this->initLocale(); |
182
|
|
|
|
183
|
|
|
// init session |
184
|
936 |
|
$this->initSession(); |
185
|
|
|
|
186
|
|
|
// init twig |
187
|
936 |
|
$this->initRendering(); |
188
|
|
|
|
189
|
|
|
// init provider |
190
|
936 |
|
$this->register(new \Silex\Provider\HttpFragmentServiceProvider()); |
191
|
936 |
|
$this->register(new \Silex\Provider\UrlGeneratorServiceProvider()); |
192
|
936 |
|
$this->register(new \Silex\Provider\FormServiceProvider()); |
193
|
936 |
|
$this->register(new \Silex\Provider\SerializerServiceProvider()); |
194
|
936 |
|
$this->register(new \Eccube\ServiceProvider\ValidatorServiceProvider()); |
195
|
|
|
|
196
|
936 |
|
$app = $this; |
197
|
|
|
$this->error(function(\Exception $e, $code) use ($app) { |
|
|
|
|
198
|
10 |
|
if ($app['debug']) { |
199
|
10 |
|
return; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
switch ($code) { |
203
|
|
|
case 403: |
204
|
|
|
$title = 'アクセスできません。'; |
205
|
|
|
$message = 'お探しのページはアクセスができない状況にあるか、移動もしくは削除された可能性があります。'; |
206
|
|
|
break; |
207
|
|
|
case 404: |
208
|
|
|
$title = 'ページがみつかりません。'; |
209
|
|
|
$message = 'URLに間違いがないかご確認ください。'; |
210
|
|
|
break; |
211
|
|
|
default: |
212
|
|
|
$title = 'システムエラーが発生しました。'; |
213
|
|
|
$message = '大変お手数ですが、サイト管理者までご連絡ください。'; |
214
|
|
|
break; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return $app->render('error.twig', array( |
218
|
|
|
'error_title' => $title, |
219
|
|
|
'error_message' => $message, |
220
|
|
|
)); |
221
|
936 |
|
}); |
222
|
|
|
|
223
|
|
|
// init mailer |
224
|
936 |
|
$this->initMailer(); |
225
|
|
|
|
226
|
|
|
// init doctrine orm |
227
|
936 |
|
$this->initDoctrine(); |
228
|
|
|
|
229
|
|
|
// Set up the DBAL connection now to check for a proper connection to the database. |
230
|
936 |
|
$this->checkDatabaseConnection(); |
231
|
|
|
|
232
|
|
|
// init security |
233
|
936 |
|
$this->initSecurity(); |
234
|
|
|
|
235
|
|
|
// init ec-cube service provider |
236
|
936 |
|
$this->register(new ServiceProvider\EccubeServiceProvider()); |
237
|
|
|
|
238
|
|
|
// mount controllers |
239
|
936 |
|
$this->register(new \Silex\Provider\ServiceControllerServiceProvider()); |
240
|
936 |
|
$this->mount('', new ControllerProvider\FrontControllerProvider()); |
241
|
936 |
|
$this->mount('/'.trim($this['config']['admin_route'], '/').'/', new ControllerProvider\AdminControllerProvider()); |
242
|
936 |
|
Request::enableHttpMethodParameterOverride(); // PUTやDELETEできるようにする |
243
|
|
|
|
244
|
|
|
// add transaction listener |
245
|
936 |
|
$this['dispatcher']->addSubscriber(new TransactionListener($this)); |
246
|
|
|
|
247
|
936 |
|
$this->initialized = true; |
248
|
|
|
} |
249
|
|
|
|
250
|
936 |
|
public function initLocale() |
|
|
|
|
251
|
|
|
{ |
252
|
|
|
|
253
|
|
|
// timezone |
254
|
936 |
|
if (!empty($this['config']['timezone'])) { |
255
|
936 |
|
date_default_timezone_set($this['config']['timezone']); |
256
|
|
|
} |
257
|
|
|
|
258
|
936 |
|
$this->register(new \Silex\Provider\TranslationServiceProvider(), array( |
259
|
936 |
|
'locale' => $this['config']['locale'], |
260
|
|
|
)); |
261
|
|
|
$this['translator'] = $this->share($this->extend('translator', function($translator, \Silex\Application $app) { |
|
|
|
|
262
|
605 |
|
$translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader()); |
263
|
|
|
|
264
|
605 |
|
$r = new \ReflectionClass('Symfony\Component\Validator\Validator'); |
265
|
605 |
|
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf'; |
266
|
605 |
|
if (file_exists($file)) { |
267
|
605 |
|
$translator->addResource('xliff', $file, $app['locale'], 'validators'); |
268
|
|
|
} |
269
|
|
|
|
270
|
605 |
|
$file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml'; |
271
|
605 |
|
if (file_exists($file)) { |
272
|
605 |
|
$translator->addResource('yaml', $file, $app['locale'], 'validators'); |
273
|
|
|
} |
274
|
|
|
|
275
|
605 |
|
$file = __DIR__.'/Resource/locale/message.'.$app['locale'].'.yml'; |
276
|
605 |
|
if (file_exists($file)) { |
277
|
605 |
|
$translator->addResource('yaml', $file, $app['locale']); |
278
|
|
|
} |
279
|
|
|
|
280
|
605 |
|
return $translator; |
281
|
936 |
|
})); |
282
|
|
|
} |
283
|
|
|
|
284
|
936 |
|
public function initSession() |
|
|
|
|
285
|
|
|
{ |
286
|
936 |
|
$this->register(new \Silex\Provider\SessionServiceProvider(), array( |
287
|
936 |
|
'session.storage.save_path' => $this['config']['root_dir'].'/app/cache/eccube/session', |
288
|
|
|
'session.storage.options' => array( |
289
|
936 |
|
'name' => 'eccube', |
290
|
936 |
|
'cookie_path' => $this['config']['root_urlpath'] ?: '/', |
291
|
936 |
|
'cookie_secure' => $this['config']['force_ssl'], |
292
|
936 |
|
'cookie_lifetime' => $this['config']['cookie_lifetime'], |
293
|
|
|
'cookie_httponly' => true, |
294
|
|
|
// cookie_domainは指定しない |
295
|
|
|
// http://blog.tokumaru.org/2011/10/cookiedomain.html |
296
|
|
|
), |
297
|
|
|
)); |
298
|
|
|
} |
299
|
|
|
|
300
|
936 |
|
public function initRendering() |
|
|
|
|
301
|
|
|
{ |
302
|
936 |
|
$this->register(new \Silex\Provider\TwigServiceProvider(), array( |
303
|
936 |
|
'twig.form.templates' => array('Form/form_layout.twig'), |
304
|
|
|
)); |
305
|
|
|
$this['twig'] = $this->share($this->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) { |
|
|
|
|
306
|
364 |
|
$twig->addExtension(new \Eccube\Twig\Extension\EccubeExtension($app)); |
307
|
364 |
|
$twig->addExtension(new \Twig_Extension_StringLoader()); |
308
|
|
|
|
309
|
364 |
|
return $twig; |
310
|
936 |
|
})); |
311
|
|
|
|
312
|
|
|
$this->before(function(Request $request, \Silex\Application $app) { |
|
|
|
|
313
|
|
|
// フロント or 管理画面ごとにtwigの探索パスを切り替える. |
314
|
|
|
$app['twig'] = $app->share($app->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) { |
|
|
|
|
315
|
351 |
|
$paths = array(); |
316
|
|
|
|
317
|
|
|
// 互換性がないのでprofiler とproduction 時のcacheを分離する |
318
|
|
|
|
319
|
351 |
|
$app['admin'] = false; |
320
|
351 |
|
$app['front'] = false; |
321
|
|
|
|
322
|
351 |
|
if (isset($app['profiler'])) { |
323
|
|
|
$cacheBaseDir = __DIR__.'/../../app/cache/twig/profiler/'; |
324
|
|
|
} else { |
325
|
351 |
|
$cacheBaseDir = __DIR__.'/../../app/cache/twig/production/'; |
326
|
|
|
} |
327
|
351 |
|
$pathinfo = rawurldecode($app['request']->getPathInfo()); |
328
|
351 |
|
if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) { |
329
|
187 |
|
if (file_exists(__DIR__.'/../../app/template/admin')) { |
330
|
187 |
|
$paths[] = __DIR__.'/../../app/template/admin'; |
331
|
|
|
} |
332
|
187 |
|
$paths[] = $app['config']['template_admin_realdir']; |
333
|
187 |
|
$paths[] = __DIR__.'/../../app/Plugin'; |
334
|
187 |
|
$cache = $cacheBaseDir.'admin'; |
335
|
187 |
|
$app['admin'] = true; |
336
|
|
|
} else { |
337
|
165 |
|
if (file_exists($app['config']['template_realdir'])) { |
338
|
165 |
|
$paths[] = $app['config']['template_realdir']; |
339
|
|
|
} |
340
|
165 |
|
$paths[] = $app['config']['template_default_realdir']; |
341
|
165 |
|
$paths[] = __DIR__.'/../../app/Plugin'; |
342
|
165 |
|
$cache = $cacheBaseDir.$app['config']['template_code']; |
343
|
165 |
|
$app['front'] = true; |
344
|
|
|
} |
345
|
351 |
|
$twig->setCache($cache); |
346
|
351 |
|
$app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($paths)); |
347
|
|
|
|
348
|
351 |
|
return $twig; |
349
|
353 |
|
})); |
350
|
|
|
|
351
|
|
|
// 管理画面のIP制限チェック. |
352
|
353 |
|
$pathinfo = rawurldecode($app['request']->getPathInfo()); |
353
|
353 |
|
if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) { |
354
|
|
|
// IP制限チェック |
355
|
187 |
|
$allowHost = $app['config']['admin_allow_host']; |
356
|
187 |
|
if (count($allowHost) > 0) { |
357
|
|
|
if (array_search($app['request']->getClientIp(), $allowHost) === false) { |
358
|
|
|
throw new \Exception(); |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
} |
362
|
936 |
|
}, self::EARLY_EVENT); |
363
|
|
|
|
364
|
|
|
// twigのグローバル変数を定義. |
365
|
936 |
|
$app = $this; |
366
|
|
|
$this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) { |
|
|
|
|
367
|
|
|
// ショップ基本情報 |
368
|
351 |
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
369
|
351 |
|
$app['twig']->addGlobal('BaseInfo', $BaseInfo); |
370
|
|
|
|
371
|
351 |
|
$pathinfo = rawurldecode($app['request']->getPathInfo()); |
372
|
351 |
|
if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) { |
373
|
|
|
// 管理画面 |
374
|
|
|
// 管理画面メニュー |
375
|
187 |
|
$menus = array('', '', ''); |
376
|
187 |
|
$app['twig']->addGlobal('menus', $menus); |
377
|
|
|
|
378
|
187 |
|
$Member = $app->user(); |
379
|
187 |
|
if (is_object($Member)) { |
380
|
|
|
// ログインしていれば管理者のロールを取得 |
381
|
181 |
|
$AuthorityRoles = $app['eccube.repository.authority_role']->findBy(array('Authority' => $Member->getAuthority())); |
382
|
|
|
|
383
|
181 |
|
$roles = array(); |
384
|
181 |
|
foreach ($AuthorityRoles as $AuthorityRole) { |
385
|
|
|
// 管理画面でメニュー制御するため相対パス全てをセット |
386
|
181 |
|
$roles[] = $app['request']->getBaseUrl().'/'.$app['config']['admin_route'].$AuthorityRole->getDenyUrl(); |
387
|
|
|
} |
388
|
|
|
|
389
|
187 |
|
$app['twig']->addGlobal('AuthorityRoles', $roles); |
390
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
} else { |
393
|
|
|
// フロント画面 |
394
|
165 |
|
$request = $event->getRequest(); |
395
|
165 |
|
$route = $request->attributes->get('_route'); |
396
|
|
|
|
397
|
|
|
// ユーザ作成画面 |
398
|
165 |
|
if ($route === trim($app['config']['user_data_route'])) { |
399
|
2 |
|
$params = $request->attributes->get('_route_params'); |
400
|
2 |
|
$route = $params['route']; |
401
|
|
|
// プレビュー画面 |
402
|
163 |
|
} elseif ($request->get('preview')) { |
403
|
|
|
$route = 'preview'; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
try { |
407
|
165 |
|
$DeviceType = $app['eccube.repository.master.device_type'] |
408
|
165 |
|
->find(\Eccube\Entity\Master\DeviceType::DEVICE_TYPE_PC); |
409
|
165 |
|
$PageLayout = $app['eccube.repository.page_layout']->getByUrl($DeviceType, $route); |
410
|
135 |
|
} catch (\Doctrine\ORM\NoResultException $e) { |
411
|
135 |
|
$PageLayout = $app['eccube.repository.page_layout']->newPageLayout($DeviceType); |
412
|
|
|
} |
413
|
|
|
|
414
|
165 |
|
$app['twig']->addGlobal('PageLayout', $PageLayout); |
415
|
165 |
|
$app['twig']->addGlobal('title', $PageLayout->getName()); |
416
|
|
|
} |
417
|
936 |
|
}); |
418
|
|
|
} |
419
|
|
|
|
420
|
936 |
|
public function initMailer() |
|
|
|
|
421
|
|
|
{ |
422
|
|
|
|
423
|
|
|
// メール送信時の文字エンコード指定(デフォルトはUTF-8) |
|
|
|
|
424
|
936 |
|
if (isset($this['config']['mail']['charset_iso_2022_jp']) && is_bool($this['config']['mail']['charset_iso_2022_jp'])) { |
425
|
936 |
|
if ($this['config']['mail']['charset_iso_2022_jp'] === true) { |
426
|
|
|
\Swift::init(function() { |
|
|
|
|
427
|
|
|
\Swift_DependencyContainer::getInstance() |
428
|
|
|
->register('mime.qpheaderencoder') |
429
|
|
|
->asAliasOf('mime.base64headerencoder'); |
430
|
|
|
\Swift_Preferences::getInstance()->setCharset('iso-2022-jp'); |
431
|
|
|
}); |
432
|
|
|
} |
433
|
|
|
} |
434
|
|
|
|
435
|
936 |
|
$this->register(new \Silex\Provider\SwiftmailerServiceProvider()); |
436
|
936 |
|
$this['swiftmailer.options'] = $this['config']['mail']; |
437
|
|
|
|
438
|
936 |
|
if (isset($this['config']['mail']['spool']) && is_bool($this['config']['mail']['spool'])) { |
439
|
|
|
$this['swiftmailer.use_spool'] = $this['config']['mail']['spool']; |
440
|
|
|
} |
441
|
|
|
// デフォルトはsmtpを使用 |
442
|
936 |
|
$transport = $this['config']['mail']['transport']; |
443
|
936 |
|
if ($transport == 'sendmail') { |
444
|
|
|
$this['swiftmailer.transport'] = \Swift_SendmailTransport::newInstance(); |
445
|
936 |
|
} elseif ($transport == 'mail') { |
446
|
|
|
$this['swiftmailer.transport'] = \Swift_MailTransport::newInstance(); |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
|
450
|
936 |
|
public function initDoctrine() |
|
|
|
|
451
|
|
|
{ |
452
|
936 |
|
$this->register(new \Silex\Provider\DoctrineServiceProvider(), array( |
|
|
|
|
453
|
|
|
'dbs.options' => array( |
|
|
|
|
454
|
936 |
|
'default' => $this['config']['database'] |
455
|
|
|
))); |
456
|
936 |
|
$this->register(new \Saxulum\DoctrineOrmManagerRegistry\Silex\Provider\DoctrineOrmManagerRegistryProvider()); |
457
|
|
|
|
458
|
|
|
// プラグインのmetadata定義を合わせて行う. |
459
|
936 |
|
$pluginBasePath = __DIR__.'/../../app/Plugin'; |
460
|
936 |
|
$finder = Finder::create() |
461
|
936 |
|
->in($pluginBasePath) |
462
|
936 |
|
->directories() |
463
|
936 |
|
->depth(0); |
464
|
|
|
|
465
|
936 |
|
$ormMappings = array(); |
466
|
936 |
|
$ormMappings[] = array( |
467
|
|
|
'type' => 'yml', |
468
|
|
|
'namespace' => 'Eccube\Entity', |
469
|
|
|
'path' => array( |
470
|
|
|
__DIR__.'/Resource/doctrine', |
471
|
|
|
__DIR__.'/Resource/doctrine/master', |
472
|
|
|
), |
473
|
|
|
); |
474
|
|
|
|
475
|
936 |
|
foreach ($finder as $dir) { |
|
|
|
|
476
|
|
|
|
477
|
139 |
|
$file = $dir->getRealPath().'/config.yml'; |
478
|
|
|
|
479
|
139 |
|
if (file_exists($file)) { |
480
|
139 |
|
$config = Yaml::parse(file_get_contents($file)); |
481
|
|
|
} else { |
482
|
|
|
$code = $dir->getBaseName(); |
483
|
|
|
$this['monolog']->warning("skip {$code} orm.path loading. config.yml not found.", array('path' => $file)); |
484
|
|
|
continue; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
// Doctrine Extend |
488
|
139 |
|
if (isset($config['orm.path']) && is_array($config['orm.path'])) { |
489
|
|
|
$paths = array(); |
490
|
|
|
foreach ($config['orm.path'] as $path) { |
491
|
|
|
$paths[] = $pluginBasePath.'/'.$config['code'].$path; |
492
|
|
|
} |
493
|
|
|
$ormMappings[] = array( |
494
|
|
|
'type' => 'yml', |
495
|
|
|
'namespace' => 'Plugin\\'.$config['code'].'\\Entity', |
496
|
936 |
|
'path' => $paths, |
497
|
|
|
); |
498
|
|
|
} |
499
|
|
|
} |
500
|
|
|
|
501
|
936 |
|
$this->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array( |
502
|
936 |
|
'orm.proxies_dir' => __DIR__.'/../../app/cache/doctrine', |
503
|
|
|
'orm.em.options' => array( |
504
|
936 |
|
'mappings' => $ormMappings, |
505
|
|
|
), |
506
|
|
|
)); |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* YamlDriverのPHP7対応. Doctrine2.4で修正されれば不要. |
510
|
|
|
* @see https://github.com/EC-CUBE/ec-cube/issues/1338 |
511
|
|
|
*/ |
512
|
936 |
|
$config = $this['orm.em']->getConfiguration(); |
513
|
|
|
/** @var $driver \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain */ |
514
|
936 |
|
$chain = $config->getMetadataDriverImpl(); |
515
|
|
|
// $ormMappingsの1要素ごとにDriverが生成されている. |
516
|
936 |
|
$drivers = $chain->getDrivers(); |
517
|
936 |
|
foreach ($drivers as $namespace => $oldDriver) { |
518
|
|
|
/** @var $newDriver \Eccube\Doctrine\ORM\Mapping\Driver\YamlDriver */ |
519
|
936 |
|
$newDriver = new YamlDriver($oldDriver->getLocator()); |
520
|
|
|
// 修正したDriverに差し替える. メソッド名はaddだけど実際はsetしてる. |
521
|
936 |
|
$chain->addDriver($newDriver, $namespace); |
522
|
|
|
} |
523
|
|
|
} |
524
|
|
|
|
525
|
936 |
|
public function initSecurity() |
|
|
|
|
526
|
|
|
{ |
527
|
936 |
|
$this->register(new \Silex\Provider\SecurityServiceProvider()); |
528
|
936 |
|
$this->register(new \Silex\Provider\RememberMeServiceProvider()); |
529
|
|
|
|
530
|
936 |
|
$this['security.firewalls'] = array( |
531
|
|
|
'admin' => array( |
532
|
936 |
|
'pattern' => "^/{$this['config']['admin_route']}/", |
533
|
|
|
'form' => array( |
534
|
936 |
|
'login_path' => "/{$this['config']['admin_route']}/login", |
535
|
936 |
|
'check_path' => "/{$this['config']['admin_route']}/login_check", |
536
|
936 |
|
'username_parameter' => 'login_id', |
537
|
936 |
|
'password_parameter' => 'password', |
538
|
|
|
'with_csrf' => true, |
539
|
|
|
'use_forward' => true, |
540
|
|
|
), |
541
|
|
|
'logout' => array( |
542
|
936 |
|
'logout_path' => "/{$this['config']['admin_route']}/logout", |
543
|
936 |
|
'target_url' => "/{$this['config']['admin_route']}/", |
544
|
|
|
), |
545
|
936 |
|
'users' => $this['orm.em']->getRepository('Eccube\Entity\Member'), |
546
|
|
|
'anonymous' => true, |
547
|
936 |
|
), |
548
|
|
|
'customer' => array( |
549
|
936 |
|
'pattern' => '^/', |
550
|
|
|
'form' => array( |
551
|
|
|
'login_path' => '/mypage/login', |
552
|
|
|
'check_path' => '/login_check', |
553
|
|
|
'username_parameter' => 'login_email', |
554
|
|
|
'password_parameter' => 'login_pass', |
555
|
|
|
'with_csrf' => true, |
556
|
|
|
'use_forward' => true, |
557
|
|
|
), |
558
|
|
|
'logout' => array( |
559
|
|
|
'logout_path' => '/logout', |
560
|
|
|
'target_url' => '/', |
561
|
|
|
), |
562
|
|
|
'remember_me' => array( |
563
|
936 |
|
'key' => sha1($this['config']['auth_magic']), |
564
|
936 |
|
'name' => 'eccube_rememberme', |
565
|
|
|
// lifetimeはデフォルトの1年間にする |
566
|
|
|
// 'lifetime' => $this['config']['cookie_lifetime'], |
|
|
|
|
567
|
936 |
|
'path' => $this['config']['root_urlpath'] ?: '/', |
568
|
936 |
|
'secure' => $this['config']['force_ssl'], |
569
|
|
|
'httponly' => true, |
570
|
|
|
'always_remember_me' => false, |
571
|
936 |
|
'remember_me_parameter' => 'login_memory', |
572
|
|
|
), |
573
|
936 |
|
'users' => $this['orm.em']->getRepository('Eccube\Entity\Customer'), |
574
|
|
|
'anonymous' => true, |
575
|
|
|
), |
576
|
|
|
); |
577
|
|
|
|
578
|
936 |
|
$this['security.access_rules'] = array( |
579
|
936 |
|
array("^/{$this['config']['admin_route']}/login", 'IS_AUTHENTICATED_ANONYMOUSLY'), |
580
|
936 |
|
array("^/{$this['config']['admin_route']}/", 'ROLE_ADMIN'), |
581
|
|
|
array('^/mypage/login', 'IS_AUTHENTICATED_ANONYMOUSLY'), |
582
|
|
|
array('^/mypage/withdraw_complete', 'IS_AUTHENTICATED_ANONYMOUSLY'), |
583
|
|
|
array('^/mypage/change', 'IS_AUTHENTICATED_FULLY'), |
584
|
|
|
array('^/mypage', 'ROLE_USER'), |
585
|
|
|
); |
586
|
|
|
|
587
|
|
|
$this['eccube.password_encoder'] = $this->share(function($app) { |
|
|
|
|
588
|
936 |
|
return new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']); |
589
|
936 |
|
}); |
590
|
|
|
$this['security.encoder_factory'] = $this->share(function($app) { |
|
|
|
|
591
|
936 |
|
return new \Symfony\Component\Security\Core\Encoder\EncoderFactory(array( |
592
|
936 |
|
'Eccube\Entity\Customer' => $app['eccube.password_encoder'], |
593
|
936 |
|
'Eccube\Entity\Member' => $app['eccube.password_encoder'], |
594
|
|
|
)); |
595
|
936 |
|
}); |
596
|
|
|
$this['eccube.event_listner.security'] = $this->share(function($app) { |
|
|
|
|
597
|
936 |
|
return new \Eccube\EventListener\SecurityEventListener($app['orm.em']); |
598
|
936 |
|
}); |
599
|
|
|
$this['user'] = function($app) { |
|
|
|
|
600
|
256 |
|
$token = $app['security']->getToken(); |
601
|
|
|
|
602
|
256 |
|
return ($token !== null) ? $token->getUser() : null; |
603
|
|
|
}; |
604
|
|
|
|
605
|
|
|
// ログイン時のイベントを設定. |
606
|
936 |
|
$this['dispatcher']->addListener(\Symfony\Component\Security\Http\SecurityEvents::INTERACTIVE_LOGIN, array($this['eccube.event_listner.security'], 'onInteractiveLogin')); |
607
|
|
|
|
608
|
|
|
// Voterの設定 |
609
|
936 |
|
$app = $this; |
610
|
|
|
$this['authority_voter'] = $this->share(function($app) { |
|
|
|
|
611
|
936 |
|
return new \Eccube\Security\Voter\AuthorityVoter($app); |
612
|
936 |
|
}); |
613
|
|
|
|
614
|
|
|
$app['security.voters'] = $app->extend('security.voters', function($voters) use ($app) { |
|
|
|
|
615
|
936 |
|
$voters[] = $app['authority_voter']; |
616
|
|
|
|
617
|
936 |
|
return $voters; |
618
|
936 |
|
}); |
619
|
|
|
|
620
|
|
|
$this['security.access_manager'] = $this->share(function($app) { |
|
|
|
|
621
|
936 |
|
return new \Symfony\Component\Security\Core\Authorization\AccessDecisionManager($app['security.voters'], 'unanimous'); |
622
|
936 |
|
}); |
623
|
|
|
|
624
|
|
|
} |
625
|
|
|
|
626
|
936 |
|
public function initializePlugin() |
|
|
|
|
627
|
|
|
{ |
628
|
936 |
|
if ($this->initializedPlugin) { |
629
|
|
|
return; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
// setup event dispatcher |
633
|
936 |
|
$this->initPluginEventDispatcher(); |
634
|
|
|
|
635
|
|
|
// load plugin |
636
|
936 |
|
$this->loadPlugin(); |
637
|
|
|
|
638
|
936 |
|
$this->initializedPlugin = true; |
639
|
|
|
} |
640
|
|
|
|
641
|
936 |
|
public function initPluginEventDispatcher() |
|
|
|
|
642
|
|
|
{ |
643
|
|
|
// EventDispatcher |
644
|
|
|
$this['eccube.event.dispatcher'] = $this->share(function() { |
|
|
|
|
645
|
366 |
|
return new EventDispatcher(); |
646
|
936 |
|
}); |
647
|
|
|
|
648
|
936 |
|
$app = $this; |
649
|
|
|
|
650
|
|
|
// hook point |
651
|
|
|
$this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($app) { |
652
|
353 |
|
if (!$event->isMasterRequest()) { |
653
|
98 |
|
return; |
654
|
|
|
} |
655
|
353 |
|
$hookpoint = 'eccube.event.app.before'; |
656
|
353 |
|
$app['eccube.event.dispatcher']->dispatch($hookpoint, $event); |
657
|
936 |
|
}, self::EARLY_EVENT); |
658
|
|
|
|
659
|
|
View Code Duplication |
$this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($app) { |
|
|
|
|
660
|
352 |
|
if (!$event->isMasterRequest()) { |
661
|
98 |
|
return; |
662
|
|
|
} |
663
|
350 |
|
$route = $event->getRequest()->attributes->get('_route'); |
664
|
350 |
|
$hookpoint = "eccube.event.controller.$route.before"; |
665
|
350 |
|
$app['eccube.event.dispatcher']->dispatch($hookpoint, $event); |
666
|
936 |
|
}); |
667
|
|
|
|
668
|
|
View Code Duplication |
$this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($app) { |
|
|
|
|
669
|
347 |
|
if (!$event->isMasterRequest()) { |
670
|
98 |
|
return; |
671
|
|
|
} |
672
|
347 |
|
$route = $event->getRequest()->attributes->get('_route'); |
673
|
347 |
|
$hookpoint = "eccube.event.controller.$route.after"; |
674
|
347 |
|
$app['eccube.event.dispatcher']->dispatch($hookpoint, $event); |
675
|
936 |
|
}); |
676
|
|
|
|
677
|
|
|
$this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($app) { |
678
|
347 |
|
if (!$event->isMasterRequest()) { |
679
|
98 |
|
return; |
680
|
|
|
} |
681
|
347 |
|
$hookpoint = 'eccube.event.app.after'; |
682
|
347 |
|
$app['eccube.event.dispatcher']->dispatch($hookpoint, $event); |
683
|
936 |
|
}, self::LATE_EVENT); |
684
|
|
|
|
685
|
|
|
$this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($app) { |
686
|
347 |
|
$route = $event->getRequest()->attributes->get('_route'); |
687
|
347 |
|
$hookpoint = "eccube.event.controller.$route.finish"; |
688
|
347 |
|
$app['eccube.event.dispatcher']->dispatch($hookpoint, $event); |
689
|
936 |
|
}); |
690
|
|
|
|
691
|
|
|
$this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) { |
|
|
|
|
692
|
347 |
|
$route = $event->getRequest()->attributes->get('_route'); |
693
|
347 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.render.'.$route.'.before', $event); |
694
|
936 |
|
}); |
695
|
|
|
|
696
|
|
|
// Request Event |
697
|
|
View Code Duplication |
$this->on(\Symfony\Component\HttpKernel\KernelEvents::REQUEST, function(\Symfony\Component\HttpKernel\Event\GetResponseEvent $event) use ($app) { |
|
|
|
|
698
|
|
|
|
699
|
352 |
|
if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { |
700
|
98 |
|
return; |
701
|
|
|
} |
702
|
|
|
|
703
|
352 |
|
$route = $event->getRequest()->attributes->get('_route'); |
704
|
|
|
|
705
|
352 |
|
if (is_null($route)) { |
706
|
|
|
return; |
707
|
|
|
} |
708
|
|
|
|
709
|
352 |
|
$app['monolog']->debug('KernelEvents::REQUEST '.$route); |
710
|
|
|
|
711
|
|
|
// 全体 |
712
|
352 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.request', $event); |
713
|
|
|
|
714
|
352 |
|
if (strpos($route, 'admin') === 0) { |
715
|
|
|
// 管理画面 |
716
|
187 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.admin.request', $event); |
717
|
|
|
} else { |
718
|
|
|
// フロント画面 |
719
|
166 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.front.request', $event); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
// ルーティング単位 |
723
|
352 |
|
$app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.request", $event); |
724
|
|
|
|
725
|
936 |
|
}, 30); // Routing(32)が解決しし, 認証判定(8)が実行される前のタイミング. |
|
|
|
|
726
|
|
|
|
727
|
|
|
// Controller Event |
728
|
|
View Code Duplication |
$this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) { |
|
|
|
|
729
|
|
|
|
730
|
351 |
|
if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { |
731
|
98 |
|
return; |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
|
735
|
349 |
|
$route = $event->getRequest()->attributes->get('_route'); |
736
|
|
|
|
737
|
349 |
|
if (is_null($route)) { |
738
|
|
|
return; |
739
|
|
|
} |
740
|
|
|
|
741
|
349 |
|
$app['monolog']->debug('KernelEvents::CONTROLLER '.$route); |
742
|
|
|
|
743
|
|
|
// 全体 |
744
|
349 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.controller', $event); |
745
|
|
|
|
746
|
349 |
|
if (strpos($route, 'admin') === 0) { |
747
|
|
|
// 管理画面 |
748
|
185 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.admin.controller', $event); |
749
|
|
|
} else { |
750
|
|
|
// フロント画面 |
751
|
165 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.front.controller', $event); |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
// ルーティング単位 |
755
|
349 |
|
$app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.controller", $event); |
756
|
936 |
|
}); |
757
|
|
|
|
758
|
|
|
// Response Event |
759
|
|
View Code Duplication |
$this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) { |
|
|
|
|
760
|
|
|
|
761
|
347 |
|
if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { |
762
|
98 |
|
return; |
763
|
|
|
} |
764
|
|
|
|
765
|
347 |
|
$route = $event->getRequest()->attributes->get('_route'); |
766
|
|
|
|
767
|
347 |
|
if (is_null($route)) { |
768
|
1 |
|
return; |
769
|
|
|
} |
770
|
|
|
|
771
|
346 |
|
$app['monolog']->debug('KernelEvents::RESPONSE '.$route); |
772
|
|
|
|
773
|
|
|
// ルーティング単位 |
774
|
346 |
|
$app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.response", $event); |
775
|
|
|
|
776
|
346 |
|
if (strpos($route, 'admin') === 0) { |
777
|
|
|
// 管理画面 |
778
|
187 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.admin.response', $event); |
779
|
|
|
} else { |
780
|
|
|
// フロント画面 |
781
|
160 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.front.response', $event); |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
// 全体 |
785
|
346 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.response', $event); |
786
|
936 |
|
}); |
787
|
|
|
|
788
|
|
|
// Exception Event |
789
|
|
View Code Duplication |
$this->on(\Symfony\Component\HttpKernel\KernelEvents::EXCEPTION, function(\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event) use ($app) { |
|
|
|
|
790
|
|
|
|
791
|
12 |
|
if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { |
792
|
|
|
return; |
793
|
|
|
} |
794
|
|
|
|
795
|
12 |
|
$route = $event->getRequest()->attributes->get('_route'); |
796
|
|
|
|
797
|
12 |
|
if (is_null($route)) { |
798
|
|
|
return; |
799
|
|
|
} |
800
|
|
|
|
801
|
12 |
|
$app['monolog']->debug('KernelEvents::EXCEPTION '.$route); |
802
|
|
|
|
803
|
|
|
// ルーティング単位 |
804
|
12 |
|
$app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.exception", $event); |
805
|
|
|
|
806
|
12 |
|
if (strpos($route, 'admin') === 0) { |
807
|
|
|
// 管理画面 |
808
|
2 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.admin.exception', $event); |
809
|
|
|
} else { |
810
|
|
|
// フロント画面 |
811
|
10 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.front.exception', $event); |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
// 全体 |
815
|
12 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.exception', $event); |
816
|
936 |
|
}); |
817
|
|
|
|
818
|
|
|
// Terminate Event |
819
|
|
View Code Duplication |
$this->on(\Symfony\Component\HttpKernel\KernelEvents::TERMINATE, function(\Symfony\Component\HttpKernel\Event\PostResponseEvent $event) use ($app) { |
|
|
|
|
820
|
|
|
|
821
|
347 |
|
$route = $event->getRequest()->attributes->get('_route'); |
822
|
|
|
|
823
|
347 |
|
if (is_null($route)) { |
824
|
1 |
|
return; |
825
|
|
|
} |
826
|
|
|
|
827
|
346 |
|
$app['monolog']->debug('KernelEvents::TERMINATE '.$route); |
828
|
|
|
|
829
|
|
|
// ルーティング単位 |
830
|
346 |
|
$app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.terminate", $event); |
831
|
|
|
|
832
|
346 |
|
if (strpos($route, 'admin') === 0) { |
833
|
|
|
// 管理画面 |
834
|
187 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.admin.terminate', $event); |
835
|
|
|
} else { |
836
|
|
|
// フロント画面 |
837
|
160 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.front.terminate', $event); |
838
|
|
|
} |
839
|
|
|
|
840
|
|
|
// 全体 |
841
|
346 |
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.terminate', $event); |
842
|
936 |
|
}); |
843
|
|
|
} |
844
|
|
|
|
845
|
936 |
|
public function loadPlugin() |
|
|
|
|
846
|
|
|
{ |
847
|
|
|
// プラグインディレクトリを探索. |
848
|
936 |
|
$basePath = __DIR__.'/../../app/Plugin'; |
849
|
936 |
|
$finder = Finder::create() |
850
|
936 |
|
->in($basePath) |
851
|
936 |
|
->directories() |
852
|
936 |
|
->depth(0); |
853
|
|
|
|
854
|
936 |
|
$finder->sortByName(); |
855
|
|
|
|
856
|
|
|
// ハンドラ優先順位をdbから持ってきてハッシュテーブルを作成 |
857
|
936 |
|
$priorities = array(); |
858
|
936 |
|
$handlers = $this['orm.em'] |
859
|
936 |
|
->getRepository('Eccube\Entity\PluginEventHandler') |
860
|
936 |
|
->getHandlers(); |
861
|
936 |
|
foreach ($handlers as $handler) { |
862
|
|
|
if ($handler->getPlugin()->getEnable() && !$handler->getPlugin()->getDelFlg()) { |
|
|
|
|
863
|
|
|
|
864
|
|
|
$priority = $handler->getPriority(); |
865
|
|
|
} else { |
866
|
|
|
// Pluginがdisable、削除済みの場合、EventHandlerのPriorityを全て0とみなす |
867
|
|
|
$priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED; |
868
|
|
|
} |
869
|
936 |
|
$priorities[$handler->getPlugin()->getClassName()][$handler->getEvent()][$handler->getHandler()] = $priority; |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
// プラグインをロードする. |
873
|
|
|
// config.yml/event.ymlの定義に沿ってインスタンスの生成を行い, イベント設定を行う. |
874
|
936 |
|
foreach ($finder as $dir) { |
875
|
|
|
//config.ymlのないディレクトリは無視する |
876
|
140 |
|
$path = $dir->getRealPath(); |
877
|
140 |
|
$code = $dir->getBaseName(); |
878
|
|
|
try { |
879
|
140 |
|
$this['eccube.service.plugin']->checkPluginArchiveContent($path); |
880
|
|
|
} catch (\Eccube\Exception\PluginException $e) { |
881
|
|
|
$this['monolog']->warning("skip {$code} config loading. config.yml not foud or invalid.", array( |
|
|
|
|
882
|
|
|
'path' => $path, |
883
|
|
|
'original-message' => $e->getMessage() |
884
|
|
|
)); |
885
|
|
|
continue; |
886
|
|
|
} |
887
|
140 |
|
$config = $this['eccube.service.plugin']->readYml($dir->getRealPath().'/config.yml'); |
888
|
|
|
|
889
|
140 |
|
$plugin = $this['orm.em'] |
890
|
140 |
|
->getRepository('Eccube\Entity\Plugin') |
891
|
140 |
|
->findOneBy(array('code' => $config['code'])); |
892
|
|
|
|
893
|
|
|
// const |
894
|
140 |
|
if (isset($config['const'])) { |
895
|
1 |
|
$this['config'] = $this->share($this->extend('config', function($eccubeConfig) use ($config) { |
|
|
|
|
896
|
1 |
|
$eccubeConfig[$config['code']] = array( |
897
|
1 |
|
'const' => $config['const'], |
898
|
|
|
); |
899
|
|
|
|
900
|
1 |
|
return $eccubeConfig; |
901
|
1 |
|
})); |
902
|
|
|
} |
903
|
|
|
|
904
|
140 |
|
if ($plugin && $plugin->getEnable() == Constant::DISABLED) { |
905
|
|
|
// プラグインが無効化されていれば読み込まない |
906
|
1 |
|
continue; |
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
// Type: Event |
910
|
139 |
|
if (isset($config['event'])) { |
911
|
139 |
|
$class = '\\Plugin\\'.$config['code'].'\\'.$config['event']; |
912
|
139 |
|
$eventExists = true; |
913
|
|
|
|
914
|
139 |
View Code Duplication |
if (!class_exists($class)) { |
|
|
|
|
915
|
|
|
$this['monolog']->warning("skip {$code} loading. event class not foud.", array( |
916
|
|
|
'class' => $class, |
917
|
|
|
)); |
918
|
|
|
$eventExists = false; |
919
|
|
|
} |
920
|
|
|
|
921
|
139 |
|
if ($eventExists && file_exists($dir->getRealPath().'/event.yml')) { |
|
|
|
|
922
|
|
|
|
923
|
139 |
|
$subscriber = new $class($this); |
924
|
|
|
|
925
|
139 |
|
foreach (Yaml::parse(file_get_contents($dir->getRealPath().'/event.yml')) as $event => $handlers) { |
926
|
139 |
|
foreach ($handlers as $handler) { |
927
|
139 |
|
if (!isset($priorities[$config['event']][$event][$handler[0]])) { // ハンドラテーブルに登録されていない(ソースにしか記述されていない)ハンドラは一番後ろにする |
928
|
139 |
|
$priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_LATEST; |
929
|
|
|
} else { |
930
|
|
|
$priority = $priorities[$config['event']][$event][$handler[0]]; |
931
|
|
|
} |
932
|
|
|
// 優先度が0のプラグインは登録しない |
933
|
139 |
|
if (\Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED != $priority) { |
934
|
139 |
|
$this['eccube.event.dispatcher']->addListener($event, array($subscriber, $handler[0]), $priority); |
935
|
|
|
} |
936
|
|
|
} |
937
|
|
|
} |
938
|
|
|
} |
939
|
|
|
} |
940
|
|
|
// Type: ServiceProvider |
941
|
139 |
|
if (isset($config['service'])) { |
942
|
|
|
foreach ($config['service'] as $service) { |
943
|
|
|
$class = '\\Plugin\\'.$config['code'].'\\ServiceProvider\\'.$service; |
944
|
|
View Code Duplication |
if (!class_exists($class)) { |
|
|
|
|
945
|
|
|
$this['monolog']->warning("skip {$code} loading. service provider class not foud.", array( |
946
|
|
|
'class' => $class, |
947
|
|
|
)); |
948
|
|
|
continue; |
949
|
|
|
} |
950
|
936 |
|
$this->register(new $class($this)); |
951
|
|
|
} |
952
|
|
|
} |
953
|
|
|
} |
954
|
|
|
} |
955
|
|
|
|
956
|
|
|
/** |
957
|
|
|
* PHPUnit を実行中かどうかを設定する. |
958
|
|
|
* |
959
|
|
|
* @param boolean $testMode PHPUnit を実行中の場合 true |
960
|
|
|
*/ |
961
|
923 |
|
public function setTestMode($testMode) { |
962
|
923 |
|
$this->testMode = $testMode; |
963
|
|
|
} |
964
|
|
|
|
965
|
|
|
/** |
966
|
|
|
* PHPUnit を実行中かどうか. |
967
|
|
|
* |
968
|
|
|
* @return boolean PHPUnit を実行中の場合 true |
969
|
|
|
*/ |
970
|
353 |
|
public function isTestMode() |
971
|
|
|
{ |
972
|
353 |
|
return $this->testMode; |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
/** |
976
|
|
|
* |
977
|
|
|
* データベースの接続を確認 |
978
|
|
|
* 成功 : trueを返却 |
979
|
|
|
* 失敗 : \Doctrine\DBAL\DBALExceptionエラーが発生( 接続に失敗した場合 )、エラー画面を表示しdie() |
980
|
|
|
* 備考 : app['debug']がtrueの際は処理を行わない |
981
|
|
|
* @return boolean true |
982
|
|
|
* |
983
|
|
|
*/ |
984
|
936 |
|
protected function checkDatabaseConnection() |
985
|
|
|
{ |
986
|
936 |
|
if ($this['debug']) { |
987
|
933 |
|
return; |
988
|
|
|
} |
989
|
|
|
try { |
990
|
3 |
|
$this['db']->connect(); |
991
|
|
|
} catch (\Doctrine\DBAL\DBALException $e) { |
992
|
|
|
$this['monolog']->error($e->getMessage()); |
993
|
|
|
$this['twig.path'] = array(__DIR__.'/Resource/template/exception'); |
994
|
|
|
$html = $this['twig']->render('error.twig', array( |
995
|
|
|
'error_title' => 'データーベース接続エラー', |
996
|
|
|
'error_message' => 'データーベースを確認してください', |
997
|
|
|
)); |
998
|
|
|
$response = new Response(); |
999
|
|
|
$response->setContent($html); |
1000
|
|
|
$response->setStatusCode('500'); |
1001
|
|
|
$response->headers->set('Content-Type', 'text/html'); |
1002
|
|
|
$response->send(); |
1003
|
|
|
die(); |
|
|
|
|
1004
|
|
|
} |
1005
|
3 |
|
return true; |
|
|
|
|
1006
|
|
|
} |
1007
|
|
|
} |
1008
|
|
|
|