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 |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
public $package; |
32
|
|
|
public $rootDir; |
33
|
|
|
|
34
|
40 |
|
public function __construct(array $values = array()) |
|
|
|
|
35
|
|
|
{ |
36
|
|
View Code Duplication |
if (\Phar::running(false)) { |
|
|
|
|
37
|
|
|
// phar |
38
|
|
|
$this->package = 'phar'; |
39
|
|
|
$this->rootDir = dirname(\Phar::running(false)); |
40
|
|
|
} elseif (file_exists(__DIR__.'/../../../../../vendor/ec-cube/ec-cube')) { |
41
|
|
|
// composer |
42
|
|
|
$this->package = 'composer'; |
43
|
|
|
$this->rootDir = __DIR__.'/../../../../..'; |
44
|
|
|
} else { |
45
|
|
|
// other |
46
|
40 |
|
$this->package = 'general'; |
47
|
40 |
|
$this->rootDir = __DIR__.'/../..'; |
48
|
|
|
} |
49
|
|
|
|
50
|
40 |
|
$app = $this; |
51
|
|
|
|
52
|
|
|
parent::__construct($values); |
53
|
|
|
|
54
|
|
|
$app->register(new \Silex\Provider\MonologServiceProvider(), array( |
55
|
40 |
|
'monolog.logfile' => $this->rootDir.'/app/log/install.log', |
56
|
|
|
)); |
57
|
|
|
|
58
|
|
|
// load config |
59
|
|
|
$app['config'] = $app->share(function() { |
|
|
|
|
60
|
27 |
|
$distPath = __DIR__.'/Resource/config'; |
61
|
|
|
|
62
|
27 |
|
$configConstant = array(); |
63
|
27 |
|
$constantYamlPath = $distPath.'/constant.yml.dist'; |
64
|
|
|
if (file_exists($constantYamlPath)) { |
65
|
|
|
$configConstant = Yaml::parse(file_get_contents($constantYamlPath)); |
66
|
|
|
} |
67
|
|
|
|
68
|
27 |
|
$configLog = array(); |
69
|
27 |
|
$logYamlPath = $distPath.'/log.yml.dist'; |
70
|
|
|
if (file_exists($logYamlPath)) { |
71
|
|
|
$configLog = Yaml::parse(file_get_contents($logYamlPath)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$config = array_replace_recursive($configConstant, $configLog); |
75
|
|
|
|
76
|
27 |
|
return $config; |
77
|
|
|
}); |
78
|
|
|
|
79
|
40 |
|
$distPath = __DIR__.'/Resource/config'; |
80
|
|
|
$config_dist = Yaml::parse(file_get_contents($distPath.'/config.yml.dist')); |
81
|
40 |
|
if (!empty($config_dist['timezone'])) { |
82
|
|
|
date_default_timezone_set($config_dist['timezone']); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$app->register(new \Silex\Provider\SessionServiceProvider()); |
86
|
|
|
|
87
|
|
|
$app->register(new \Silex\Provider\TwigServiceProvider(), array( |
88
|
40 |
|
'twig.path' => array(__DIR__.'/Resource/template/install'), |
89
|
40 |
|
'twig.form.templates' => array('bootstrap_3_horizontal_layout.html.twig'), |
90
|
|
|
)); |
91
|
|
|
|
92
|
|
|
$this->register(new \Silex\Provider\UrlGeneratorServiceProvider()); |
93
|
|
|
$this->register(new \Silex\Provider\FormServiceProvider()); |
94
|
|
|
$this->register(new \Silex\Provider\ValidatorServiceProvider()); |
95
|
|
|
|
96
|
|
|
$this->register(new \Silex\Provider\TranslationServiceProvider(), array( |
97
|
|
|
'locale' => 'ja', |
98
|
|
|
)); |
99
|
|
|
$app['translator'] = $app->share($app->extend('translator', function($translator, \Silex\Application $app) { |
|
|
|
|
100
|
|
|
$translator->addLoader('yaml', new \Symfony\Component\Translation\Loader\YamlFileLoader()); |
101
|
|
|
|
102
|
|
|
$r = new \ReflectionClass('Symfony\Component\Validator\Validator'); |
103
|
|
|
$file = dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf'; |
104
|
|
|
if (file_exists($file)) { |
105
|
|
|
$translator->addResource('xliff', $file, $app['locale'], 'validators'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$file = __DIR__.'/Resource/locale/validator.'.$app['locale'].'.yml'; |
109
|
|
|
if (file_exists($file)) { |
110
|
|
|
$translator->addResource('yaml', $file, $app['locale'], 'validators'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$translator->addResource('yaml', __DIR__.'/Resource/locale/ja.yml', $app['locale']); |
114
|
|
|
|
115
|
36 |
|
return $translator; |
116
|
|
|
})); |
117
|
|
|
|
118
|
|
|
$app->mount('', new ControllerProvider\InstallControllerProvider()); |
119
|
|
|
$app->register(new ServiceProvider\InstallServiceProvider()); |
120
|
|
|
|
121
|
|
|
$app->error(function(\Exception $e, $code) use ($app) { |
|
|
|
|
122
|
|
|
if ($code === 404) { |
123
|
|
|
return $app->redirect($app->url('install')); |
124
|
|
|
} elseif ($app['debug']) { |
125
|
|
|
return; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $app['twig']->render('error.twig', array( |
129
|
|
|
'error' => 'エラーが発生しました.', |
130
|
|
|
)); |
131
|
|
|
}); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|