Failed Conditions
Pull Request — master (#1695)
by Kentaro
23:25
created

Application::parseConfig()   D

Complexity

Conditions 13
Paths 192

Size

Total Lines 41
Code Lines 29

Duplication

Lines 6
Ratio 14.63 %

Code Coverage

Tests 6
CRAP Score 23.816

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 6
loc 41
ccs 6
cts 10
cp 0.6
rs 4.8178
cc 13
eloc 29
nc 192
nop 5
crap 23.816

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
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())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
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()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
58
    {
59 933
        self::$instance = null;
60
    }
61
62
    final public function __clone()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
63
    {
64
        throw new \Exception('Clone is not allowed against '.get_class($this));
65
    }
66
67 946
    public function __construct(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
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()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
83
    {
84
        // load config
85
        $app = $this;
86 939
        $this['config'] = $this->share(function() use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
87 939
            $configAll = array();
88
            $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
                ->parseConfig('log', $configAll)
94
                ->parseConfig('nav', $configAll, true)
95 939
                ->parseConfig('doctrine_cache', $configAll);
96 939
            return $configAll;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
97 939
        });
98 939
    }
99
100
    public function initLogger()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
101 939
    {
102 939
        $app = $this;
103 939
        $this->register(new ServiceProvider\EccubeMonologServiceProvider($app));
0 ignored issues
show
Unused Code introduced by
The call to EccubeMonologServiceProvider::__construct() has too many arguments starting with $app.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
104 939
        $this['monolog.logfile'] = __DIR__.'/../../app/log/site.log';
105
        $this['monolog.name'] = 'eccube';
106
    }
107 939
108 939
    public function initialize()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
109 939
    {
110
        if ($this->initialized) {
111
            return;
112
        }
113
114 939
        // init locale
115 939
        $this->initLocale();
116 939
117 939
        // init session
118
        if (!$this->isSessionStarted()) {
119
            $this->initSession();
120 939
        }
121
122 939
        // init twig
123 939
        $this->initRendering();
124 939
125 939
        // init provider
126
        $this->register(new \Silex\Provider\HttpFragmentServiceProvider());
127
        $this->register(new \Silex\Provider\UrlGeneratorServiceProvider());
128 939
        $this->register(new \Silex\Provider\FormServiceProvider());
129 939
        $this->register(new \Silex\Provider\SerializerServiceProvider());
130 939
        $this->register(new \Eccube\ServiceProvider\ValidatorServiceProvider());
131 939
132
        $app = $this;
133 939
        $this->error(function(\Exception $e, $code) use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
134
            if ($app['debug']) {
135 939
                return;
136 939
            }
137 939
138
            switch ($code) {
139
                case 403:
140 939
                    $title = 'アクセスできません。';
141 939
                    $message = 'お探しのページはアクセスができない状況にあるか、移動もしくは削除された可能性があります。';
142 939
                    break;
143 939
                case 404:
144
                    $title = 'ページがみつかりません。';
145
                    $message = 'URLに間違いがないかご確認ください。';
146 939
                    break;
147
                default:
148 939
                    $title = 'システムエラーが発生しました。';
149 939
                    $message = '大変お手数ですが、サイト管理者までご連絡ください。';
150 939
                    break;
151
            }
152
153 939
            return $app->render('error.twig', array(
154 939
                'error_title' => $title,
155 939
                'error_message' => $message,
156 939
            ));
157
        });
158
159 939
        // init mailer
160
        $this->initMailer();
161 939
162 939
        // init doctrine orm
163 939
        $this->initDoctrine();
164
165
        // Set up the DBAL connection now to check for a proper connection to the database.
166 939
        $this->checkDatabaseConnection();
167 939
168 939
        // init security
169 939
        $this->initSecurity();
170
171
        // init ec-cube service provider
172 939
        $this->register(new ServiceProvider\EccubeServiceProvider());
173
174 939
        // mount controllers
175 946
        $this->register(new \Silex\Provider\ServiceControllerServiceProvider());
176
        $this->mount('', new ControllerProvider\FrontControllerProvider());
177
        $this->mount('/'.trim($this['config']['admin_route'], '/').'/', new ControllerProvider\AdminControllerProvider());
178 946
        Request::enableHttpMethodParameterOverride(); // PUTやDELETEできるようにする
179
180 946
        // add transaction listener
181 946
        $this['dispatcher']->addSubscriber(new TransactionListener($this));
182 946
183 946
        $this->initialized = true;
184
    }
185
186 936
    public function initLocale()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
