Skip to content

Commit 959500d

Browse files
authored
Merge pull request #337 from dotkernel/issue-334
Issue #334: Fixed Composer `post-update-cmd` command
2 parents 06793ad + 56c989d commit 959500d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

bin/composer-post-install-script.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@
22

33
declare(strict_types=1);
44

5+
require_once 'vendor/autoload.php';
6+
57
const ENVIRONMENT_DEVELOPMENT = 'development';
68
const ENVIRONMENT_PRODUCTION = 'production';
79

810
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
911

1012
function copyFile(array $file): void
1113
{
14+
if (! in_array(getEnvironment(), $file['environment'])) {
15+
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
16+
return;
17+
}
18+
1219
if (is_readable($file['destination'])) {
13-
echo "File {$file['destination']} already exists." . PHP_EOL;
20+
echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL;
21+
return;
22+
}
23+
24+
if (! copy($file['source'], $file['destination'])) {
25+
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
1426
} else {
15-
if (! in_array(getEnvironment(), $file['environment'])) {
16-
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
17-
} else {
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-
}
23-
}
27+
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
2428
}
2529
}
2630

2731
function getEnvironment(): string
2832
{
29-
return file_exists('config/autoload/development.local.php') ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
33+
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
3034
}
3135

3236
// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder
@@ -49,4 +53,6 @@ function getEnvironment(): string
4953
],
5054
];
5155

56+
echo "Using environment setting: " . getEnvironment() . PHP_EOL;
57+
5258
array_walk($files, 'copyFile');

0 commit comments

Comments
 (0)