Failed Conditions
Pull Request — master (#1798)
by Kentaro
691:01 queued 682:45
created

eccube_install.php ➔ displayEnvironmentVariables()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
if (php_sapi_name() !== 'cli') {
4
    exit(1);
5
}
6
7
set_time_limit(0);
8
ini_set('display_errors', 1);
9
10
define('COMPOSER_FILE', 'composer.phar');
11
define('COMPOSER_SETUP_FILE', 'composer-setup.php');
12
13
setUseAnsi($argv);
14
15
$argv = is_array($argv) ? $argv : array();
16
17
$argv[1] = isset($argv[1]) ? $argv[1] : null;
18
$argv[2] = isset($argv[2]) ? $argv[2] : null;
19
20
if (in_array('--help', $argv) || empty($argv[1])) {
21
    displayHelp($argv);
22
    exit(0);
23
}
24
25
if (in_array('-v', $argv) || in_array('--version', $argv)) {
26
    require __DIR__.'/src/Eccube/Common/Constant.php';
27
    echo 'EC-CUBE '.Eccube\Common\Constant::VERSION.PHP_EOL;
28
    exit(0);
29
}
30
31
out('EC-CUBE3 installer use database driver of ', null, false);
32
33
$database_driver = 'pdo_sqlite';
34
switch($argv[1]) {
35
    case 'mysql':
36
        $database_driver = 'pdo_mysql';
37
        break;
38
    case 'pgsql':
39
        $database_driver = 'pdo_pgsql';
40
        break;
41
    default:
42
    case 'sqlite':
43
    case 'sqlite3':
44
    case 'sqlite3-in-memory':
45
        $database_driver = 'pdo_sqlite';
46
}
47
out($database_driver);
48
49
initializeDefaultVariables($database_driver);
50
51
if (in_array('-V', $argv) || in_array('--verbose', $argv)) {
52
    displayEnvironmentVariables();
53
}
54
55
$database = getDatabaseConfig($database_driver);
56
$connectionParams = $database['database'];
57
58
if ($argv[2] != 'none') {
59
    composerSetup();
60
    composerInstall();
61
}
62
63
require __DIR__.'/autoload.php';
64
65
out('update permissions...');
66
updatePermissions($argv);
67
68
createConfigFiles($database_driver);
69
70
if (!in_array('--skip-createdb', $argv)) {
71
    createDatabase($connectionParams);
72
}
73
74
$app = createApplication();
75
initializeDatabase($app);
76
out('EC-CUBE3 install finished successfully!', 'success');
77
$root_urlpath = getenv('ROOT_URLPATH');
78
if (PHP_VERSION_ID >= 50400 && empty($root_urlpath)) {
79
    out('PHP built-in web server to run applications, `php -S localhost:8080 -t html`', 'info');
80
    out('Open your browser and access the http://localhost:8080/', 'info');
81
}
82
exit(0);
83
84
function displayHelp($argv)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "displayHelp" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
85
{
86
    echo <<<EOF
87
EC-CUBE3 Installer
88
------------------
89
Usage:
90
${argv[0]} [mysql|pgsql|sqlite3] [none] [options]
91
92
Arguments[1]:
93
Specify database types
94
95
Arguments[2]:
96
Specifying the "none" to skip the installation of Composer
97
98
Options:
99
-v, --version        print ec-cube version
100
-V, --verbose        enable verbose output
101
--skip-createdb      skip to create database
102
--help               this help
103
--ansi               force ANSI color output
104
--no-ansi            disable ANSI color output
105
106
Environment variables:
107
108
EOF;
109
    foreach (getExampleVariables() as $name => $value) {
110
        echo $name.'='.$value.PHP_EOL;
111
    }
112
}
113
114
function initializeDefaultVariables($database_driver)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "initializeDefaultVariables" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
115
{
116
    switch ($database_driver) {
117
        case 'pdo_pgsql':
118
            putenv('ROOTUSER='.(getenv('ROOTUSER') ? getenv('ROOTUSER') : (getenv('DBUSER') ? getenv('DBUSER') : 'postgres')));
119
            putenv('ROOTPASS='.(getenv('ROOTPASS') ? getenv('ROOTPASS') : (getenv('DBPASS') ? getenv('DBPASS') : 'password')));
120
            putenv('DBSERVER='.(getenv('DBSERVER') ? getenv('DBSERVER') : 'localhost'));
121
            putenv('DBNAME='.(getenv('DBNAME') ? getenv('DBNAME') : 'cube3_dev'));
122
            putenv('DBUSER='.(getenv('DBUSER') ? getenv('DBUSER') : 'cube3_dev_user'));
123
            putenv('DBPORT='.(getenv('DBPORT') ? getenv('DBPORT') : '5432'));
124
            putenv('DBPASS='.(getenv('DBPASS') ? getenv('DBPASS') : 'password'));
125
            break;
126
        case 'pdo_mysql':
127
            putenv('ROOTUSER='.(getenv('ROOTUSER') ? getenv('ROOTUSER') : (getenv('DBUSER') ? getenv('DBUSER') : 'root')));
128
            putenv('DBSERVER='.(getenv('DBSERVER') ? getenv('DBSERVER') : 'localhost'));
129
            putenv('DBNAME='.(getenv('DBNAME') ? getenv('DBNAME') : 'cube3_dev'));
130
            putenv('DBUSER='.(getenv('DBUSER') ? getenv('DBUSER') : 'cube3_dev_user'));
131
            putenv('DBPORT='.(getenv('DBPORT') ? getenv('DBPORT') : '3306'));
132
            putenv('DBPASS='.(getenv('DBPASS') ? getenv('DBPASS') : 'password'));
133
            if (getenv('TRAVIS')) {
134
                putenv('DBPASS=');
135
                putenv('ROOTPASS=');
136
            } else {
137
                putenv('DBPASS='.(getenv('DBPASS') ? getenv('DBPASS') : 'password'));
138
                putenv('ROOTPASS='.(getenv('ROOTPASS') ? getenv('ROOTPASS') : (getenv('DBPASS') ? getenv('DBPASS') : 'password')));
139
            }
140
            break;
141
        default:
142
        case 'pdo_sqlite':
143
            break;
144
    }
145
    putenv('SHOP_NAME='.(getenv('SHOP_NAME') ? getenv('SHOP_NAME') : 'EC-CUBE SHOP'));
146
    putenv('ADMIN_MAIL='.(getenv('ADMIN_MAIL') ? getenv('ADMIN_MAIL') : '[email protected]'));
147
    putenv('ADMIN_USER='.(getenv('ADMIN_USER') ? getenv('ADMIN_USER') : 'admin'));
148
    putenv('ADMIN_PASS='.(getenv('ADMIN_PASS') ? getenv('ADMIN_PASS') : 'password'));
149
    putenv('MAIL_BACKEND='.(getenv('MAIL_BACKEND') ? getenv('MAIL_BACKEND') : 'smtp'));
150
    putenv('MAIL_HOST='.(getenv('MAIL_HOST') ? getenv('MAIL_HOST') : 'localhost'));
151
    putenv('MAIL_PORT='.(getenv('MAIL_PORT') ? getenv('MAIL_PORT') : 25));
152
    putenv('MAIL_USER='.(getenv('MAIL_USER') ? getenv('MAIL_USER') : null));
153
    putenv('MAIL_PASS='.(getenv('MAIL_PASS') ? getenv('MAIL_PASS') : null));
154
    putenv('ADMIN_ROUTE='.(getenv('ADMIN_ROUTE') ? getenv('ADMIN_ROUTE') : 'admin'));
155
    putenv('ROOT_URLPATH='.(getenv('ROOT_URLPATH') ? getenv('ROOT_URLPATH') : null));
156
}
157
158
function getExampleVariables()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "getExampleVariables" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
159
{
160
    return array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
161
        'ADMIN_USER' => 'admin',
162
        'ADMIN_MAIL' => '[email protected]',
163
        'SHOP_NAME' => 'EC-CUBE SHOP',
164
        'ADMIN_ROUTE' => 'admin',
165
        'ROOT_URLPATH' => '<ec-cube install path>',
166
        'DBSERVER' => '127.0.0.1',
167
        'DBNAME' => 'cube3_dev',
168
        'DBUSER' => 'cube3_dev_user',
169
        'DBPASS' => 'password',
170
        'DBPORT' => '<database port>',
171
        'ROOTUSER' => 'root|postgres',
172
        'ROOTPASS' => 'password',
173
        'MAIL_BACKEND' => 'smtp',
174
        'MAIL_HOST' => 'localhost',
175
        'MAIL_PORT' => '25',
176
        'MAIL_USER' => '<SMTP AUTH user>',
177
        'MAIL_PASS' => '<SMTP AUTH password>'
178
    );
179
}
180
181
182
function displayEnvironmentVariables()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "displayEnvironmentVariables" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
183
{
184
    echo 'Environment variables:'.PHP_EOL;
185
    foreach (array_keys(getExampleVariables()) as $name) {
186
        echo $name.'='.getenv($name).PHP_EOL;
187
    }
188
}
189
190
function composerSetup()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "composerSetup" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
191
{
192
    if (!file_exists(__DIR__.'/'.COMPOSER_FILE)) {
193
        if (!file_exists(__DIR__.'/'.COMPOSER_SETUP_FILE)) {
194
            copy('https://getcomposer.org/installer', COMPOSER_SETUP_FILE);
195
        }
196
197
        $sha = hash_file('SHA384', COMPOSER_SETUP_FILE).PHP_EOL;
198
        out(COMPOSER_SETUP_FILE.': '.$sha);
199
200
        $command = 'php '.COMPOSER_SETUP_FILE;
201
        out("execute: $command", 'info');
202
        passthru($command);
203
        unlink(COMPOSER_SETUP_FILE);
204
    } else {
205
        $command = 'php '.COMPOSER_FILE.' self-update';
206
        passthru($command);
207
    }
208
}
209
210
function composerInstall()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "composerInstall" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
211
{
212
    $command = 'php '.COMPOSER_FILE.' install --dev --no-interaction';
213
    passthru($command);
214
}
215
216
function createDatabase(array $connectionParams)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "createDatabase" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
217
{
218
    $dbname = $connectionParams['dbname'];
219
    switch ($connectionParams['driver']) {
220 View Code Duplication
        case 'pdo_pgsql':
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...
221
            $connectionParams['dbname'] = 'postgres';
222
            $connectionParams['user'] = getenv('ROOTUSER');
223
            $connectionParams['password'] = getenv('ROOTPASS');
224
            break;
225 View Code Duplication
        case 'pdo_mysql':
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...
226
            $connectionParams['dbname'] = 'mysql';
227
            $connectionParams['user'] = getenv('ROOTUSER');
228
            $connectionParams['password'] = getenv('ROOTPASS');
229
            break;
230
        default:
231
        case 'pdo_sqlite':
232
            $connectionParams['dbname'] = '';
233
            if (file_exists($dbname)) {
234
                out('remove database to '.$dbname, 'info');
235
                unlink($dbname);
236
            }
237
            break;
238
    }
239
240
    $config = new \Doctrine\DBAL\Configuration();
241
    $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
242
    $sm = $conn->getSchemaManager();
243
    out('Created database connection...', 'info');
244
245
    if ($connectionParams['driver'] != 'pdo_sqlite') {
246
        $databases = $sm->listDatabases();
247
        if (in_array($dbname, $databases)) {
248
            out('database exists '.$dbname, 'info');
249
            out('drop database to '.$dbname, 'info');
250
            $sm->dropDatabase($dbname);
251
        }
252
    }
253
    out('create database to '.$dbname, 'info');
254
    $sm->createDatabase($dbname);
255
}
256
257
/**
258
 * @return \Eccube\Application
259
 */