187
    {
188 936
189
        // timezone
190
        if (!empty($this['config']['timezone'])) {
191
            date_default_timezone_set($this['config']['timezone']);
192
        }
193 936
194
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
195
            'locale' => $this['config']['locale'],
196 936
        ));
197 936
        $this['translator'] = $this->share($this->extend('translator', function($translator, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
198
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
199
200
            $r = new \ReflectionClass('Symfony\Component\Validator\Validator');
201 936
            $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
202
            if (file_exists($file)) {
203
                $translator->addResource('xliff', $file, $app['locale'], 'validators');
204 936
            }
205 936
206 936
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
207 936
            if (file_exists($file)) {
208 936
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
209
            }
210 936
211
            $file = __DIR__.'/Resource/locale/message.'.$app['locale'].'.yml';
212 10
            if (file_exists($file)) {
213 10
                $translator->addResource('yaml', $file, $app['locale']);
214
            }
215
216
            return $translator;
217
        }));
218
    }
219
220
    public function initSession()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
221
    {
222
        $this->register(new \Silex\Provider\SessionServiceProvider(), array(
223
            'session.storage.save_path' => $this['config']['root_dir'].'/app/cache/eccube/session',
224
            'session.storage.options' => array(
225
                'name' => 'eccube',
226
                'cookie_path' => $this['config']['root_urlpath'] ?: '/',
227
                'cookie_secure' => $this['config']['force_ssl'],
228
                '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 936
236
    public function initRendering()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
237
    {
238 936
        $this->register(new \Silex\Provider\TwigServiceProvider(), array(
239
            'twig.form.templates' => array('Form/form_layout.twig'),
240
        ));
241 936
        $this['twig'] = $this->share($this->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
242
            $twig->addExtension(new \Eccube\Twig\Extension\EccubeExtension($app));
243
            $twig->addExtension(new \Twig_Extension_StringLoader());
244 936
245
            return $twig;
246
        }));
247 936
248
        $this->before(function(Request $request, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
249
            // フロント or 管理画面ごとにtwigの探索パスを切り替える.
250 936
            $app['twig'] = $app->share($app->extend('twig', function(\Twig_Environment $twig, \Silex\Application $app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
251
                $paths = array();
252
253 936
                // 互換性がないのでprofiler とproduction 時のcacheを分離する
254 936
255 936
                $app['admin'] = false;
256 936
                $app['front'] = false;
257
258
                if (isset($app['profiler'])) {
259 936
                    $cacheBaseDir = __DIR__.'/../../app/cache/twig/profiler/';
260
                } else {
261 936
                    $cacheBaseDir = __DIR__.'/../../app/cache/twig/production/';
262
                }
263
                $pathinfo = rawurldecode($app['request']->getPathInfo());
264 936
                if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) {
265
                    if (file_exists(__DIR__.'/../../app/template/admin')) {
266
                        $paths[] = __DIR__.'/../../app/template/admin';
267
                    }
268 936
                    $paths[] = $app['config']['template_admin_realdir'];
269 936
                    $paths[] = __DIR__.'/../../app/Plugin';
270
                    $cache = $cacheBaseDir.'admin';
271
                    $app['admin'] = true;
272 936
                } else {
273 936
                    if (file_exists($app['config']['template_realdir'])) {
274
                        $paths[] = $app['config']['template_realdir'];
275
                    }
276 605
                    $paths[] = $app['config']['template_default_realdir'];
277
                    $paths[] = __DIR__.'/../../app/Plugin';
278 605
                    $cache = $cacheBaseDir.$app['config']['template_code'];
279 605
                    $app['front'] = true;
280 605
                }
281 605
                $twig->setCache($cache);
282
                $app['twig.loader']->addLoader(new \Twig_Loader_Filesystem($paths));
283
284 605
                return $twig;
285 605
            }));
286 605
287
            // 管理画面のIP制限チェック.
288
            $pathinfo = rawurldecode($app['request']->getPathInfo());
289 605
            if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) {
290 605
                // IP制限チェック
291 605
                $allowHost = $app['config']['admin_allow_host'];
292
                if (count($allowHost) > 0) {
293
                    if (array_search($app['request']->getClientIp(), $allowHost) === false) {
294 605
                        throw new \Exception();
295 936
                    }
296
                }
297
            }
298 936
        }, self::EARLY_EVENT);
299
300 936
        // twigのグローバル変数を定義.
301 936
        $app = $this;
302
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
303 936
            // ショップ基本情報
304 936
            $BaseInfo = $app['eccube.repository.base_info']->get();
305 936
            $app['twig']->addGlobal('BaseInfo', $BaseInfo);
306 936
307
            $pathinfo = rawurldecode($app['request']->getPathInfo());
308
            if (strpos($pathinfo, '/'.trim($app['config']['admin_route'], '/').'/') === 0) {
309
                // 管理画面
310
                // 管理画面メニュー
311
                $menus = array('', '', '');
312
                $app['twig']->addGlobal('menus', $menus);
313
314 936
                $Member = $app->user();
315
                if (is_object($Member)) {
316 936
                    // ログインしていれば管理者のロールを取得
317 936
                    $AuthorityRoles = $app['eccube.repository.authority_role']->findBy(array('Authority' => $Member->getAuthority()));
318
319
                    $roles = array();
320 364
                    foreach ($AuthorityRoles as $AuthorityRole) {
321 364
                        // 管理画面でメニュー制御するため相対パス全てをセット
322
                        $roles[] = $app['request']->getBaseUrl().'/'.$app['config']['admin_route'].$AuthorityRole->getDenyUrl();
323 364
                    }
324 936
325
                    $app['twig']->addGlobal('AuthorityRoles', $roles);
326
                }
327
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
328
            } else {
329 351
                // フロント画面
330
                $request = $event->getRequest();
331
                $route = $request->attributes->get('_route');
332
333 351
                // ユーザ作成画面
334 351
                if ($route === trim($app['config']['user_data_route'])) {
335
                    $params = $request->attributes->get('_route_params');
336 351
                    $route = $params['route'];
337
                    // プレビュー画面
338
                } elseif ($request->get('preview')) {
339 351
                    $route = 'preview';
340
                }
341 351
342 351
                try {
343 187
                    $DeviceType = $app['eccube.repository.master.device_type']
344 187
                        ->find(\Eccube\Entity\Master\DeviceType::DEVICE_TYPE_PC);
345
                    $PageLayout = $app['eccube.repository.page_layout']->getByUrl($DeviceType, $route);
346 187
                } catch (\Doctrine\ORM\NoResultException $e) {
347 187
                    $PageLayout = $app['eccube.repository.page_layout']->newPageLayout($DeviceType);
348 187
                }
349 187
350
                $app['twig']->addGlobal('PageLayout', $PageLayout);
351 165
                $app['twig']->addGlobal('title', $PageLayout->getName());
352 165
            }
353
        });
