Failed Conditions
Pull Request — master (#1798)
by Kentaro
34:37
created

eccube_install.php ➔ createApplication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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