260
function createApplication()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "createApplication" in a static class
Loading history...
261
{
262
    $app = \Eccube\Application::getInstance();
263
    $app['debug'] = true;
264
    $app->initDoctrine();
265
    $app->initSecurity();
266
    $app->register(new \Silex\Provider\FormServiceProvider());
267
    $app->register(new \Eccube\ServiceProvider\EccubeServiceProvider());
268
    $app->boot();
269
    return $app;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
270
}
271
272
function initializeDatabase(\Eccube\Application $app)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "initializeDatabase" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
273
{
274
    // Get an instance of your entity manager
275
    $entityManager = $app['orm.em'];
276
277
    $pdo = $entityManager->getConnection()->getWrappedConnection();
278
279
    // Clear Doctrine to be safe
280
    $entityManager->getConnection()->getConfiguration()->setSQLLogger(null);
281
    $entityManager->clear();
282
    gc_collect_cycles();
283
284
    // Schema Tool to process our entities
285
    $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
286
    $classes = $entityManager->getMetaDataFactory()->getAllMetaData();
287
288
    // Drop all classes and re-build them for each test case
289
    out('Dropping database schema...', 'info');
290
    $tool->dropSchema($classes);
291
    out('Creating database schema...', 'info');
292
    $tool->createSchema($classes);
293
    out('Database schema created successfully!', 'success');
294
    $config = new \Doctrine\DBAL\Migrations\Configuration\Configuration($app['db']);
295
    $config->setMigrationsNamespace('DoctrineMigrations');
296
297
    $migrationDir = __DIR__.'/src/Eccube/Resource/doctrine/migration';
298
    $config->setMigrationsDirectory($migrationDir);
299
    $config->registerMigrationsFromDirectory($migrationDir);
300
301
    $migration = new \Doctrine\DBAL\Migrations\Migration($config);
302
    $migration->migrate();
303
    out('Database migration successfully!', 'success');
304
305
    $login_id = getenv('ADMIN_USER');
306
    $login_password = getenv('ADMIN_PASS');
307
    $passwordEncoder = new \Eccube\Security\Core\Encoder\PasswordEncoder($app['config']);
308
    $salt = \Eccube\Util\Str::random(32);
309
    $encodedPassword = $passwordEncoder->encodePassword($login_password, $salt);
310
311
    out('Creating admin accounts...', 'info');
312
    $sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, :login_id, :admin_pass , :salt , '1', '0', '0', '1', '1', current_timestamp, current_timestamp,'管理者', 'EC-CUBE SHOP');";