354 165
    }
355 165
356 165
    public function initMailer()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
357 165
    {
358
359 351
        // メール送信時の文字エンコード指定(デフォルトはUTF-8)
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
360 351
        if (isset($this['config']['mail']['charset_iso_2022_jp']) && is_bool($this['config']['mail']['charset_iso_2022_jp'])) {
361
            if ($this['config']['mail']['charset_iso_2022_jp'] === true) {
362 351
                \Swift::init(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
363 353
                    \Swift_DependencyContainer::getInstance()
364
                        ->register('mime.qpheaderencoder')
365
                        ->asAliasOf('mime.base64headerencoder');
366 353
                    \Swift_Preferences::getInstance()->setCharset('iso-2022-jp');
367 353
                });
368
            }
369 187
        }
370 187
371
        $this->register(new \Silex\Provider\SwiftmailerServiceProvider());
372
        $this['swiftmailer.options'] = $this['config']['mail'];
373
374
        if (isset($this['config']['mail']['spool']) && is_bool($this['config']['mail']['spool'])) {
375
            $this['swiftmailer.use_spool'] = $this['config']['mail']['spool'];
376 936
        }
377
        // デフォルトはsmtpを使用
378
        $transport = $this['config']['mail']['transport'];
379 936
        if ($transport == 'sendmail') {
380
            $this['swiftmailer.transport'] = \Swift_SendmailTransport::newInstance();
381
        } elseif ($transport == 'mail') {
382 351
            $this['swiftmailer.transport'] = \Swift_MailTransport::newInstance();
383 351
        }
384
    }
385 351
386 351
    public function initDoctrine()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
387
    {
388
        $this->register(new \Silex\Provider\DoctrineServiceProvider(), array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
389 187
            'dbs.options' => array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
390 187
                'default' => $this['config']['database']
391
        )));
392 187
        $this->register(new \Saxulum\DoctrineOrmManagerRegistry\Silex\Provider\DoctrineOrmManagerRegistryProvider());
393 187
394
        // プラグインのmetadata定義を合わせて行う.
395 181
        $pluginBasePath = __DIR__.'/../../app/Plugin';
396
        $finder = Finder::create()
