Skip to content

Commit 9d4fcec

Browse files
authored
Merge pull request #528 from dotkernel/issue-526
Composer post install script
2 parents 08efa63 + 20bb143 commit 9d4fcec

File tree

6 files changed

+55
-128
lines changed

6 files changed

+55
-128
lines changed

.github/workflows/codecov.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ jobs:
4444
- name: Install dependencies with composer
4545
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
4646

47-
- name: Setup project
48-
run: |
49-
mv config/autoload/local.php.dist config/autoload/local.php
50-
mv config/autoload/mail.local.php.dist config/autoload/mail.local.php
51-
mv config/autoload/local.test.php.dist config/autoload/local.test.php
52-
5347
- name: Collect code coverage with PHPUnit
5448
run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml
5549

.github/workflows/static-analysis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,5 @@ jobs:
4444
- name: Install dependencies with composer
4545
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
4646

47-
- name: Setup project
48-
run: |
49-
mv config/autoload/local.php.dist config/autoload/local.php
50-
mv config/autoload/mail.local.php.dist config/autoload/mail.local.php
51-
mv config/autoload/local.test.php.dist config/autoload/local.test.php
52-
5347
- name: Run static analysis with PHPStan
5448
run: vendor/bin/phpstan analyse

.laminas-ci/pre-run.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ if [[ ${COMMAND} =~ phpunit ]];then
99
apt-get install php"${PHP_VERSION}"-sqlite3
1010

1111
cp config/autoload/local.php.dist config/autoload/local.php
12-
cp config/autoload/mail.local.php.dist config/autoload/mail.local.php
1312
cp config/autoload/local.test.php.dist config/autoload/local.test.php
1413

1514
fi
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
const ENVIRONMENT_DEVELOPMENT = 'development';
6+
const ENVIRONMENT_PRODUCTION = 'production';
7+
8+
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
9+
10+
function copyFile(array $file): void
11+
{
12+
if (is_readable($file['destination'])) {
13+
echo "File {$file['destination']} already exists." . PHP_EOL;
14+
} 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+
}
24+
}
25+
}
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,
34+
$files = [
35+
[
36+
'source' => 'config/autoload/local.php.dist',
37+
'destination' => 'config/autoload/local.php',
38+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
39+
],
40+
[
41+
'source' => 'config/autoload/local.test.php.dist',
42+
'destination' => 'config/autoload/local.test.php',
43+
'environment' => [ENVIRONMENT_DEVELOPMENT],
44+
],
45+
[
46+
'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist',
47+
'destination' => 'config/autoload/mail.global.php',
48+
'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION],
49+
],
50+
];
51+
52+
array_walk($files, 'copyFile');

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@
104104
"post-create-project-cmd": [
105105
"@development-enable"
106106
],
107+
"post-update-cmd": [
108+
"php bin/composer-post-install-script.php"
109+
],
107110
"development-disable": "laminas-development-mode disable",
108111
"development-enable": "laminas-development-mode enable",
109112
"development-status": "laminas-development-mode status",

config/autoload/mail.local.php.dist

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)