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