397 181
            ->in($pluginBasePath)
398 181
            ->directories()
399
            ->depth(0);
400 181
401
        $ormMappings = array();
402
        $ormMappings[] = array(
403 187
            'type' => 'yml',
404
            'namespace' => 'Eccube\Entity',
405
            'path' => array(
406
                __DIR__.'/Resource/doctrine',
407
                __DIR__.'/Resource/doctrine/master',
408 165
            ),
409 165
        );
410
411
        foreach ($finder as $dir) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
412 165
413 2
            $file = $dir->getRealPath().'/config.yml';
414 2
415
            if (file_exists($file)) {
416 163
                $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 165
            }
422 165
423 165
            // Doctrine Extend
424 135
            if (isset($config['orm.path']) && is_array($config['orm.path'])) {
425 135
                $paths = array();
426
                foreach ($config['orm.path'] as $path) {
427
                    $paths[] = $pluginBasePath.'/'.$config['code'].$path;
428 165
                }
429 165
                $ormMappings[] = array(
430
                    'type' => 'yml',
431 936
                    'namespace' => 'Plugin\\'.$config['code'].'\\Entity',
432
                    'path' => $paths,
433
                );
434 936
            }
435
        }
436
437
        $options = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
438 936
            'mappings' => $ormMappings
439 936
        );
440
441
        if (!$this['debug']) {
442
            $cacheDrivers = array();
443
            if (array_key_exists('doctrine_cache', $this['config'])) {
444
                $cacheDrivers = $this['config']['doctrine_cache'];
445
            }
446
447
            if (array_key_exists('metadata_cache', $cacheDrivers)) {
448
                $options['metadata_cache'] = $cacheDrivers['metadata_cache'];
449 936
            }
450 936
            if (array_key_exists('query_cache', $cacheDrivers)) {
451
                $options['query_cache'] = $cacheDrivers['query_cache'];
452 936
            }
453
            if (array_key_exists('result_cache', $cacheDrivers)) {
454
                $options['result_cache'] = $cacheDrivers['result_cache'];
455
            }
456 936
            if (array_key_exists('hydration_cache', $cacheDrivers)) {
457 936
                $options['hydration_cache'] = $cacheDrivers['hydration_cache'];
458
            }
459 936
        }
460
461
        $this->register(new \Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider(), array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
462
            'orm.proxies_dir' => __DIR__.'/../../app/cache/doctrine/proxies',
463
            'orm.em.options' => $options
464 936
        ));
465
    }
466 936
467
    public function initSecurity()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
468 936
    {
469
        $this->register(new \Silex\Provider\SecurityServiceProvider());
470 936
        $this->register(new \Silex\Provider\RememberMeServiceProvider());
471
472
        $this['security.firewalls'] = array(
473 936
            'admin' => array(
474 936
                'pattern' => "^/{$this['config']['admin_route']}/",
475 936
                'form' => array(
476 936
                    'login_path' => "/{$this['config']['admin_route']}/login",
477 936
                    'check_path' => "/{$this['config']['admin_route']}/login_check",
478
                    'username_parameter' => 'login_id',
479 936
                    'password_parameter' => 'password',
480 936
                    'with_csrf' => true,
481
                    'use_forward' => true,
482
                ),
483
                'logout' => array(
484
                    'logout_path' => "/{$this['config']['admin_route']}/logout",
485
                    'target_url' => "/{$this['config']['admin_route']}/",
486
                ),
487
                'users' => $this['orm.em']->getRepository('Eccube\Entity\Member'),
488
                'anonymous' => true,
489 936
            ),
490
            'customer' => array(
491 139
                'pattern' => '^/',
492
                'form' => array(
493 139
                    'login_path' => '/mypage/login',
494 139
                    '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 139
                    'target_url' => '/',
503
                ),
504
                'remember_me' => array(
505
                    'key' => sha1($this['config']['auth_magic']),
506
                    'name' => 'eccube_rememberme',
507
                    // lifetimeはデフォルトの1年間にする
508
                    // 'lifetime' => $this['config']['cookie_lifetime'],
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
509
                    'path' => $this['config']['root_urlpath'] ?: '/',
510 936
                    'secure' => $this['config']['force_ssl'],
511
                    'httponly' => true,
512
                    'always_remember_me' => false,
513
                    'remember_me_parameter' => 'login_memory',
514
                ),
515
                'users' => $this['orm.em']->getRepository('Eccube\Entity\Customer'),
516 936
                'anonymous' => true,
517
            ),
518
        );
519 936
520 3
        $this['security.access_rules'] = array(
521 3
            array("^/{$this['config']['admin_route']}/login", 'IS_AUTHENTICATED_ANONYMOUSLY'),
522
            array("^/{$this['config']['admin_route']}/", 'ROLE_ADMIN'),
523
            array('^/mypage/login', 'IS_AUTHENTICATED_ANONYMOUSLY'),
524 3
            array('^/mypage/withdraw_complete', 'IS_AUTHENTICATED_ANONYMOUSLY'),
525
            array('^/mypage/change', 'IS_AUTHENTICATED_FULLY'),
526
            array('^/mypage', 'ROLE_USER'),
527 3
        );
528
529
        $this['eccube.password_encoder'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
530 3
            return new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']);
531
        });
