|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
| 5 | +require_once 'vendor/autoload.php'; |
| 6 | + |
| 7 | +const ENVIRONMENT_DEVELOPMENT = 'development'; |
| 8 | +const ENVIRONMENT_PRODUCTION = 'production'; |
| 9 | + |
5 | 10 | // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols |
6 | 11 |
|
7 | 12 | function copyFile(array $file): void |
8 | 13 | { |
| 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 | + |
9 | 19 | if (is_readable($file['destination'])) { |
10 | | - 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; |
11 | 26 | } else { |
12 | | - if (! copy($file['source'], $file['destination'])) { |
13 | | - echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; |
14 | | - } else { |
15 | | - echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; |
16 | | - } |
| 27 | + echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; |
17 | 28 | } |
18 | 29 | } |
19 | 30 |
|
| 31 | +function getEnvironment(): string |
| 32 | +{ |
| 33 | + return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION; |
| 34 | +} |
| 35 | + |
| 36 | +// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder |
| 37 | +// the `environment` key will indicate on what environments the file will be copied, |
20 | 38 | $files = [ |
21 | 39 | [ |
22 | 40 | 'source' => 'config/autoload/local.php.dist', |
23 | 41 | 'destination' => 'config/autoload/local.php', |
| 42 | + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], |
24 | 43 | ], |
25 | 44 | [ |
26 | 45 | 'source' => 'config/autoload/local.test.php.dist', |
27 | 46 | 'destination' => 'config/autoload/local.test.php', |
| 47 | + 'environment' => [ENVIRONMENT_DEVELOPMENT], |
28 | 48 | ], |
29 | 49 | [ |
30 | 50 | 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', |
31 | 51 | 'destination' => 'config/autoload/mail.global.php', |
| 52 | + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], |
32 | 53 | ], |
33 | 54 | ]; |
34 | 55 |
|
| 56 | +echo "Using environment setting: " . getEnvironment() . PHP_EOL; |
| 57 | + |
35 | 58 | array_walk($files, 'copyFile'); |
0 commit comments