-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomposer-post-install-script.php
More file actions
69 lines (58 loc) · 2.21 KB
/
composer-post-install-script.php
File metadata and controls
69 lines (58 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
const ENVIRONMENT_DEVELOPMENT = 'development';
const ENVIRONMENT_PRODUCTION = 'production';
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
/**
* @param array{source: string, destination: string, environment: array<string>} $file
*/
function copyFile(array $file): void
{
if (! in_array(getEnvironment(), $file['environment'])) {
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
return;
}
if (is_readable($file['destination'])) {
echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL;
return;
}
if (! copy($file['source'], $file['destination'])) {
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
} else {
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
}
}
function getEnvironment(): string
{
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
}
/**
* When adding files to the below array:
* - `source` and `destination` paths must be relative to the project root folder
* - `environment` key will indicate on what environments the file will be copied
*/
$files = [
[
'source' => 'config/autoload/local.php.dist',
'destination' => 'config/autoload/local.php',
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
],
[
'source' => 'config/autoload/log.local.php.dist',
'destination' => 'config/autoload/log.local.php',
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
],
[
'source' => 'config/autoload/messenger.local.php.dist',
'destination' => 'config/autoload/messenger.local.php',
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
],
[
'source' => 'config/autoload/swoole.local.php.dist',
'destination' => 'config/autoload/swoole.local.php',
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
],
];
echo "Using environment setting: " . getEnvironment() . PHP_EOL;
array_walk($files, 'copyFile');