313
    $stmt = $pdo->prepare($sql);
314
    $stmt->execute(
315
        array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
316
            ':login_id' => $login_id,
317
            ':admin_pass' => $encodedPassword,
318
            ':salt' => $salt
319
        )
320
    );
321
    $stmt->closeCursor();
322
323
    $shop_name = getenv('SHOP_NAME');
324
    $admin_mail = getenv('ADMIN_MAIL');
325
    $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, :shop_name, :admin_mail1, :admin_mail2, :admin_mail3, :admin_mail4, current_timestamp, 0)";
326
    $stmt = $pdo->prepare($sql);
327
    $stmt->execute(
328
        array(
329
            ':shop_name' => $shop_name,
330
            ':admin_mail1' => $admin_mail,
331
            ':admin_mail2' => $admin_mail,
332
            ':admin_mail3' => $admin_mail,
333
            ':admin_mail4' => $admin_mail,
334
        )
335
    );
336
    $stmt->closeCursor();
337
}
338
339
function updatePermissions($argv)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "updatePermissions" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
340
{
341
    $finder = \Symfony\Component\Finder\Finder::create();
342
    $finder
343
        ->in('html')->notName('.htaccess')
344
        ->in('app')->notName('console');
345
346
    $verbose = false;
347
    if (in_array('-V', $argv) || in_array('--verbose', $argv)) {
348
        $verbose = true;
349
    }
350
    foreach ($finder as $content) {
351
        $permission = $content->getPerms();
352
        // see also http://www.php.net/fileperms
353
        if (!($permission & 0x0010) || !($permission & 0x0002)) {
354
            $realPath = $content->getRealPath();
355
            if ($verbose) {
356
                out(sprintf('%s %s to ', $realPath, substr(sprintf('%o', $permission), -4)), 'info', false);
357
            }
358
            $permission = !($permission & 0x0020) ? $permission += 040 : $permission; // g+r
359
            $permission = !($permission & 0x0010) ? $permission += 020 : $permission; // g+w
360
            $permission = !($permission & 0x0004) ? $permission += 04 : $permission;  // o+r
361
            $permission = !($permission & 0x0002) ? $permission += 02 : $permission;  // o+w
362
            $result = chmod($realPath, $permission);
363
            if ($verbose) {
364
                if ($result) {
365
                    out(substr(sprintf('%o', $permission), -4), 'info');
366
                } else {
367
                    out('failure', 'error');
368
                }
369
            }
370
        }
371
    }
372
}
373
374
function createConfigFiles($database_driver)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "createConfigFiles" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
375
{
376
    $config_path = __DIR__.'/app/config/eccube';
377
    createYaml(getConfig(), $config_path.'/config.yml');
378
    createYaml(getDatabaseConfig($database_driver), $config_path.'/database.yml');
379
    createYaml(getMailConfig(), $config_path.'/mail.yml');
380
    createYaml(getPathConfig(), $config_path.'/path.yml');
381
}
382
383
function createYaml($config, $path)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "createYaml" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
384
{
385
    $content = \Symfony\Component\Yaml\Yaml::dump($config);
386
    $fs = new \Symfony\Component\Filesystem\Filesystem();
387
    $fs->dumpFile($path, $content);
388
}
389
390
function getConfig()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "getConfig" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
391
{
392
    $config = array (
393
        'auth_magic' => \Eccube\Util\Str::random(32),
394
        'password_hash_algos' => 'sha256',
395
        'shop_name' => getenv('SHOP_NAME'),
396
        'force_ssl' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
397
        'admin_allow_host' =>
398
        array (
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
399
        ),
400
        'cookie_lifetime' => 0,
401
        'locale' => 'ja',
402
        'timezone' => 'Asia/Tokyo',
403
        'eccube_install' => 1,
404
    );
405
    return $config;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
406
}
407
408
function getDatabaseConfig($database_driver)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "getDatabaseConfig" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
409
{
410
    $database = array (
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
411
        'database' =>
412
        array (
413
            'driver' => $database_driver,
414
        )
415
    );
416
417
    switch ($database_driver) {
418
        case 'pdo_sqlite':
419
            $database['database']['dbname'] = $database['database']['path'] = __DIR__.'/app/config/eccube/eccube.db';
420
421
            break;
422
        case 'pdo_pgsql':
423
        case 'pdo_mysql':
424
            $database['database']['host'] = getenv('DBSERVER');
425
            $database['database']['dbname'] = getenv('DBNAME');
426
            $database['database']['user'] = getenv('DBUSER');
427
            $database['database']['port'] = getenv('DBPORT');
428
            $database['database']['password'] = getenv('DBPASS');
429
            $database['database']['port'] = getenv('DBPORT');
430
            break;
431
    }
432
    $database['database']['charset'] = 'utf8';
433
    $database['database']['defaultTableOptions'] = array('collate' => 'utf8_general_ci');
434
    return $database;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
435
}
436
437
function getMailConfig()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "getMailConfig" in a static class
Loading history...
introduced by
Missing function doc comment
Loading history...
438
{
439
    $mail = array (
440
        'mail' =>
441
        array (
442
            'transport' => getenv('MAIL_BACKEND'),
443
            'host' => getenv('MAIL_HOST'),
444
            'port' => getenv('MAIL_PORT'),
445
            'username' => getenv('MAIL_USER'),
446
            'password' => getenv('MAIL_PASS'),
447
            'encryption' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
448
            'auth_mode' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
449
            'charset_iso_2022_jp' => false,
450
        ),
451
    );
452
    return $mail;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
453
}
454
455
/**
456
 * @see \Eccube\Controller\Install\InstallController::createPathYamlFile()
457
 */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
