Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
34.48% covered (danger)
34.48%
10 / 29
CRAP
74.70% covered (warning)
74.70%
378 / 506
Application
0.00% covered (danger)
0.00%
0 / 1
34.48% covered (danger)
34.48%
10 / 29
549.94
74.70% covered (warning)
74.70%
378 / 506
 getInstance
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 clearInstance
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 __clone
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 isBooted
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 initConfig
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
15 / 15
 anonymous function
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 1
 initLogger
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 initialize
0.00% covered (danger)
0.00%
0 / 1
6
97.22% covered (success)
97.22%
35 / 36
 initLocale
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
15 / 15
 initSession
0.00% covered (danger)
0.00%
0 / 1
3.14
75.00% covered (warning)
75.00%
9 / 12
 initRendering
0.00% covered (danger)
0.00%
0 / 1
17
97.14% covered (success)
97.14%
68 / 70
 initMailer
0.00% covered (danger)
0.00%
0 / 1
9.86
69.23% covered (warning)
69.23%
9 / 13
 initDoctrine
0.00% covered (danger)
0.00%
0 / 1
13.77
76.92% covered (warning)
76.92%
30 / 39
 initSecurity
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
42 / 42
 initializePlugin
0.00% covered (danger)
0.00%
0 / 1
2.02
83.33% covered (warning)
83.33%
5 / 6
 initPluginEventDispatcher
100.00% covered (success)
100.00%
1 / 1
20
100.00% covered (success)
100.00%
91 / 91
 loadPlugin
0.00% covered (danger)
0.00%
0 / 1
246.18
17.31% covered (danger)
17.31%
9 / 52
 setTestMode
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 isTestMode
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 checkDatabaseConnection
0.00% covered (danger)
0.00%
0 / 1
7.61
20.00% covered (danger)
20.00%
3 / 15
 parseConfig
0.00% covered (danger)
0.00%
0 / 1
13.09
92.00% covered (success)
92.00%
23 / 25
 isSessionStarted
0.00% covered (danger)
0.00%
0 / 1
6.60
60.00% covered (warning)
60.00%
3 / 5
 initCacheRequest
0.00% covered (danger)
0.00%
0 / 1
8.81
66.67% covered (warning)
66.67%
2 / 3
 getPluginConfigAll
