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