458
function getPathConfig()
0 ignored issues
show
Coding Style introduced by
Consider putting global function "getPathConfig" in a static class
Loading history...
459
{
460
    $ADMIN_ROUTE = getenv('ADMIN_ROUTE');
461
    $TEMPLATE_CODE = 'default';
462
    $USER_DATA_ROUTE = 'user_data';
463
    $ROOT_DIR = realpath(__DIR__);
464
    $ROOT_URLPATH = getenv('ROOT_URLPATH');
465
    $ROOT_PUBLIC_URLPATH = $ROOT_URLPATH.RELATIVE_PUBLIC_DIR_PATH;
466
467
    $target = array('${ADMIN_ROUTE}', '${TEMPLATE_CODE}', '${USER_DATA_ROUTE}', '${ROOT_DIR}', '${ROOT_URLPATH}', '${ROOT_PUBLIC_URLPATH}');
468
    $replace = array($ADMIN_ROUTE, $TEMPLATE_CODE, $USER_DATA_ROUTE, $ROOT_DIR, $ROOT_URLPATH, $ROOT_PUBLIC_URLPATH);
469
    $content = str_replace(
470
        $target,
471
        $replace,
472
        file_get_contents(__DIR__.'/src/Eccube/Resource/config/path.yml.dist')
473
    );
474
    return \Symfony\Component\Yaml\Yaml::parse($content);
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
475
}
476
477
/**
0 ignored issues
show
introduced by
Doc comment for parameter "$argv" missing
Loading history...
478
 * @link https://github.com/composer/windows-setup/blob/master/src/php/installer.php
479
 */