0.00% covered (danger)
0.00%
0 / 1
6.00
50.00% covered (danger)
50.00%
4 / 8
 writePluginConfigCache
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 7
 removePluginConfigCache
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 5
 getPluginConfigCacheFile
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 parsePluginConfigs
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 25
<?php
/*
 * This file is part of EC-CUBE
 *
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
namespace Eccube;
use Eccube\Application\ApplicationTrait;
use Eccube\Common\Constant;
use Eccube\Doctrine\ORM\Mapping\Driver\YamlDriver;
use Eccube\EventListener\TransactionListener;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Yaml\Yaml;
class Application extends ApplicationTrait
{
    protected static $instance;
    protected $initialized = false;
    protected $initializedPlugin = false;
    protected $testMode = false;
    public static function getInstance(array $values = array())
    {
        if (!is_object(self::$instance)) {
            self::$instance = new Application($values);
        }
        return self::$instance;
    }
    public static function clearInstance()
    {
        self::$instance = null;
    }
    final public function __clone()
    {
        throw new \Exception('Clone is not allowed against '.get_class($this));
    }
    public function __construct(array $values = array())
    {
        parent::__construct($values);
        if (is_null(self::$instance)) {
            self::$instance = $this;
        }
        // load config
        $this->initConfig();
        // init monolog
        $this->initLogger();
    }
    /**
     * Application::runが実行されているか親クラスのプロパティから判定
     *
     * @return bool
     */
    public function isBooted()
    {
        return $this->booted;
    }
    public function initConfig()
    {
        // load config
        $app = $this;
        $this['config'] = $this->share(function() use ($app) {
            $configAll = array();
            $app->parseConfig('constant', $configAll)
                ->parseConfig('path', $configAll)
                ->parseConfig('config', $configAll)
                ->parseConfig('database', $configAll)
                ->parseConfig('mail', $configAll)
                ->parseConfig('log', $configAll)
                ->parseConfig('nav', $configAll, true)
                ->parseConfig('doctrine_cache', $configAll)
                ->parseConfig('http_cache', $configAll)
                ->parseConfig('session_handler', $configAll);
            return $configAll;
        });
    }
    public function initLogger()
    {
        $app = $this;
        $this->register(new ServiceProvider\LogServiceProvider($app));
    }
    public function initialize()
    {
        if ($this->initialized) {
            return;
        }
        // init locale
        $this->initLocale();
        // init session
        if (!$this->isSessionStarted()) {
            $this->initSession();
        }
        // init twig
        $this->initRendering();
        // init provider
        $this->register(new \Silex\Provider\HttpCacheServiceProvider(), array(
            'http_cache.cache_dir' => __DIR__.'/../../app/cache/http/',
        ));
        $this->register(new \Silex\Provider\HttpFragmentServiceProvider());
        $this->register(new \Silex\Provider\UrlGeneratorServiceProvider());
        $this->register(new \Silex\Provider\FormServiceProvider());
        $this->register(new \Silex\Provider\SerializerServiceProvider());
        $this->register(new \Silex\Provider\ValidatorServiceProvider());
        $app = $this;
        $this->error(function (\Exception $e, $code) use ($app) {
            if ($app['debug']) {
                return;
            }
            switch ($code) {
                case 403:
                    $title = 'アクセスできません。';
                    $message = 'お探しのページはアクセスができない状況にあるか、移動もしくは削除された可能性があります。';
                    break;
                case 404:
                    $title = 'ページがみつかりません。';
                    $message = 'URLに間違いがないかご確認ください。';
                    break;
                default:
                    $title = 'システムエラーが発生しました。';
                    $message = '大変お手数ですが、サイト管理者までご連絡ください。';
                    break;
            }
            return $app->render('error.twig', array(
                'error_title' => $title,
                'error_message' => $message,
            ));
        });
        // init mailer
        $this->initMailer();
        // init doctrine orm
        $this->initDoctrine();
        // Set up the DBAL connection now to check for a proper connection to the database.
        $this->checkDatabaseConnection();
        // init security
        $this->initSecurity();
        // init ec-cube service provider
        $this->register(new ServiceProvider\EccubeServiceProvider());
        // mount controllers
        $this->register(new \Silex\Provider\ServiceControllerServiceProvider());
        $this->mount('', new ControllerProvider\FrontControllerProvider());
        $this->mount('/'.trim($this['config']['admin_route'], '/').'/', new ControllerProvider\AdminControllerProvider());
        Request::enableHttpMethodParameterOverride(); // PUTやDELETEできるようにする
        // add transaction listener
        $this['dispatcher']->addSubscriber(new TransactionListener($this));
        // init http cache
        $this->initCacheRequest();
        $this->initialized = true;
    }
    public function initLocale()
    {
        // timezone
        if (!empty($this['config']['timezone'])) {
            date_default_timezone_set($this['config']['timezone']);
        }
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
            'locale' => $this['config']['locale'],
            'translator.cache_dir' => $this['debug'] ? null : $this['config']['root_dir'].'/app/cache/translator',
        ));
        $this['translator'] = $this->share($this->extend('translator', function ($translator, \Silex\Application $app) {
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
            if (file_exists($file)) {
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
            }
            $file = __DIR__.'/Resource/locale/message.'.$app['locale'].'.yml';
            if (file_exists($file)) {
                $translator->addResource('yaml', $file, $app['locale']);
            }
            return $translator;
        }));
    }
    public function initSession()
    {
        $this->register(new \Silex\Provider\SessionServiceProvider