532
        $this['security.encoder_factory'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
533 3
            return new \Symfony\Component\Security\Core\Encoder\EncoderFactory(array(
534
                'Eccube\Entity\Customer' => $app['eccube.password_encoder'],
535
                'Eccube\Entity\Member' => $app['eccube.password_encoder'],
536
            ));
537
        });
538 936
        $this['eccube.event_listner.security'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
539 936
            return new \Eccube\EventListener\SecurityEventListener($app['orm.em']);
540 936
        });
541
        $this['user'] = function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
542
            $token = $app['security']->getToken();
543
544 936
            return ($token !== null) ? $token->getUser() : null;
545
        };
546 936
547 936
        // ログイン時のイベントを設定.
548
        $this['dispatcher']->addListener(\Symfony\Component\Security\Http\SecurityEvents::INTERACTIVE_LOGIN, array($this['eccube.event_listner.security'], 'onInteractiveLogin'));
549 936
550
        // Voterの設定
551 936
        $app = $this;
552
        $this['authority_voter'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
553 936
            return new \Eccube\Security\Voter\AuthorityVoter($app);
554 936
        });
555 936
556 936
        $app['security.voters'] = $app->extend('security.voters', function($voters) use ($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
557
            $voters[] = $app['authority_voter'];
558
559
            return $voters;
560
        });
561 936
562 936
        $this['security.access_manager'] = $this->share(function($app) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
563
            return new \Symfony\Component\Security\Core\Authorization\AccessDecisionManager($app['security.voters'], 'unanimous');
564 936
        });
565
566 936
    }
567
568 936
    public function initializePlugin()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
569
    {
570
        if ($this->initializedPlugin) {
571
            return;
572
        }
573
574
        // setup event dispatcher
575
        $this->initPluginEventDispatcher();
576
577
        // load plugin
578
        $this->loadPlugin();
579
580
        $this->initializedPlugin = true;
581
    }
582 936
583 936
    public function initPluginEventDispatcher()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
584
    {
585
        // EventDispatcher
586 936
        $this['eccube.event.dispatcher'] = $this->share(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
587 936
            return new EventDispatcher();
588
        });
589
590 936
        $app = $this;
591
592 936
        // hook point
593
        $this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($app) {
594
            if (!$event->isMasterRequest()) {
595
                return;
596
            }
597 936
            $hookpoint = 'eccube.event.app.before';
598 936
            $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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
602
            if (!$event->isMasterRequest()) {
603
                return;
604
            }
605
            $route = $event->getRequest()->attributes->get('_route');
606
            $hookpoint = "eccube.event.controller.$route.before";
607 936
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
608 936
        });
609
610 936 View Code Duplication
        $this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
611 936
            if (!$event->isMasterRequest()) {
612 936
                return;
613
            }
614 936
            $route = $event->getRequest()->attributes->get('_route');
615
            $hookpoint = "eccube.event.controller.$route.after";
616 936
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
617 936
        });
618
619 256
        $this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($app) {
620
            if (!$event->isMasterRequest()) {
621 256
                return;
622
            }
623
            $hookpoint = 'eccube.event.app.after';
624
            $app['eccube.event.dispatcher']->dispatch($hookpoint, $event);
625 936
        }, self::LATE_EVENT);
626
627
        $this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($app) {
628 936
            $route = $event->getRequest()->attributes->get('_route');
629
            $hookpoint = "eccube.event.controller.$route.finish";
630 936
            $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) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
634 936
            $route = $event->getRequest()->attributes->get('_route');
635
            $app['eccube.event.dispatcher']->dispatch('eccube.event.render.'.$route.'.before', $event);
636 936
        });
637 936
638
        // Request Event
639 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::REQUEST, function(\Symfony\Component\HttpKernel\Event\GetResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
640 936
641 936
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
642
                return;
643
            }
