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 Symfony\Component\EventDispatcher\EventDispatcher; |
29
|
|
|
use Symfony\Component\Finder\Finder; |
30
|
|
|
use Symfony\Component\HttpFoundation\Request; |
31
|
|
|
use Symfony\Component\HttpFoundation\Response; |
32
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; |
33
|
|
|
use Symfony\Component\Yaml\Yaml; |
34
|
|
|
|
35
|
|
|
class Application extends ApplicationTrait |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
protected static $instance; |
38
|
|
|
|
39
|
|
|
protected $initialized = false; |
40
|
|
|
protected $initializedPlugin = false; |
41
|
|
|
|
42
|
697 |
|
public static function getInstance(array $values = array()) |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
if (!is_object(self::$instance)) { |
45
|
|
|
self::$instance = new Application($values); |
46
|
|
|
} |
47
|
|
|
|
48
|
697 |
|
return self::$instance; |
49
|
697 |
|
} |
50
|
|
|
|
51
|
697 |
|
public static function clearInstance() |
|
|
|
|
52
|
|
|
{ |
53
|
697 |
|
self::$instance = null; |
54
|
697 |
|
} |
55
|
|
|
|
56
|
|
|
final public function __clone() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
throw new \Exception('Clone is not allowed against' . get_class($this)); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
697 |
|
public function __construct(array $values = array()) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
parent::__construct($values); |
64
|
|
|
|
65
|
|
|
if (is_null(self::$instance)) { |
66
|
697 |
|
self::$instance = $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// load config |
70
|
|
|
$this->initConfig(); |
71
|
|
|
|
72
|
|
|
// init monolog |
73
|
|
|
$this->initLogger(); |
74
|
|
|
} |
75
|
|
|
|
76
|
711 |
|
public function initConfig() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
// load config |
79
|
|
|
$this['config'] = $this->share(function() { |
80
|
700 |
|
$ymlPath = __DIR__.'/../../app/config/eccube'; |
81
|
700 |
|
$distPath = __DIR__.'/../../src/Eccube/Resource/config'; |
82
|
|
|
|
83
|
700 |
|
$config = array(); |
84
|
700 |
|
$config_yml = $ymlPath.'/config.yml'; |
85
|
|
|
if (file_exists($config_yml)) { |
86
|
|
|
$config = Yaml::parse(file_get_contents($config_yml)); |
87
|
|
|
} |
88
|
|
|
|
89
|
700 |
|
$config_dist = array(); |
90
|
700 |
|
$config_yml_dist = $distPath.'/config.yml.dist'; |
91
|
|
|
if (file_exists($config_yml_dist)) { |
92
|
|
|
$config_dist = Yaml::parse(file_get_contents($config_yml_dist)); |
93
|
|
|
} |
94
|
|
|
|
95
|
700 |
|
$config_path = array(); |
96
|
700 |
|
$path_yml = $ymlPath.'/path.yml'; |
97
|
|
|
if (file_exists($path_yml)) { |
98
|
|
|
$config_path = Yaml::parse(file_get_contents($path_yml)); |
99
|
|
|
} |
100
|
|
|
|
101
|
700 |
|
$config_constant = array(); |
102
|
700 |
|
$constant_yml = $ymlPath.'/constant.yml'; |
103
|
|
|
if (file_exists($constant_yml)) { |
104
|
|
|
$config_constant = Yaml::parse(file_get_contents($constant_yml)); |
105
|
|
|
$config_constant = empty($config_constant) ? array() : $config_constant; |
106
|
|
|
} |
107
|
|
|
|
108
|
700 |
|
$config_constant_dist = array(); |
109
|
700 |
|
$constant_yml_dist = $distPath.'/constant.yml.dist'; |
110
|
|
|
if (file_exists($constant_yml_dist)) { |
111
|
|
|
$config_constant_dist = Yaml::parse(file_get_contents($constant_yml_dist)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$configAll = array_replace_recursive($config_constant_dist, $config_dist, $config_constant, $config_path, $config); |
115
|
|
|
|
116
|
700 |
|
$database = array(); |
117
|
700 |
|
$yml = $ymlPath.'/database.yml'; |
118
|
|
|
if (file_exists($yml)) { |
119
|
|
|
$database = Yaml::parse(file_get_contents($yml)); |
120
|
|
|
} |
121
|
|
|
|
122
|
700 |
|
$mail = array(); |
123
|
700 |
|
$yml = $ymlPath.'/mail.yml'; |
124
|
|
|
if (file_exists($yml)) { |
125
|
|
|
$mail = Yaml::parse(file_get_contents($yml)); |
126
|
|
|
} |
127
|
|
|
$configAll = array_replace_recursive($configAll, $database, $mail); |
128
|
|
|
|
129
|
700 |
|
$config_log = array(); |
130
|
700 |
|
$yml = $ymlPath.'/log.yml'; |
131
|
|
|
if (file_exists($yml)) { |
132
|
|
|
$config_log = Yaml::parse(file_get_contents($yml)); |
133
|
|
|
} |
134
|
700 |
|
$config_log_dist = array(); |
135
|
700 |
|
$log_yml_dist = $distPath.'/log.yml.dist'; |
136
|
|
|
if (file_exists($log_yml_dist)) { |
137
|
|
|
$config_log_dist = Yaml::parse(file_get_contents($log_yml_dist)); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$configAll = array_replace_recursive($configAll, $config_log_dist, $config_log); |
141
|
|
|
|
142
|
700 |
|
$config_nav = array(); |
143
|
700 |
|
$yml = $ymlPath.'/nav.yml'; |
144
|
|
|
if (file_exists($yml)) { |
145
|
|
|
$config_nav = array('nav' => Yaml::parse(file_get_contents($yml))); |
146
|
|
|
} |
147
|
700 |
|
$config_nav_dist = array(); |
148
|
700 |
|
$nav_yml_dist = $distPath.'/nav.yml.dist'; |
149
|
|
|
if (file_exists($nav_yml_dist)) { |
150
|
|
|
$config_nav_dist = array('nav' => Yaml::parse(file_get_contents($nav_yml_dist))); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$configAll = array_replace_recursive($configAll, $config_nav_dist, $config_nav); |
154
|
|
|
|
155
|
700 |
|
return $configAll; |
156
|
|
|
}); |
157
|
711 |
|
} |
158
|
|
|
|
159
|
711 |
|
public function initLogger() |
|
|
|
|
160
|
|
|
{ |
161
|
711 |
|
$app = $this; |
162
|
|
|
$this->register(new ServiceProvider\EccubeMonologServiceProvider($app)); |
|
|
|
|
163
|
|
|
$this['monolog.logfile'] = __DIR__.'/../../app/log/site.log'; |
164
|
|
|
$this['monolog.name'] = 'eccube'; |
165
|
711 |
|
} |
166
|
|
|
|
167
|
697 |
|
public function initialize() |
|
|
|
|
168
|
|
|
{ |
169
|
697 |
|
if ($this->initialized) { |
170
|
|
|
return; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// init locale |
174
|
|
|
$this->initLocale(); |
175
|
|
|
|
176
|
|
|
// init session |
177
|
|
|
$this->initSession(); |
178
|
|
|
|
179
|
|
|
// init twig |
180
|
|
|
$this->initRendering(); |
181
|
|
|
|
182
|
|
|
// init provider |
183
|
|
|
$this->register(new \Silex\Provider\HttpFragmentServiceProvider()); |
184
|
|
|
$this->register(new \Silex\Provider\UrlGeneratorServiceProvider()); |
185
|
|
|
$this->register(new \Silex\Provider\FormServiceProvider()); |
186
|
|
|
$this->register(new \Silex\Provider\SerializerServiceProvider()); |
187
|
|
|
$this->register(new \Eccube\ServiceProvider\ValidatorServiceProvider()); |
188
|
|
|
|
189
|
697 |
|
$app = $this; |
190
|
|
|
$this->error(function(\Exception $e, $code) use ($app) { |
191
|
|
|
if ($app['debug']) { |
192
|
5 |
|
return; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
switch ($code) { |
196
|
|
|
case 403: |
197
|
|
|
$title = 'アクセスできません。'; |
198
|
|
|
$message = 'お探しのページはアクセスができない状況にあるか、移動もしくは削除された可能性があります。'; |
199
|
|
|
break; |
200
|
|
|
case 404: |
201
|
|
|
$title = 'ページがみつかりません。'; |
202
|
|
|
$message = 'URLに間違いがないかご確認ください。'; |
203
|
|
|
break; |
204
|
|
|
default: |
205
|
|
|
$title = 'システムエラーが発生しました。'; |
206
|
|
|
$message = '大変お手数ですが、サイト管理者までご連絡ください。'; |
207
|
|
|
break; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
return $app['twig']->render('error.twig', array( |
211
|
|
|
'error_title' => $title, |
212
|
|
|
'error_message' => $message, |
213
|
|
|
)); |
214
|
|
|
}); |
215
|
|
|
|
216
|
|
|
// init mailer |
217
|
|
|
$this->initMailer(); |
218
|
|
|
|
219
|
|
|
// init doctrine orm |
220
|
|
|
$this->initDoctrine(); |
221
|
|
|
|
222
|
|
|
// init security |
223
|
|
|
$this->initSecurity(); |
224
|
|
|
|
225
|
|
|
// init ec-cube service provider |
226
|
|
|
$this->register(new ServiceProvider\EccubeServiceProvider()); |
227
|
|
|
|
228
|
|
|
// mount controllers |
229
|
|
|
$this->register(new \Silex\Provider\ServiceControllerServiceProvider()); |
230
|
|
|
$this->mount('', new ControllerProvider\FrontControllerProvider()); |
231
|
|
|
$this->mount('/'.trim($this['config']['admin_route'], '/').'/', new ControllerProvider\AdminControllerProvider()); |
232
|
|
|
Request::enableHttpMethodParameterOverride(); // PUTやDELETEできるようにする |
233
|
|
|
|
234
|
697 |
|
$this->initialized = true; |
235
|
697 |
|
} |
236
|
|
|
|
237
|
697 |
|
public function initLocale() |
|
|
|
|
238
|
|
|
{ |
239
|
|
|
|
240
|
|
|
// timezone |
241
|
|
|
if (!empty($this['config']['timezone'])) { |
242
|
|
|
date_default_timezone_set($this['config']['timezone']); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$this->register(new \Silex\Provider\TranslationServiceProvider(), array( |
246
|
697 |
|
'locale' => $this['config']['locale'], |
247
|
|
|
)); |
248
|
|
|
$this['translator'] = $this->share($this->extend('translator', function($translator, \Silex\Application $app) { |
249
|
|
|
$translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader()); |
250
|
|
|
|
251
|
|
|
$r = new \ReflectionClass('Symfony\Component\Validator\Validator'); |
252
|
|
|
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf'; |
253
|
|
|
if (file_exists($file)) { |
254
|
|
|
$translator->addResource('xliff', $file, $app['locale'], 'validators'); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
$file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml'; |
258
|
|
|
if (file_exists($file)) { |
259
|
|
|
$translator->addResource('yaml', $file, $app['locale'], 'validators'); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
$file = __DIR__.'/Resource/locale/message.'.$app['locale'].'.yml'; |
263
|
|
|
if (file_exists($file)) { |
264
|
|
|
$translator->addResource('yaml', $file, $app['locale']); |
265
|
|
|
} |
266
|
|
|
|
267
|
372 |
|
return $translator; |
268
|
|
|
})); |
269
|
697 |
|
} |
270
|
|
|
|
271
|
697 |
|
public function initSession() |
|
|
|
|
272
|
|
|
{ |
273
|
|
|
$this->register(new \Silex\Provider\SessionServiceProvider(), array( |
274
|
|
|
'session.storage.options' => array( |
275
|
697 |
|
'name' => 'eccube', |
276
|
|
|
'cookie_path' => $this['config']['root_urlpath'] ?: '/', |
277
|
697 |
|
'cookie_secure' => $this['config']['force_ssl'], |
278
|
697 |
|
'cookie_lifetime' => $this['config']['cookie_lifetime'], |
279
|
697 |
|
'cookie_httponly' => true, |
280
|
|
|
// cookie_domainは指定しない |
281
|
|
|
// http://blog.tokumaru.org/2011/10/cookiedomain.html |
282
|
697 |
|
), |
283
|
|
|
)); |
284
|
697 |
|
$this['session.db_options'] = array( |
285
|
|
|
'db_table' => 'dtb_session', |
286
|
|
|
); |
287
|
|
|
|
288
|
697 |
|
$app = $this; |
289
|
|
|
$this['session.storage.handler'] = function() use ($app) { |
290
|
|
|
return new PdoSessionHandler( |
291
|
|
|
$app['dbs']['session']->getWrappedConnection(), |
292
|
|
|
$app['session.db_options'] |
293
|
|
|
); |
294
|
|
|
}; |
295
|
697 |
|
} |
296
|
|
|
|
297
|
697 |
|
public function initRendering() |
|
|
|
|
298
|
|
|
{ |
299
|
|
|
$this->register(new \Silex\Provider\TwigServiceProvider(), array( |
300
|
|
|
'twig.form.templates' => array('Form/form_layout.twig'), |
301
|
|
|
)); |
302
|
|
|
$this['twig'] = $this->share($this->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) { |
303
|
|
|
$twig->addExtension(new \Eccube\Twig\Extension\EccubeExtension($app)); |
304
|
|
|
$twig->addExtension(new \Twig_Extension_StringLoader()); |
305
|
|
|
|
306
|
132 |
|
return $twig; |
307
|
|
|
})); |
308
|
|
|
|
309
|
|
|
$this->before(function(Request $request, \Silex\Application $app) { |
310
|
|
|
// フロント or 管理画面ごとにtwigの探索パスを切り替える. |
311
|
|
|
$app['twig'] = $app->share($app->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) { |
312
|
101 |
|
$paths = array(); |
313
|
|
|
|
314
|
|
|
// 互換性がないのでprofiler とproduction 時のcacheを分離する |
315
|
|
|
|
316
|
|
|
if (isset($app['profiler'])) { |
317
|
|
|
$cacheBaseDir = __DIR__.'/../../app/cache/twig/profiler/'; |
318
|
|
|
} else { |
319
|
101 |
|
$cacheBaseDir = __DIR__.'/../../app/cache/twig/production/'; |
320
|
|
|
} |
321
|
|
|
if (strpos($app['request']->getPathInfo(), '/'.trim($app['config']['admin_route'], '/')) === 0) { |
322
|
|
|
if (file_exists(__DIR__.'/../../app/template/admin')) { |
323
|
55 |
|
$paths[] = __DIR__.'/../../app/template/admin'; |
324
|
|
|
} |
325
|
|
|
$paths[] = $app['config']['template_admin_realdir']; |
326
|
55 |
|
$paths[] = __DIR__.'/../../app/Plugin'; |
327
|
55 |
|
$cache = $cacheBaseDir.'admin'; |
328
|
|
|
} else { |
329
|
|
|
if (file_exists($app['config']['template_realdir'])) { |
330
|
|
|
$paths[] = $app['config']['template_realdir']; |
331
|
|
|
} |
332
|
|
|
$paths[] = $app['config']['template_default_realdir']; |
333
|
46 |
|
$paths[] = __DIR__.'/../../app/Plugin'; |
334
|
|
|
$cache = $cacheBaseDir.$app['config']['template_code']; |
335
|
55 |
|
} |
336
|
|
|
$twig->setCache($cache); |
337
|
|
|
$app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($paths)); |
338
|
|
|
|
339
|
101 |
|
return $twig; |
340
|
|
|
})); |
341
|
|
|
|
342
|
|
|
// 管理画面のIP制限チェック. |
343
|
|
|
if (strpos($app['request']->getPathInfo(), '/'.trim($app['config']['admin_route'], '/')) === 0) { |
344
|
|
|
// IP制限チェック |
345
|
|
|
$allowHost = $app['config']['admin_allow_host']; |
346
|
|
|
if (count($allowHost) > 0) { |
347
|
|
|
if (array_search($app['request']->getClientIp(), $allowHost) === false) { |
348
|
|
|
throw new \Exception(); |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
}, self::EARLY_EVENT); |
353
|
|
|
|
354
|
|
|
// twigのグローバル変数を定義. |
355
|
697 |
|
$app = $this; |
356
|
|
|
$this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) { |
357
|
|
|
// ショップ基本情報 |
358
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
359
|
|
|
$app['twig']->addGlobal('BaseInfo', $BaseInfo); |
360
|
|
|
|
361
|
|
|
if (strpos($app['request']->getPathInfo(), '/'.trim($app['config']['admin_route'], '/')) === 0) { |
362
|
|
|
// 管理画面 |
363
|
|
|
// 管理画面メニュー |
364
|
55 |
|
$menus = array('', '', ''); |
365
|
|
|
$app['twig']->addGlobal('menus', $menus); |
366
|
|
|
|
367
|
|
|
$Member = $app->user(); |
368
|
|
|
if (is_object($Member)) { |
369
|
|
|
// ログインしていれば管理者のロールを取得 |
370
|
|
|
$AuthorityRoles = $app['eccube.repository.authority_role']->findBy(array('Authority' => $Member->getAuthority())); |
371
|
|
|
|
372
|
52 |
|
$roles = array(); |
373
|
|
|
foreach ($AuthorityRoles as $AuthorityRole) { |
374
|
|
|
// 管理画面でメニュー制御するため相対パス全てをセット |
375
|
|
|
$roles[] = $app['request']->getBaseUrl() . '/' . $app['config']['admin_route'] . $AuthorityRole->getDenyUrl(); |
|
|
|
|
376
|
52 |
|
} |
377
|
|
|
|
378
|
|
|
$app['twig']->addGlobal('AuthorityRoles', $roles); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
} else { |
382
|
|
|
// フロント画面 |
383
|
|
|
$request = $event->getRequest(); |
384
|
|
|
$route = $request->attributes->get('_route'); |
385
|
|
|
|
386
|
|
|
// ユーザ作成画面 |
387
|
|
|
if ($route === trim($app['config']['user_data_route'])) { |
388
|
|
|
$params = $request->attributes->get('_route_params'); |
389
|
2 |
|
$route = $params['route']; |
390
|
|
|
// プレビュー画面 |
391
|
|
|
} elseif ($request->get('preview')) { |
392
|
|
|
$route = 'preview'; |
393
|
2 |
|
} |
394
|
|
|
|
395
|
|
|
try { |
396
|
|
|
$DeviceType = $app['eccube.repository.master.device_type'] |
397
|
|
|
->find(\Eccube\Entity\Master\DeviceType::DEVICE_TYPE_PC); |
398
|
|
|
$PageLayout = $app['eccube.repository.page_layout']->getByUrl($DeviceType, $route); |
399
|
|
|
} catch (\Doctrine\ORM\NoResultException $e) { |
400
|
|
|
$PageLayout = $app['eccube.repository.page_layout']->newPageLayout($DeviceType); |
401
|
23 |
|
} |
402
|
|
|
|
403
|
|
|
$app['twig']->addGlobal('PageLayout', $PageLayout); |
404
|
|
|
$app['twig']->addGlobal('title', $PageLayout->getName()); |
405
|
55 |
|
} |
406
|
|
|
}); |
407
|
697 |
|
} |
408
|
|
|
|
409
|
697 |
|
public function initMailer() |
|
|
|
|
410
|
|
|
{ |
411
|
|
|
|
412
|
|
|
// メール送信時の文字エンコード指定(デフォルトはUTF-8) |
|
|
|
|
413
|
|
|
if (isset($this['config']['mail']['charset_iso_2022_jp']) && is_bool($this['config']['mail']['charset_iso_2022_jp'])) { |
414
|
|
|
if ($this['config']['mail']['charset_iso_2022_jp'] === true) { |
415
|
|
|
\Swift::init(function() { |
416
|
|
|
\Swift_DependencyContainer::getInstance() |
417
|
|
|
->register('mime.qpheaderencoder') |
418
|
|
|
->asAliasOf('mime.base64headerencoder'); |
419
|
|
|
\Swift_Preferences::getInstance()->setCharset('iso-2022-jp'); |
420
|
|
|
}); |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
$this->register(new \Silex\Provider\SwiftmailerServiceProvider()); |
425
|
|
|
$this['swiftmailer.options'] = $this['config']['mail']; |
426
|
|
|
|
427
|
|
|
if (isset($this['config']['mail']['spool']) && is_bool($this['config']['mail']['spool'])) { |
428
|
|
|
$this['swiftmailer.use_spool'] = $this['config']['mail']['spool']; |
429
|
|
|
} |
430
|
|
|
// デフォルトはsmtpを使用 |
431
|
|
|
$transport = $this['config']['mail']['transport']; |
432
|
697 |
|
if ($transport == 'sendmail') { |
433
|
|
|
$this['swiftmailer.transport'] = \Swift_SendmailTransport::newInstance(); |
434
|
697 |
|
} elseif ($transport == 'mail') { |
435
|
|
|
$this['swiftmailer.transport'] = \Swift_MailTransport::newInstance(); |
436
|
|
|
} |
437
|
697 |
|
} |
438
|
|
|
|
439
|
697 |
|
public function initDoctrine() |
|
|
|
|
440
|
|
|
{ |
441
|
|
|
$this->register(new \Silex\Provider\DoctrineServiceProvider(), array( |
|
|
|
|
442
|
|
|
'dbs.options' => array( |
443
|
697 |
|
'default' => $this['config']['database'], |
444
|
697 |
|
'session' => $this['config']['database'], |
445
|
|
|
))); |
|
|
|
|
446
|
|
|
$this->register(new \Saxulum\DoctrineOrmManagerRegistry\Silex\Provider\DoctrineOrmManagerRegistryProvider()); |
|
|
|
|
447
|
|
|
|
448
|
|
|
// プラグインのmetadata定義を合わせて行う. |
449
|
697 |
|
$pluginBasePath = __DIR__.'/../../app/Plugin'; |
|
|
|
|
450
|
696 |
|
$finder = Finder::create() |
|
|
|
|
451
|
697 |
|
->in($pluginBasePath) |
452
|
697 |
|
->directories() |
453
|
|
|
->depth(0); |
454
|
|
|
|
455
|
697 |
|
$ormMappings = array(); |
|
|
|
|
456
|
|
|
$ormMappings[] = array( |
|
|
|
|
457
|
697 |
|
'type' => 'yml', |
458
|
697 |
|
'namespace' => 'Eccube\Entity', |
459
|
|
|
'path' => array( |
460
|
697 |
|
__DIR__.'/Resource/doctrine', |
461
|
697 |
|
__DIR__.'/Resource/doctrine/master', |
462
|
697 |
|
), |
463
|
697 |
|
); |
464
|
|
|
|
465
|
|
|
foreach ($finder as $dir) { |
466
|
|
|
$config = Yaml::parse(file_get_contents($dir->getRealPath().'/config.yml')); |
467
|
|
|
|
468
|
|
|
// Doctrine Extend |
469
|
|
|
if (isset($config['orm.path']) && is_array($config['orm.path'])) { |
470
|
|
|
$paths = array(); |
471
|
|
|
foreach ($config['orm.path'] as $path) { |
472
|
|
|
$paths[] = $pluginBasePath.'/'.$config['code'].$path; |
473
|
|
|
} |
474
|
|
|
$ormMappings[] = array( |
475
|
|
|
'type' => 'yml', |
476
|
|
|
'namespace' => 'Plugin\\'.$config['code'].'\\Entity', |
477
|
|
|
'path' => $paths, |
478
|
|
|
); |
479
|
|
|
} |
480
|
697 |
|
} |
481
|
|
|
|
482
|
|
|
$this->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array( |
483
|
697 |
|
'orm.proxies_dir' => __DIR__.'/../../app/cache/doctrine', |
484
|
|
|
'orm.em.options' => array( |
485
|
|
|
'mappings' => $ormMappings, |
486
|
697 |
|
), |
487
|
|
|
)); |
488
|
697 |
|
} |
489
|
|
|
|
490
|
697 |
|
public function initSecurity() |
|
|
|
|
491
|
|
|
{ |
492
|
|
|
$this->register(new \Silex\Provider\SecurityServiceProvider()); |
493
|
|
|
$this->register(new \Silex\Provider\RememberMeServiceProvider()); |
494
|
|
|
|
495
|
697 |
|
$this['security.firewalls'] = array( |
496
|
|
|
'admin' => array( |
497
|
|
|
'pattern' => "^/{$this['config']['admin_route']}", |
498
|
|
|
'form' => array( |
499
|
|
|
'login_path' => "/{$this['config']['admin_route']}/login", |
500
|
|
|
'check_path' => "/{$this['config']['admin_route']}/login_check", |
501
|
697 |
|
'username_parameter' => 'login_id', |
502
|
697 |
|
'password_parameter' => 'password', |
503
|
697 |
|
'with_csrf' => true, |
504
|
697 |
|
'use_forward' => true, |
505
|
697 |
|
), |
506
|
|
|
'logout' => array( |
507
|
|
|
'logout_path' => "/{$this['config']['admin_route']}/logout", |
508
|
|
|
'target_url' => "/{$this['config']['admin_route']}/", |
509
|
697 |
|
), |
510
|
|
|
'users' => $this['orm.em']->getRepository('Eccube\Entity\Member'), |
511
|
697 |
|
'anonymous' => true, |
512
|
|
|
), |
513
|
|
|
'customer' => array( |
514
|
697 |
|
'pattern' => '^/', |
515
|
|
|
'form' => array( |
516
|
|
|
'login_path' => '/mypage/login', |
517
|
|
|
'check_path' => '/login_check', |
518
|
|
|
'username_parameter' => 'login_email', |
519
|
|
|
'password_parameter' => 'login_pass', |
520
|
|
|
'with_csrf' => true, |
521
|
|
|
'use_forward' => true, |
522
|
697 |
|
), |
523
|
|
|
'logout' => array( |
524
|
|
|
'logout_path' => '/logout', |
525
|
|
|
'target_url' => '/', |
526
|
697 |
|
), |
527
|
|
|
'remember_me' => array( |
528
|
|
|
'key' => sha1($this['config']['auth_magic']), |
529
|
697 |
|
'name' => 'eccube_rememberme', |
530
|
|
|
// lifetimeはデフォルトの1年間にする |
531
|
|
|
// 'lifetime' => $this['config']['cookie_lifetime'], |
|
|
|
|
532
|
|
|
'path' => $this['config']['root_urlpath'] ?: '/', |
533
|
697 |
|
'secure' => $this['config']['force_ssl'], |
534
|
697 |
|
'httponly' => true, |
535
|
697 |
|
'always_remember_me' => false, |
536
|
697 |
|
'remember_me_parameter' => 'login_memory', |
537
|
|
|
), |
538
|
|
|
'users' => $this['orm.em']->getRepository('Eccube\Entity\Customer'), |
539
|
697 |
|
'anonymous' => true, |
540
|
|
|
), |
541
|
|
|
); |
542
|
|
|
|
543
|
697 |
|
$this['security.access_rules'] = array( |
544
|
|
|
array("^/{$this['config']['admin_route']}/login", 'IS_AUTHENTICATED_ANONYMOUSLY'), |
545
|
|
|
array("^/{$this['config']['admin_route']}", 'ROLE_ADMIN'), |
546
|
697 |
|
array('^/mypage/login', 'IS_AUTHENTICATED_ANONYMOUSLY'), |
547
|
697 |
|
array('^/mypage/withdraw_complete', 'IS_AUTHENTICATED_ANONYMOUSLY'), |
548
|
697 |
|
array('^/mypage/change', 'IS_AUTHENTICATED_FULLY'), |
549
|
697 |
|
array('^/mypage', 'ROLE_USER'), |
550
|
|
|
); |
551
|
|
|
|
552
|
|
|
$this['eccube.password_encoder'] = $this->share(function($app) { |
553
|
|
|
return new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']); |
554
|
|
|
}); |
555
|
|
|
$this['security.encoder_factory'] = $this->share(function($app) { |
556
|
|
|
return new \Symfony\Component\Security\Core\Encoder\EncoderFactory(array( |
557
|
697 |
|
'Eccube\Entity\Customer' => $app['eccube.password_encoder'], |
558
|
697 |
|
'Eccube\Entity\Member' => $app['eccube.password_encoder'], |
559
|
|
|
)); |
560
|
|
|
}); |
561
|
|
|
$this['eccube.event_listner.security'] = $this->share(function($app) { |
562
|
|
|
return new \Eccube\EventListener\SecurityEventListener($app['orm.em']); |
563
|
|
|
}); |
564
|
|
|
$this['user'] = $this->share(function($app) { |
565
|
|
|
$token = $app['security']->getToken(); |
566
|
|
|
|
567
|
|
|
return ($token !== null) ? $token->getUser() : null; |
568
|
|
|
}); |
569
|
|
|
|
570
|
|
|
// ログイン時のイベントを設定. |
571
|
|
|
$this['dispatcher']->addListener(\Symfony\Component\Security\Http\SecurityEvents::INTERACTIVE_LOGIN, array($this['eccube.event_listner.security'], 'onInteractiveLogin')); |
572
|
|
|
|
573
|
|
|
// Voterの設定 |
574
|
697 |
|
$app = $this; |
575
|
|
|
$this['authority_voter'] = $this->share(function($app) { |
576
|
|
|
return new \Eccube\Security\Voter\AuthorityVoter($app); |
577
|
|
|
}); |
578
|
|
|
|
579
|
|
|
$app['security.voters'] = $app->extend('security.voters', function($voters) use ($app) { |
580
|
|
|
$voters[] = $app['authority_voter']; |
581
|
|
|
|
582
|
697 |
|
return $voters; |
583
|
|
|
}); |
584
|
|
|
|
585
|
|
|
$this['security.access_manager'] = $this->share(function($app) { |
586
|
|
|
return new \Symfony\Component\Security\Core\Authorization\AccessDecisionManager($app['security.voters'], 'unanimous'); |
587
|
|
|
}); |
588
|
|
|
|
589
|
697 |
|
} |
590
|
|
|
|
591
|
|
|
public function initializePlugin() |
|
|
|
|
592
|
|
|
{ |
593
|
|
|
if (!$this->initializedPlugin) { |
594
|
|
|
return; |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
// setup event dispatcher |
598
|
|
|
$this->initPluginEventDispatcher(); |
599
|
|
|
|
600
|
|
|
// load plugin |
601
|
|
|
$this->loadPlugin(); |
602
|
|
|
|
603
|
|
|
$this->initializedPlugin = true; |
604
|
|
|
} |
605
|
|
|
|
606
|
697 |
|
public function initPluginEventDispatcher() |
|
|
|
|
607
|
|
|
{ |
608
|
|
|
// EventDispatcher |
609
|
|
|
$this['eccube.event.dispatcher'] = $this->share(function() { |
610
|
|
|
return new EventDispatcher(); |
611
|
|
|
}); |
612
|
|
|
|
613
|
|
|
// hook point |
614
|
|
|
$this->before(function(Request $request, \Silex\Application $app) { |
615
|
|
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.before'); |
616
|
|
|
}, self::EARLY_EVENT); |
617
|
|
|
|
618
|
|
|
$this->before(function(Request $request, \Silex\Application $app) { |
619
|
|
|
$event = 'eccube.event.controller.'.$request->attributes->get('_route').'.before'; |
620
|
|
|
$app['eccube.event.dispatcher']->dispatch($event); |
621
|
|
|
}); |
622
|
|
|
|
623
|
|
View Code Duplication |
$this->after(function(Request $request, Response $response, \Silex\Application $app) { |
|
|
|
|
624
|
|
|
$event = 'eccube.event.controller.'.$request->attributes->get('_route').'.after'; |
625
|
|
|
$app['eccube.event.dispatcher']->dispatch($event); |
626
|
|
|
}); |
627
|
|
|
|
628
|
|
|
$this->after(function(Request $request, Response $response, \Silex\Application $app) { |
629
|
|
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.app.after'); |
630
|
|
|
}, self::LATE_EVENT); |
631
|
|
|
|
632
|
|
View Code Duplication |
$this->finish(function(Request $request, Response $response, \Silex\Application $app) { |
|
|
|
|
633
|
|
|
$event = 'eccube.event.controller.'.$request->attributes->get('_route').'.finish'; |
634
|
|
|
$app['eccube.event.dispatcher']->dispatch($event); |
635
|
|
|
}); |
636
|
|
|
|
637
|
697 |
|
$app = $this; |
638
|
|
|
$this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) { |
639
|
|
|
$route = $event->getRequest()->attributes->get('_route'); |
640
|
|
|
$app['eccube.event.dispatcher']->dispatch('eccube.event.render.'.$route.'.before', $event); |
641
|
|
|
}); |
642
|
697 |
|
} |
643
|
|
|
|
644
|
|
|
public function loadPlugin() |
|
|
|
|
645
|
|
|
{ |
646
|
|
|
// プラグインディレクトリを探索. |
647
|
|
|
$basePath = __DIR__.'/../../app/Plugin'; |
648
|
|
|
$finder = Finder::create() |
649
|
|
|
->in($basePath) |
650
|
|
|
->directories() |
651
|
|
|
->depth(0); |
652
|
|
|
|
653
|
|
|
$finder->sortByName(); |
654
|
|
|
|
655
|
|
|
// ハンドラ優先順位をdbから持ってきてハッシュテーブルを作成 |
656
|
|
|
$priorities = array(); |
657
|
|
|
$handlers = $this['orm.em'] |
658
|
|
|
->getRepository('Eccube\Entity\PluginEventHandler') |
659
|
|
|
->getHandlers(); |
660
|
|
|
foreach ($handlers as $handler) { |
661
|
|
|
if ($handler->getPlugin()->getEnable() && !$handler->getPlugin()->getDelFlg()) { |
662
|
|
|
$priority = $handler->getPriority(); |
663
|
|
|
} else { |
664
|
|
|
// Pluginがdisable、削除済みの場合、EventHandlerのPriorityを全て0とみなす |
665
|
|
|
$priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED; |
666
|
|
|
} |
667
|
|
|
$priorities[$handler->getPlugin()->getClassName()][$handler->getEvent()][$handler->getHandler()] = $priority; |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
// プラグインをロードする. |
671
|
|
|
// config.yml/event.ymlの定義に沿ってインスタンスの生成を行い, イベント設定を行う. |
672
|
|
|
foreach ($finder as $dir) { |
673
|
|
|
//config.ymlのないディレクトリは無視する |
674
|
|
|
if (!file_exists($dir->getRealPath().'/config.yml')) { |
675
|
|
|
continue; |
676
|
|
|
} |
677
|
|
|
$config = Yaml::parse(file_get_contents($dir->getRealPath().'/config.yml')); |
678
|
|
|
|
679
|
|
|
$plugin = $this['orm.em'] |
680
|
|
|
->getRepository('Eccube\Entity\Plugin') |
681
|
|
|
->findOneBy(array('code' => $config['code'])); |
682
|
|
|
|
683
|
|
|
// const |
684
|
|
|
if (isset($config['const'])) { |
685
|
|
|
$this['config'] = $this->share($this->extend('config', function($eccubeConfig) use ($config) { |
686
|
|
|
$eccubeConfig[$config['code']] = array( |
687
|
|
|
'const' => $config['const'], |
688
|
|
|
); |
689
|
|
|
|
690
|
|
|
return $eccubeConfig; |
691
|
|
|
})); |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
if ($plugin && $plugin->getEnable() == Constant::DISABLED) { |
695
|
|
|
// プラグインが無効化されていれば読み込まない |
696
|
|
|
continue; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
// Type: Event |
700
|
|
|
if (isset($config['event'])) { |
701
|
|
|
$class = '\\Plugin\\'.$config['code'].'\\'.$config['event']; |
702
|
|
|
$subscriber = new $class($this); |
703
|
|
|
|
704
|
|
|
if (file_exists($dir->getRealPath().'/event.yml')) { |
705
|
|
|
foreach (Yaml::parse(file_get_contents($dir->getRealPath().'/event.yml')) as $event => $handlers) { |
|
|
|
|
706
|
|
|
foreach ($handlers as $handler) { |
707
|
|
|
if (!isset($priorities[$config['event']][$event][$handler[0]])) { // ハンドラテーブルに登録されていない(ソースにしか記述されていない)ハンドラは一番後ろにする |
708
|
|
|
$priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_LATEST; |
709
|
|
|
} else { |
710
|
|
|
$priority = $priorities[$config['event']][$event][$handler[0]]; |
711
|
|
|
} |
712
|
|
|
// 優先度が0のプラグインは登録しない |
713
|
|
|
if (\Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED != $priority) { |
714
|
|
|
$this['eccube.event.dispatcher']->addListener($event, array($subscriber, $handler[0]), $priority); |
715
|
|
|
} |
716
|
|
|
} |
717
|
|
|
} |
718
|
|
|
} |
719
|
|
|
} |
720
|
|
|
// Type: ServiceProvider |
721
|
|
|
if (isset($config['service'])) { |
722
|
|
|
foreach ($config['service'] as $service) { |
723
|
|
|
$class = '\\Plugin\\'.$config['code'].'\\ServiceProvider\\'.$service; |
724
|
|
|
$this->register(new $class($this)); |
725
|
|
|
} |
726
|
|
|
} |
727
|
|
|
} |
728
|
|
|
} |
729
|
|
|
} |
730
|
|
|
|