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