644
645 936
            $route = $event->getRequest()->attributes->get('_route');
646
647 936
            if (is_null($route)) {
648
                return;
649
            }
650
651
            $app['monolog']->debug('KernelEvents::REQUEST '.$route);
652 936
653
            // 全体
654
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.request', $event);
655 936
656
            if (strpos($route, 'admin') === 0) {
657 936
                // 管理画面
658
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.request', $event);
659
            } else {
660 936
                // フロント画面
661
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.request', $event);
662
            }
663
664 366
            // ルーティング単位
665 936
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.request", $event);
666
667 936
        }, 30); // Routing(32)が解決しし, 認証判定(8)が実行される前のタイミング.
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
668
669
        // Controller Event
670 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::CONTROLLER, function(\Symfony\Component\HttpKernel\Event\FilterControllerEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
671 353
672 98
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
673
                return;
674 353
            }
675 353
676 936
677
            $route = $event->getRequest()->attributes->get('_route');
678
679 352
            if (is_null($route)) {
680 98
                return;
681
            }
682 350
683 350
            $app['monolog']->debug('KernelEvents::CONTROLLER '.$route);
684 350
685 936
            // 全体
686
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.controller', $event);
687
688 347
            if (strpos($route, 'admin') === 0) {
689 98
                // 管理画面
690
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.controller', $event);
691 347
            } else {
692 347
                // フロント画面
693 347
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.controller', $event);
694 936
            }
695
696
            // ルーティング単位
697 347
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.controller", $event);
698 98
        });
699
700 347
        // Response Event
701 347 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::RESPONSE, function(\Symfony\Component\HttpKernel\Event\FilterResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
702 936
703
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
704
                return;
705 347
            }
706 347
707 347
            $route = $event->getRequest()->attributes->get('_route');
708 936
709
            if (is_null($route)) {
710
                return;
711 347
            }
712 347
713 936
            $app['monolog']->debug('KernelEvents::RESPONSE '.$route);
714
715
            // ルーティング単位
716
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.response", $event);
717
718 352
            if (strpos($route, 'admin') === 0) {
719 98
                // 管理画面
720
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.response', $event);
721
            } else {
722 352
                // フロント画面
723
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.response', $event);
724 352
            }
725
726
            // 全体
727
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.response', $event);
728 352
        });
729
730
        // Exception Event
731 352 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::EXCEPTION, function(\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
732
733 352
            if (\Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
734
                return;
735 187
            }
736
737
            $route = $event->getRequest()->attributes->get('_route');
738 166
739
            if (is_null($route)) {
740
                return;
741
            }
742 352
743
            $app['monolog']->debug('KernelEvents::EXCEPTION '.$route);
744 936
745
            // ルーティング単位
746
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.exception", $event);
747
748
            if (strpos($route, 'admin') === 0) {
749 351
                // 管理画面
750 98
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.exception', $event);
751
            } else {
752
                // フロント画面
753
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.exception', $event);
754 349
            }
755
756 349
            // 全体
757
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.exception', $event);
758
        });
759
760 349
        // Terminate Event
761 View Code Duplication
        $this->on(\Symfony\Component\HttpKernel\KernelEvents::TERMINATE, function(\Symfony\Component\HttpKernel\Event\PostResponseEvent $event) use ($app) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
762
763 349
            $route = $event->getRequest()->attributes->get('_route');
764
765 349
            if (is_null($route)) {
766
                return;
767 185
            }
768
769
            $app['monolog']->debug('KernelEvents::TERMINATE '.$route);
770 165
771
            // ルーティング単位
772
            $app['eccube.event.dispatcher']->dispatch("eccube.event.route.{$route}.terminate", $event);
773
774 349
            if (strpos($route, 'admin') === 0) {
775 936
                // 管理画面
776
                $app['eccube.event.dispatcher']->dispatch('eccube.event.admin.terminate', $event);
777
            } else {
778
                // フロント画面
779
                $app['eccube.event.dispatcher']->dispatch('eccube.event.front.terminate', $event);
780 347
            }
781 98
782
            // 全体
783
            $app['eccube.event.dispatcher']->dispatch('eccube.event.app.terminate', $event);
784 347
        });
785
    }
786 347
787 1
    public function loadPlugin()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