480
function setUseAnsi($argv)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "setUseAnsi" in a static class
Loading history...
481
{
482
    // --no-ansi wins over --ansi
483
    if (in_array('--no-ansi', $argv)) {
484
        define('USE_ANSI', false);
485
    } elseif (in_array('--ansi', $argv)) {
486
        define('USE_ANSI', true);
487
    } else {
488
        // On Windows, default to no ANSI, except in ANSICON and ConEmu.
489
        // Everywhere else, default to ANSI if stdout is a terminal.
490
        define(
491
            'USE_ANSI',
492
            (DIRECTORY_SEPARATOR == '\\')
493
                ? (false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'))
494
                : (function_exists('posix_isatty') && posix_isatty(1))
495
        );
496
    }
497
}
498
499
/**
0 ignored issues
show
introduced by
Doc comment for parameter "$text" missing
Loading history...
introduced by
Doc comment for parameter "$color" missing
Loading history...
introduced by
Doc comment for parameter "$newLine" missing
Loading history...
500
 * @link https://github.com/composer/windows-setup/blob/master/src/php/installer.php
501
 */
502
function out($text, $color = null, $newLine = true)
0 ignored issues
show
Coding Style introduced by
Consider putting global function "out" in a static class
Loading history...
503
{
504
    $styles = array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
505
        'success' => "\033[0;32m%s\033[0m",
506
        'error' => "\033[31;31m%s\033[0m",
507
        'info' => "\033[33;33m%s\033[0m"
508
    );
509
    $format = '%s';
510
    if (isset($styles[$color]) && USE_ANSI) {
511
        $format = $styles[$color];
512
    }
513
    if ($newLine) {
514
        $format .= PHP_EOL;
515
    }
516
    printf($format, $text);
517
}
518