22
33declare (strict_types=1 );
44
5+ require_once 'vendor/autoload.php ' ;
6+
57const ENVIRONMENT_DEVELOPMENT = 'development ' ;
68const ENVIRONMENT_PRODUCTION = 'production ' ;
79
810// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
911
1012function 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
2731function 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+
5258array_walk ($ files , 'copyFile ' );
0 commit comments