788
    {
789
        // プラグインディレクトリを探索.
790 346
        $basePath = __DIR__.'/../../app/Plugin';
791
        $finder = Finder::create()
792
            ->in($basePath)
793 346
            ->directories()
794
            ->depth(0);
795 346
796
        $finder->sortByName();
797 187
798
        // ハンドラ優先順位をdbから持ってきてハッシュテーブルを作成
799
        $priorities = array();
800 160
        $handlers = $this['orm.em']
801
            ->getRepository('Eccube\Entity\PluginEventHandler')
802
            ->getHandlers();
803
        foreach ($handlers as $handler) {
804 346
            if ($handler->getPlugin()->getEnable() && !$handler->getPlugin()->getDelFlg()) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
805 936
806
                $priority = $handler->getPriority();
807
            } else {
808
                // Pluginがdisable、削除済みの場合、EventHandlerのPriorityを全て0とみなす
809
                $priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED;
810 12
            }
811
            $priorities[$handler->getPlugin()->getClassName()][$handler->getEvent()][$handler->getHandler()] = $priority;
812
        }
813
814 12
        // プラグインをロードする.
815
        // config.yml/event.ymlの定義に沿ってインスタンスの生成を行い, イベント設定を行う.
816 12
        foreach ($finder as $dir) {
817
            //config.ymlのないディレクトリは無視する
818
            $path = $dir->getRealPath();
819
            $code = $dir->getBaseName();
820 12
            try {
821
                $this['eccube.service.plugin']->checkPluginArchiveContent($path);
822
            } catch (\Eccube\Exception\PluginException $e) {
823 12
                $this['monolog']->warning("skip {$code} config loading. config.yml not foud or invalid.", array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
824
                    'path' =>  $path,
825 12
                    'original-message' => $e->getMessage()
826
                ));
827 2
                continue;
828
            }
829
            $config = $this['eccube.service.plugin']->readYml($dir->getRealPath().'/config.yml');
830 10
831
            $plugin = $this['orm.em']
832
                ->getRepository('Eccube\Entity\Plugin')
833
                ->findOneBy(array('code' => $config['code']));
834 12
835 936
            // const
836
            if (isset($config['const'])) {
837
                $this['config'] = $this->share($this->extend('config', function($eccubeConfig) use ($config) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
838
                    $eccubeConfig[$config['code']] = array(
839
                        'const' => $config['const'],
840 347
                    );
841
842 347
                    return $eccubeConfig;
843 1
                }));
844
            }
845
846 346
            if ($plugin && $plugin->getEnable() == Constant::DISABLED) {
847
                // プラグインが無効化されていれば読み込まない
848
                continue;
849 346
            }
850
851 346
            // Type: Event
852
            if (isset($config['event'])) {
853 187
                $class = '\\Plugin\\'.$config['code'].'\\'.$config['event'];
854
                $eventExists = true;
855
856 160 View Code Duplication
                if (!class_exists($class)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
857
                    $this['monolog']->warning("skip {$code} loading. event class not foud.", array(
858
                        'class' =>  $class,
859
                    ));
860 346
                    $eventExists = false;
861 936
                }
862
863
                if ($eventExists && file_exists($dir->getRealPath().'/event.yml')) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
864 936
865
                    $subscriber = new $class($this);
866
867 936
                    foreach (Yaml::parse(file_get_contents($dir->getRealPath().'/event.yml')) as $event => $handlers) {
868 936
                        foreach ($handlers as $handler) {
869 936
                            if (!isset($priorities[$config['event']][$event][$handler[0]])) { // ハンドラテーブルに登録されていない(ソースにしか記述されていない)ハンドラは一番後ろにする
870 936
                                $priority = \Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_LATEST;
871 936
                            } else {
872
                                $priority = $priorities[$config['event']][$event][$handler[0]];
873 936
                            }
874
                            // 優先度が0のプラグインは登録しない
875
                            if (\Eccube\Entity\PluginEventHandler::EVENT_PRIORITY_DISABLED != $priority) {
876 936
                                $this['eccube.event.dispatcher']->addListener($event, array($subscriber, $handler[0]), $priority);
877 936
                            }
878 936
                        }
879 936
                    }
880 936
                }
881
            }
882
            // Type: ServiceProvider
883
            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)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
887
                        $this['monolog']->warning("skip {$code} loading. service provider class not foud.", array(
888 936
                            'class' =>  $class,
889
                        ));
890
                        continue;
891
                    }
892
                    $this->register(new $class($this));
893 936
                }
894
            }
895 140
        }
896 140
    }
897
898 140
    /**
899
     * PHPUnit を実行中かどうかを設定する.
900
     *
901
     * @param boolean $testMode PHPUnit を実行中の場合 true
902
     */
903
    public function setTestMode($testMode) {
904
        $this->testMode = $testMode;
905
    }
