From 2e64da59fa7f3675d11007be76b484caa47876bf Mon Sep 17 00:00:00 2001 From: MarioRadu Date: Tue, 10 Dec 2024 13:17:04 +0200 Subject: [PATCH 1/3] post install script Signed-off-by: MarioRadu --- .github/workflows/codecov.yml | 6 -- .github/workflows/static-analysis.yml | 6 -- .laminas-ci/pre-run.sh | 1 - bin/composer-post-install-script.php | 35 ++++++++ config/autoload/mail.local.php.dist | 115 -------------------------- 5 files changed, 35 insertions(+), 128 deletions(-) create mode 100644 bin/composer-post-install-script.php delete mode 100644 config/autoload/mail.local.php.dist diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 293bb8eb..59c4b08d 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -44,12 +44,6 @@ jobs: - name: Install dependencies with composer run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Setup project - run: | - mv config/autoload/local.php.dist config/autoload/local.php - mv config/autoload/mail.local.php.dist config/autoload/mail.local.php - mv config/autoload/local.test.php.dist config/autoload/local.test.php - - name: Collect code coverage with PHPUnit run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 6a700f5d..ee7251d0 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -44,11 +44,5 @@ jobs: - name: Install dependencies with composer run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Setup project - run: | - mv config/autoload/local.php.dist config/autoload/local.php - mv config/autoload/mail.local.php.dist config/autoload/mail.local.php - mv config/autoload/local.test.php.dist config/autoload/local.test.php - - name: Run static analysis with PHPStan run: vendor/bin/phpstan analyse diff --git a/.laminas-ci/pre-run.sh b/.laminas-ci/pre-run.sh index 4a356038..34626d54 100755 --- a/.laminas-ci/pre-run.sh +++ b/.laminas-ci/pre-run.sh @@ -9,7 +9,6 @@ if [[ ${COMMAND} =~ phpunit ]];then apt-get install php"${PHP_VERSION}"-sqlite3 cp config/autoload/local.php.dist config/autoload/local.php - cp config/autoload/mail.local.php.dist config/autoload/mail.local.php cp config/autoload/local.test.php.dist config/autoload/local.test.php fi diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php new file mode 100644 index 00000000..af2e8a93 --- /dev/null +++ b/bin/composer-post-install-script.php @@ -0,0 +1,35 @@ + 'config/autoload/local.php.dist', + 'destination' => 'config/autoload/local.php', + ], + [ + 'source' => 'config/autoload/local.test.php.dist', + 'destination' => 'config/autoload/local.test.php', + ], + [ + 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', + 'destination' => 'config/autoload/mail.global.php', + ], +]; + +array_walk($files, 'copyFile'); diff --git a/config/autoload/mail.local.php.dist b/config/autoload/mail.local.php.dist deleted file mode 100644 index b3b25676..00000000 --- a/config/autoload/mail.local.php.dist +++ /dev/null @@ -1,115 +0,0 @@ - [ - //the key is the mail service name, this is the default one, which does not extends any configuration - 'default' => [ - //tells which other mail service configuration to extend - 'extends' => null, - - /** - * the mail transport to use - * can be any class implementing Symfony\Component\Mailer\Transport\TransportInterface - * - * for standard mail transports, you can use these aliases - * - sendmail => Symfony\Component\Mailer\Transport\SendmailTransport - * - smtp => Symfony\Component\Mailer\Transport\Smtp\SmtpTransport - * - * defaults to sendmail - **/ - - 'transport' => Symfony\Component\Mailer\Transport\SendmailTransport::class, - - //message configuration - 'message_options' => [ - - //from email address of the email - 'from' => '', - - //from name to be displayed instead of from address - 'from_name' => '', - - //reply-to email address of the email - 'reply_to' => '', - - //replyTo name to be displayed instead of the address - 'reply_to_name' => '', - - //destination email address as string or a list of email addresses - 'to' => [], - - //copy destination addresses - 'cc' => [], - - //hidden copy destination addresses - 'bcc' => [], - - //email subject - 'subject' => '', - - //body options - content can be plain text, HTML - 'body' => [ - 'content' => '', - - 'charset' => 'utf-8', - ], - - //attachments config - 'attachments' => [ - 'files' => [], - - 'dir' => [ - 'iterate' => false, - 'path' => 'data/mail/attachments', - 'recursive' => false, - ] - ], - ], - - //options that will be used only if Symfony\Component\Mailer\Transport\Smtp\SmtpTransport adapter is used - 'smtp_options' => [ - - //hostname or IP address of the mail server - 'host' => '', - - //port of the mail server - 587 or 465 for secure connections - 'port' => 587, - - //connection class used for authentication - //the value can be one of smtp, plain, login or crammd5 - 'connection_class' => 'login', - - 'connection_config' => [ - - //the smtp authentication identity - //'username' => '', - - //the smtp authentication credential - //'password' => '', - - //the encryption type to be used, ssl or tls - //null should be used to disable SSL - 'ssl' => 'tls', - ] - ], - ], - // option to log the SENT emails - 'log' => [ - 'sent' => getcwd() . '/log/mail/sent.log' - ], - - /** - * You can define other mail services here, with the same structure as the default block - * you can even extend from the default block, and overwrite only the differences - */ - ], -]; From 2c0b76a169a3ff0c93c85991858a099f7a1b0649 Mon Sep 17 00:00:00 2001 From: MarioRadu Date: Tue, 10 Dec 2024 16:30:19 +0200 Subject: [PATCH 2/3] copy files only of specific environments Signed-off-by: MarioRadu --- bin/composer-post-install-script.php | 22 +++++++++++++++++++--- composer.json | 3 +++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php index af2e8a93..23f5011c 100644 --- a/bin/composer-post-install-script.php +++ b/bin/composer-post-install-script.php @@ -9,26 +9,42 @@ function copyFile(array $file): void if (is_readable($file['destination'])) { echo "File {$file['destination']} already exists." . PHP_EOL; } else { - if (! copy($file['source'], $file['destination'])) { - echo "Cannot copy {$file['source']} file to {$file['destination']}" . PHP_EOL; + if (! isDevModeEnabled() && $file['environment'] === 'local') { + echo "Skipping the copy of {$file['source']} due to environment settings." . PHP_EOL; } else { - echo "File {$file['source']} copied successfully to {$file['destination']}." . PHP_EOL; + 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; + } } } } +function isDevModeEnabled(): bool +{ + return file_exists('config/autoload/development.local.php'); +} + +// when adding files to the below array the `source` and `destination` must be relative to the project root folder +// the `environment` key will indicate when the file should be copied, +// if the value is `production` the file will be copied on both production and local environments, +// if the value is `local` the file will be copied only on local environments $files = [ [ 'source' => 'config/autoload/local.php.dist', 'destination' => 'config/autoload/local.php', + 'environment' => 'production', ], [ 'source' => 'config/autoload/local.test.php.dist', 'destination' => 'config/autoload/local.test.php', + 'environment' => 'local', ], [ 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', 'destination' => 'config/autoload/mail.global.php', + 'environment' => 'production', ], ]; diff --git a/composer.json b/composer.json index 5e018aca..2b6d2642 100644 --- a/composer.json +++ b/composer.json @@ -104,6 +104,9 @@ "post-create-project-cmd": [ "@development-enable" ], + "post-update-cmd": [ + "php bin/composer-post-install-script.php" + ], "development-disable": "laminas-development-mode disable", "development-enable": "laminas-development-mode enable", "development-status": "laminas-development-mode status", From 20bb143b39924ae0cb6e8d6320027c35c6c4ccd2 Mon Sep 17 00:00:00 2001 From: MarioRadu Date: Tue, 10 Dec 2024 19:24:06 +0200 Subject: [PATCH 3/3] requested changes Signed-off-by: MarioRadu --- bin/composer-post-install-script.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/composer-post-install-script.php b/bin/composer-post-install-script.php index 23f5011c..66bd803b 100644 --- a/bin/composer-post-install-script.php +++ b/bin/composer-post-install-script.php @@ -2,6 +2,9 @@ declare(strict_types=1); +const ENVIRONMENT_DEVELOPMENT = 'development'; +const ENVIRONMENT_PRODUCTION = 'production'; + // phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols function copyFile(array $file): void @@ -9,7 +12,7 @@ function copyFile(array $file): void if (is_readable($file['destination'])) { echo "File {$file['destination']} already exists." . PHP_EOL; } else { - if (! isDevModeEnabled() && $file['environment'] === 'local') { + 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'])) { @@ -21,30 +24,28 @@ function copyFile(array $file): void } } -function isDevModeEnabled(): bool +function getEnvironment(): string { - return file_exists('config/autoload/development.local.php'); + return file_exists('config/autoload/development.local.php') ? ENVIRONMENT_DEVELOPMENT : ENVIRONMENT_PRODUCTION; } -// when adding files to the below array the `source` and `destination` must be relative to the project root folder -// the `environment` key will indicate when the file should be copied, -// if the value is `production` the file will be copied on both production and local environments, -// if the value is `local` the file will be copied only on local environments +// when adding files to the below array the `source` and `destination` paths must be relative to the project root folder +// the `environment` key will indicate on what environments the file will be copied, $files = [ [ 'source' => 'config/autoload/local.php.dist', 'destination' => 'config/autoload/local.php', - 'environment' => 'production', + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], ], [ 'source' => 'config/autoload/local.test.php.dist', 'destination' => 'config/autoload/local.test.php', - 'environment' => 'local', + 'environment' => [ENVIRONMENT_DEVELOPMENT], ], [ 'source' => 'vendor/dotkernel/dot-mail/config/mail.global.php.dist', 'destination' => 'config/autoload/mail.global.php', - 'environment' => 'production', + 'environment' => [ENVIRONMENT_DEVELOPMENT, ENVIRONMENT_PRODUCTION], ], ];