Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions bin/composer-post-install-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@

declare(strict_types=1);

require_once 'vendor/autoload.php';

const ENVIRONMENT_DEVELOPMENT = 'development';
const ENVIRONMENT_PRODUCTION = 'production';

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

function copyFile(array $file): void
{
if (! in_array(getEnvironment(), $file['environment'])) {
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
return;
}

if (is_readable($file['destination'])) {
echo "File {$file['destination']} already exists." . PHP_EOL;
echo "File {$file['destination']} already exists. Skipping..." . PHP_EOL;
return;
}

if (! copy($file['source'], $file['destination'])) {
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
} else {
if (! in_array(getEnvironment(), $file['environment'])) {
echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL;
} else {
if (! copy($file['source'], $file['destination'])) {
echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL;
} else {
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
}
}
echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL;
}
}

function getEnvironment(): string
{
return file_exists('config/autoload/development.local.php') ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
return getenv('COMPOSER_DEV_MODE') === '1' ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION;
}

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

echo "Using environment setting: " . getEnvironment() . PHP_EOL;

array_walk($files, 'copyFile');