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\ServiceProvider\DiServiceProvider; |
28
|
|
|
use Symfony\Component\Yaml\Yaml; |
29
|
|
|
|
30
|
|
|
class InstallApplication extends \Silex\Application |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
use \Silex\Application\FormTrait; |
33
|
|
|
use \Silex\Application\UrlGeneratorTrait; |
34
|
|
|
use \Silex\Application\MonologTrait; |
35
|
|
|
use \Silex\Application\SwiftmailerTrait; |
36
|
|
|
use \Silex\Application\SecurityTrait; |
37
|
|
|
use \Eccube\Application\ApplicationTrait; |
38
|
|
|
use \Eccube\Application\SecurityTrait; |
39
|
|
|
use \Eccube\Application\TwigTrait; |
40
|
|
|
|
41
|
42 |
|
public function __construct(array $values = array()) |
|
|
|
|
42
|
|
|
{ |
43
|
42 |
|
$app = $this; |
44
|
|
|
|
45
|
42 |
|
parent::__construct($values); |
46
|
|
|
|
47
|
42 |
|
$logDir = realpath(__DIR__.'/../../app/log'); |
48
|
42 |
|
$installLog = $logDir.'/install.log'; |
49
|
|
|
|
50
|
42 |
|
if (is_writable($logDir)) { |
51
|
42 |
|
if (file_exists($installLog) && !is_writable($installLog)) { |
52
|
|
|
die($installLog . ' の書込権限を変更して下さい。'); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
// install step2 でログディレクトリに書き込み権限が付与されればログ出力を開始する. |
55
|
42 |
|
$app->register(new \Silex\Provider\MonologServiceProvider(), array( |
56
|
42 |
|
'monolog.logfile' => $installLog, |
57
|
|
|
)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// load config |
61
|
|
|
$app['config'] = function() { |
|
|
|
|
62
|
28 |
|
$distPath = __DIR__.'/../../src/Eccube/Resource/config'; |
63
|
|
|
|
64
|
28 |
|
$configConstant = array(); |
65
|
28 |
|
$constantYamlPath = $distPath.'/constant.yml.dist'; |
66
|
28 |
|
if (file_exists($constantYamlPath)) { |
67
|
28 |
|
$configConstant = Yaml::parse(file_get_contents($constantYamlPath)); |
68
|
|
|
} |
69
|
|
|
|
70
|
28 |
|
$configLog = array(); |
71
|
28 |
|
$logYamlPath = $distPath.'/log.yml.dist'; |
72
|
28 |
|
if (file_exists($logYamlPath)) { |
73
|
28 |
|
$configLog = Yaml::parse(file_get_contents($logYamlPath)); |
74
|
|
|
} |
75
|
|
|
|
76
|
28 |
|
$config = array_replace_recursive($configConstant, $configLog); |
77
|
|
|
|
78
|
28 |
|
return $config; |
79
|
|
|
}; |
80
|
|
|
|
81
|
42 |
|
$distPath = __DIR__.'/../../src/Eccube/Resource/config'; |
82
|
42 |
|
$config_dist = Yaml::parse(file_get_contents($distPath.'/config.yml.dist')); |
83
|
42 |
|
if (!empty($config_dist['timezone'])) { |
84
|
42 |
|
date_default_timezone_set($config_dist['timezone']); |
85
|
|
|
} |
86
|
|
|
|
87
|
42 |
|
$app->register(new \Silex\Provider\SessionServiceProvider()); |
88
|
42 |
|
$app->register(new \Silex\Provider\TwigServiceProvider(), array( |
89
|
42 |
|
'twig.path' => array(__DIR__.'/Resource/template/install'), |
90
|
|
|
'twig.form.templates' => array('bootstrap_3_horizontal_layout.html.twig'), |
91
|
|
|
)); |
92
|
|
|
|
93
|
42 |
|
$this->register(new \Silex\Provider\FormServiceProvider()); |
94
|
42 |
|
$this->register(new \Silex\Provider\ValidatorServiceProvider()); |
95
|
|
|
|
96
|
42 |
|
$this->register(new \Silex\Provider\TranslationServiceProvider(), array( |
97
|
42 |
|
'locale' => 'ja', |
98
|
|
|
)); |
99
|
|
|
$app->extend('translator', function($translator, \Silex\Application $app) { |
|
|
|
|
100
|
42 |
|
$translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader()); |
101
|
|
|
|
102
|
42 |
|
$r = new \ReflectionClass('Symfony\Component\Validator\Validation'); |
103
|
42 |
|
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf'; |
104
|
42 |
|
if (file_exists($file)) { |
105
|
42 |
|
$translator->addResource('xliff', $file, $app['locale'], 'validators'); |
106
|
|
|
} |
107
|
|
|
|
108
|
42 |
|
$file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml'; |
109
|
42 |
|
if (file_exists($file)) { |
110
|
|
|
$translator->addResource('yaml', $file, $app['locale'], 'validators'); |
111
|
|
|
} |
112
|
|
|
|
113
|
42 |
|
$translator->addResource('yaml', __DIR__.'/Resource/locale/ja.yml', $app['locale']); |
114
|
|
|
|
115
|
42 |
|
return $translator; |
116
|
42 |
|
}); |
117
|
|
|
|
118
|
42 |
|
$app->mount('', new ControllerProvider\InstallControllerProvider()); |
|
|
|
|
119
|
42 |
|
$app->register(new ServiceProvider\InstallServiceProvider()); |
120
|
42 |
|
$app->register(new \Silex\Provider\CsrfServiceProvider()); |
121
|
|
|
|
122
|
42 |
|
$app->error(function(\Exception $e, $code) use ($app) { |
|
|
|
|
123
|
|
|
if ($code === 404) { |
124
|
|
|
return $app->redirect($app->url('install')); |
125
|
|
|
} elseif ($app['debug']) { |
126
|
|
|
return; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $app['twig']->render('error.twig', array( |
130
|
|
|
'error' => 'エラーが発生しました.', |
131
|
|
|
)); |
132
|
42 |
|
}); |
133
|
|
|
|
134
|
42 |
|
$app->register(new DiServiceProvider(), [ |
|
|
|
|
135
|
42 |
|
'eccube.di.dirs' => [__DIR__.'/Form/Type/Install'], |
136
|
|
|
'eccube.di.generator.dir' => __DIR__.'/../../app/cache/provider', |
137
|
|
|
'eccube.di.generator.class' => 'InstallServiceProviderCache' |
138
|
|
|
]); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|