Skip to content

Commit a4f1216

Browse files
authored
Update composer-post-install-script.php
Signed-off-by: arhimede <julian@dotkernel.com>
1 parent 1a3351a commit a4f1216

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

bin/composer-post-install-script.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,50 @@
22

33
declare(strict_types=1);
44

5+
const ENVIRONMENT_DEVELOPMENT = 'development';
6+
const ENVIRONMENT_PRODUCTION = 'production';
7+
58
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
69

710
function copyFile(array $file): void
811
{
912
if (is_readable($file['destination'])) {
1013
echo "File {$file['destination']} already exists." . PHP_EOL;
1114
} else {
12-
if (! copy($file['source'], $file['destination'])) {
13-
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
15+
if (! in_array(getEnvironment(), $file['environment'])) {
16+
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
1417
} else {
15-
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
18+
if (! copy($file['source'], $file['destination'])) {
19+
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
20+
} else {
21+
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
22+
}
1623
}
1724
}
1825
}
1926

27+
function getEnvironment(): string
28+
{
29+
return file_exists('config/autoload/development.local.php') ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
30+
}
31+
32+
// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder
33+
// the `environment` key will indicate on what environments the file will be copied,
2034
$files = [
2135
[
2236
'source' => 'config/autoload/local.php.dist',
2337
'destination' => 'config/autoload/local.php',
38+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
2439
],
2540
[
2641
'source' => 'config/autoload/local.test.php.dist',
2742
'destination' => 'config/autoload/local.test.php',
43+
'environment' => [ENVIRONMENT_DEVELOPMENT],
2844
],
2945
[
3046
'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist',
3147
'destination' => 'config/autoload/mail.global.php',
48+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
3249
],
3350
];
3451

0 commit comments

Comments
 (0)