906 140
907
    /**
908 140
     * PHPUnit を実行中かどうか.
909 140
     *
910 140
     * @return boolean PHPUnit を実行中の場合 true
911
     */
912
    public function isTestMode()
913 140
    {
914 1
        return $this->testMode;
915 1
    }
916 1
917
    /**
918
     *
919 1
     * データベースの接続を確認
920 1
     * 成功 : trueを返却
921
     * 失敗 : \Doctrine\DBAL\DBALExceptionエラーが発生( 接続に失敗した場合 )、エラー画面を表示しdie()
922
     * 備考 : app['debug']がtrueの際は処理を行わない
923 140
     * @return boolean true
924
     *
925 1
     */
926
    protected function checkDatabaseConnection()
927
    {
928
        if ($this['debug']) {
929 139
            return;
930 139
        }
931 139
        try {
932
            $this['db']->connect();
933 139
        } 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 139
            $response = new Response();
941
            $response->setContent($html);
942 139
            $response->setStatusCode('500');
943
            $response->headers->set('Content-Type', 'text/html');
944 139
            $response->send();
945 139
            die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method checkDatabaseConnection() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
946 139
        }
947 139
        return true;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
948
    }
949
950
    /**
951
     * Config ファイルをパースし、連想配列を返します.
952 139
     *
953 139
     * $config_name.yml ファイルをパースし、連想配列を返します.
954
     * $config_name.php が存在する場合は、 PHP ファイルに記述された連想配列を使用します。
955
     *
956
     * @param string $config_name Config 名称
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
957
     * @param array $configAll Config の連想配列
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
958
     * @param boolean $wrap_key Config の連想配列に config_name のキーを生成する場合 true, デフォルト false
0 ignored issues
show
introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
959
     * @param string $ymlPath config yaml を格納したディレクトリ
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 5 spaces after parameter name; 1 found
Loading history...
960 139
     * @param string $distPath config yaml dist を格納したディレクトリ
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 4 spaces after parameter name; 1 found
Loading history...
961
     * @return Application
962
     */
963
    public function parseConfig($config_name, array &$configAll, $wrap_key = false, $ymlPath = null, $distPath = null)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
964
    {
965
        $ymlPath = $ymlPath ? $ymlPath : __DIR__.'/../../app/config/eccube';
966
        $distPath = $distPath ? $distPath : __DIR__.'/../../src/Eccube/Resource/config';
967
        $config = array();
968
        $config_php = $ymlPath.'/'.$config_name.'.php';
969 936
        if (!file_exists($config_php)) {
970
            $config_yml = $ymlPath.'/'.$config_name.'.yml';
971
            if (file_exists($config_yml)) {
972
                $config = Yaml::parse(file_get_contents($config_yml));
973
                $config = empty($config) ? array() : $config;
974 View Code Duplication
                if (isset($this['output_config_php']) && $this['output_config_php']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
975
                    file_put_contents($config_php, sprintf('<?php return %s', var_export($config, true)).';');
976
                }
977
            }
978
        } else {
979
            $config = require $config_php;
980 923
        }
981 923
982
        $config_dist = array();
983
        $config_php_dist = $distPath.'/'.$config_name.'.dist.php';
984
        if (!file_exists($config_php_dist)) {
985
            $config_yml_dist = $distPath.'/'.$config_name.'.yml.dist';
986
            if (file_exists($config_yml_dist)) {
987
                $config_dist = Yaml::parse(file_get_contents($config_yml_dist));
988 View Code Duplication
                if (isset($this['output_config_php']) && $this['output_config_php']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
989 353
                    file_put_contents($config_php_dist, sprintf('<?php return %s', var_export($config_dist, true)).';');
990
                }
991 353
            }
992
        } else {
993
            $config_dist = require $config_php_dist;
994
        }
995
996
        if ($wrap_key) {
997
            $configAll = array_replace_recursive($configAll, array($config_name => $config_dist), array($config_name => $config));
998
        } else {
999
            $configAll = array_replace_recursive($configAll, $config_dist, $config);
1000
        }
1001
1002
        return $this;
1003 936
    }
1004
1005 936
    /**
1006 933
     * セッションが開始されているかどうか.
1007
     *
1008
     * @return boolean セッションが開始済みの場合 true
1009 3
     * @link http://php.net/manual/ja/function.session-status.php#113468
1010
     */
1011
    protected function isSessionStarted()
1012
    {
1013
        if (php_sapi_name() !== 'cli') {
1014
            if (version_compare(phpversion(), '5.4.0', '>=')) {
1015
                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