Completed
Pull Request — master (#2103)
by
unknown
69:45 queued 34:07
created

InstallApplication   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 14

Test Coverage

Coverage 87.93%

Importance

Changes 0
Metric Value
dl 0
loc 101
ccs 51
cts 58
cp 0.8793
rs 10
c 0
b 0
f 0
wmc 11
lcom 0
cbo 14

1 Method

Rating   Name   Duplication   Size   Complexity  
C __construct() 0 98 11
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 Symfony\Component\Yaml\Yaml;
28
29
class InstallApplication extends ApplicationTrait
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
30
{
31 42
    public function __construct(array $values = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
32
    {
33 42
        $app = $this;
34
35 42
        parent::__construct($values);
36
37 42
        $logDir = realpath(__DIR__.'/../../app/log');
38 42
        $installLog = $logDir.'/install.log';
39
40 42
        if (is_writable($logDir)) {
41 42
            if (file_exists($installLog) && !is_writable($installLog)) {
42
                die($installLog . ' の書込権限を変更して下さい。');
0 ignored issues
show
Coding Style Compatibility introduced by
The method __construct() 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...
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
43
            }
44
            // install step2 でログディレクトリに書き込み権限が付与されればログ出力を開始する.
45 42
            $app->register(new \Silex\Provider\MonologServiceProvider(), array(
46 42
                'monolog.logfile' => $installLog,
47
            ));
48
        }
49
50
        // load config
51
        $app['config'] = $app->share(function() {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
52 28
            $distPath = __DIR__.'/../../src/Eccube/Resource/config';
53
54 28
            $configConstant = array();
55 28
            $constantYamlPath = $distPath.'/constant.yml.dist';
56 28
            if (file_exists($constantYamlPath)) {
57 28
                $configConstant = Yaml::parse(file_get_contents($constantYamlPath));
58
            }
59
60 28
            $configLog = array();
61 28
            $logYamlPath = $distPath.'/log.yml.dist';
62 28
            if (file_exists($logYamlPath)) {
63 28
                $configLog = Yaml::parse(file_get_contents($logYamlPath));
64
            }
65
66 28
            $config = array_replace_recursive($configConstant, $configLog);
67
68 28
            return $config;
69 42
        });
70
71 42
        $distPath = __DIR__.'/../../src/Eccube/Resource/config';
72 42
        $config_dist = Yaml::parse(file_get_contents($distPath.'/config.yml.dist'));
73 42
        if (!empty($config_dist['timezone'])) {
74 42
            date_default_timezone_set($config_dist['timezone']);
75
        }
76
77 42
        $app->register(new \Silex\Provider\SessionServiceProvider());
78
79 42
        $app->register(new \Silex\Provider\TwigServiceProvider(), array(
80 42
            'twig.path' => array(__DIR__.'/Resource/template/install'),
81
            'twig.form.templates' => array('bootstrap_3_horizontal_layout.html.twig'),
82
        ));
83
        $this['twig'] = $this->share($this->extend('twig', function (\Twig_Environment $twig, \Silex\Application $app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
84 1
            $twig->addExtension(new \Twig_Extension_StringLoader());
85 1
            return $twig;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
86 42
        }));
87
88 42
        $this->register(new \Silex\Provider\UrlGeneratorServiceProvider());
89 42
        $this->register(new \Silex\Provider\FormServiceProvider());
90 42
        $this->register(new \Silex\Provider\ValidatorServiceProvider());
91
92 42
        $this->register(new \Silex\Provider\TranslationServiceProvider(), array(
93 42
            'locale' => 'ja',
94
        ));
95
        $app['translator'] = $app->share($app->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...
96 36
            $translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader());
97
98 36
            $r = new \ReflectionClass('Symfony\Component\Validator\Validator');
99 36
            $file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf';
100 36
            if (file_exists($file)) {
101 36
                $translator->addResource('xliff', $file, $app['locale'], 'validators');
102
            }
103
104 36
            $file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml';
105 36
            if (file_exists($file)) {
106 36
                $translator->addResource('yaml', $file, $app['locale'], 'validators');
107
            }
108
109 36
            $translator->addResource('yaml', __DIR__.'/Resource/locale/ja.yml', $app['locale']);
110
111 36
            return $translator;
112 42
        }));
113
114 42
        $app->mount('', new ControllerProvider\InstallControllerProvider());
115 42
        $app->register(new ServiceProvider\InstallServiceProvider());
116
117 42
        $app->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...
118
            if ($code === 404) {
119
                return $app->redirect($app->url('install'));
120
            } elseif ($app['debug']) {
121
                return;
122
            }
123
124
            return $app['twig']->render('error.twig', array(
125
                'error' => 'エラーが発生しました.',
126
            ));
127 42
        });
128
    }
129
}
130