|
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
| 5 | +const ENVIRONMENT_DEVELOPMENT = 'development'; |
| 6 | +const ENVIRONMENT_PRODUCTION = 'production'; |
| 7 | + |
5 | 8 | // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols |
6 | 9 |
|
7 | 10 | function copyFile(array $file): void |
8 | 11 | { |
9 | 12 | if (is_readable($file['destination'])) { |
10 | 13 | echo "File {$file['destination']} already exists." . PHP_EOL; |
11 | 14 | } 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; |
14 | 17 | } 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 | + } |
16 | 23 | } |
17 | 24 | } |
18 | 25 | } |
19 | 26 |
|
| 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, |
20 | 34 | $files = [ |
21 | 35 | [ |
22 | 36 | 'source' => 'config/autoload/local.php.dist', |
23 | 37 | 'destination' => 'config/autoload/local.php', |
| 38 | + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], |
24 | 39 | ], |
25 | 40 | [ |
26 | 41 | 'source' => 'config/autoload/local.test.php.dist', |
27 | 42 | 'destination' => 'config/autoload/local.test.php', |
| 43 | + 'environment' => [ENVIRONMENT_DEVELOPMENT], |
28 | 44 | ], |
29 | 45 | [ |
30 | 46 | 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', |
31 | 47 | 'destination' => 'config/autoload/mail.global.php', |
| 48 | + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], |
32 | 49 | ], |
33 | 50 | ]; |
34 | 51 |
|
|
0 commit comments