Skip to content

Commit c84c73c

Browse files
gmazzapkuliebiakin
andauthored
Sync development (#16)
* License normalization - remove license text in every file - rewording in README - year in LICENSE * Add support for custom env config files in 'vip-composer-plugin-env-config' packages (#14) * Fix copyright in LICENSE * Add "preprod" as standard env name * Add 'develop' to default envConfigs --------- Signed-off-by: Giuseppe Mazzapica <giuseppe.mazzapica@gmail.com> Co-authored-by: Viktor Kuliebiakin <6066592+kuliebiakin@users.noreply.github.com>
1 parent f767eaf commit c84c73c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+282
-460
lines changed

.github/workflows/quality-assurance-php.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run lint only')) }}
3636
strategy:
3737
matrix:
38-
php: [ "8.0", "8.1", "8.2" ]
38+
php: [ "8.0", "8.1", "8.2", "8.3" ]
3939
uses: inpsyde/reusable-workflows/.github/workflows/lint-php.yml@main
4040
with:
4141
PHP_VERSION: ${{ matrix.php }}
@@ -49,8 +49,8 @@ jobs:
4949
if: ${{ (github.event_name != 'workflow_dispatch') || ((github.event.inputs.jobs == 'Run all') || (github.event.inputs.jobs == 'Run Psalm only')) }}
5050
strategy:
5151
matrix:
52-
php: [ "8.0", "8.1", "8.2" ]
52+
php: [ "8.0", "8.1", "8.2", "8.3" ]
5353
uses: inpsyde/reusable-workflows/.github/workflows/static-analysis-php.yml@main
5454
with:
5555
PHP_VERSION: ${{ matrix.php }}
56-
PSALM_ARGS: --output-format=github --no-suggestions --no-cache --no-diff --find-unused-psalm-suppress --php-version=${{ matrix.php }}
56+
PSALM_ARGS: --output-format=github --no-suggestions --no-cache --no-diff --find-unused-psalm-suppress

.github/workflows/unit-tests-php.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ jobs:
2525
strategy:
2626
fail-fast: false
2727
matrix:
28-
php-ver: [ '8.0', '8.1', '8.2' ]
28+
php-ver: [ '8.0', '8.1', '8.2', '8.3' ]
2929
composer: [ '2.4', '2.5', '2.6', '2' ]
3030
dependency-versions: [ 'lowest', 'highest' ]
31-
exclude:
32-
- composer: '2'
33-
dependency-versions: 'lowest'
3431
steps:
3532
- name: Checkout
3633
uses: actions/checkout@v4
@@ -50,9 +47,10 @@ jobs:
5047
composer require "composer/composer:~${{ matrix.composer }}.0" --dev --no-update
5148
5249
- name: Install dependencies
53-
uses: ramsey/composer-install@v2
50+
uses: ramsey/composer-install@v3
5451
with:
5552
dependency-versions: ${{ matrix.dependency-versions }}
53+
tools: composer:v${{ matrix.composer-ver }}
5654

5755
- name: Run unit tests
5856
run: ./vendor/bin/phpunit --no-coverage

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Syde GmbH
3+
Copyright (c) 2024 Syde GmbH
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ The whole set of settings available, with their defaults, looks like this:
178178
"vip-config-dir": "vip-config",
179179
"config-dir": "config",
180180
"private-dir": "private"
181-
}
181+
},
182+
"custom-env-names": [
183+
]
182184
}
183185
}
184186
}
@@ -289,6 +291,14 @@ Only the `config/vip-config.php` is mandatory all the other folders and their co
289291
`vip-composer.dev-paths` controls the name of those folders. By default names are the same names used by VIP Go repository, except for `mu-plugins/` is renamed to `client-mu-plugins/`.
290292

291293

294+
#### `vip-composer.custom-env-names`
295+
296+
VIP expects WordPress configuration normally placed in `wp-config.php` (e.g. constants with secrets) to be placed in a `vip-config.php` file. To help having environment-specific setting, this package support multiple files where to set such configuration, where each file is environment-specific and named after the environment.
297+
The configuration files can be placed directly in the `./vip-config/` folder in a "website repository" root folder, or can be placed in separate Composer packages having the `vip-composer-plugin-env-config` type, whose support is handled by this package.
298+
In the latter case, the supported files that are copied over from packages into website config folder are, by default, those named after the environments supported by WordPress core, and they are: `local.php`, `development.php`, `staging.php`, and `production.php`, plus a file named `all.php`aimed at target all environments.
299+
Considering VIP GO allows us to have more environments or anyway name them differently, it is possible to expand the list of supported files names via the `vip-composer.custom-env-names` configuration.
300+
301+
292302

293303
## Folder structure *after* the command runs
294304

@@ -678,6 +688,9 @@ composer vip --vip-dev-env
678688
vip dev-env create --app-code="./vip"
679689
```
680690

681-
## Copyright
691+
## License and Copyright
692+
693+
_VIP Composer Plugin_ is a free software, and is released under the terms of the MIT license.
694+
See [LICENSE](./LICENSE) for complete license.
682695

683-
This repository is a free software, and is released under the terms of the MIT license. See [LICENSE](./LICENSE) for complete license.
696+
The team at Syde is engineering the Web since 2006.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"require-dev": {
2626
"composer/composer": "^2.4",
2727
"inpsyde/php-coding-standards": "^2@dev",
28-
"vimeo/psalm": "^5.15.0",
29-
"phpunit/phpunit": "^9.6.11"
28+
"vimeo/psalm": "^5.23.1",
29+
"phpunit/phpunit": "^9.6.17"
3030
},
3131
"autoload": {
3232
"psr-4": {
@@ -47,7 +47,7 @@
4747
},
4848
"scripts": {
4949
"phpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
50-
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-cache --show-info=false --no-progress",
50+
"psalm": "@php ./vendor/vimeo/psalm/psalm --no-suggestions --report-show-info=false --find-unused-psalm-suppress --no-diff --no-cache --no-file-cache --output-format=compact",
5151
"tests": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
5252
"tests:coverage": "@php ./vendor/phpunit/phpunit/phpunit --coverage-clover",
5353
"qa": [

src/Command.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the vip-composer-plugin package.
5-
*
6-
* (c) Inpsyde GmbH
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
declare(strict_types=1);
134

145
namespace Inpsyde\VipComposer;
@@ -162,12 +153,9 @@ protected function configure(): void
162153
* @param InputInterface $input
163154
* @param OutputInterface $output
164155
* @return int
165-
*
166-
* phpcs:disable Inpsyde.CodeQuality.ReturnTypeDeclaration
167156
*/
168-
protected function execute(InputInterface $input, OutputInterface $output)
157+
protected function execute(InputInterface $input, OutputInterface $output): int
169158
{
170-
// phpcs:enable Inpsyde.CodeQuality.ReturnTypeDeclaration
171159
try {
172160
$this->resetComposer();
173161
$composer = $this->requireComposer();
@@ -186,8 +174,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
186174
->addTask($taskFactory->downloadWpCore())
187175
->addTask($taskFactory->downloadVipGoMuPlugins())
188176
->addTask($taskFactory->symlinkVipGoDir())
189-
->addTask($taskFactory->copyDevPaths())
190177
->addTask($taskFactory->copyEnvConfig())
178+
->addTask($taskFactory->copyDevPaths())
191179
->addTask($taskFactory->generateMuPluginsLoader())
192180
->addTask($taskFactory->generateProductionAutoload())
193181
->addTask($taskFactory->updateLocalWpConfigFile())

src/Config.php

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the vip-composer-plugin package.
5-
*
6-
* (c) Inpsyde GmbH
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
declare(strict_types=1);
134

145
namespace Inpsyde\VipComposer;
@@ -53,6 +44,8 @@ final class Config implements \ArrayAccess
5344
public const DEV_PATHS_YAML_CONFIG_DIR_KEY = 'config-dir';
5445
public const DEV_PATHS_PRIVATE_DIR_KEY = 'private-dir';
5546

47+
public const CUSTOM_ENV_NAMES_KEY = 'custom-env-names';
48+
5649
public const PACKAGE_TYPE_MULTI_MU_PLUGINS = 'wordpress-multiple-mu-plugins';
5750

5851
public const DEFAULTS = [
@@ -83,6 +76,7 @@ final class Config implements \ArrayAccess
8376
self::DEV_PATHS_YAML_CONFIG_DIR_KEY => 'config',
8477
self::DEV_PATHS_PRIVATE_DIR_KEY => 'private',
8578
],
79+
self::CUSTOM_ENV_NAMES_KEY => [],
8680
];
8781

8882
private array $config;
@@ -94,7 +88,7 @@ final class Config implements \ArrayAccess
9488
*/
9589
public function __construct(Composer $composer, string $basePath)
9690
{
97-
$extra = (array)($composer->getPackage()->getExtra()[self::CONFIG_KEY] ?? []);
91+
$extra = (array) ($composer->getPackage()->getExtra()[self::CONFIG_KEY] ?? []);
9892
$this->composerConfig = $composer->getConfig();
9993

10094
$this->config = [];
@@ -114,15 +108,15 @@ public function __construct(Composer $composer, string $basePath)
114108
*/
115109
public function basePath(): string
116110
{
117-
return (string)$this->offsetGet(self::BASE_PATH_KEY);
111+
return (string) $this->offsetGet(self::BASE_PATH_KEY);
118112
}
119113

120114
/**
121115
* @return string
122116
*/
123117
public function prodAutoloadDir(): string
124118
{
125-
return (string)$this->offsetGet(self::PROD_AUTOLOAD_DIR_KEY);
119+
return (string) $this->offsetGet(self::PROD_AUTOLOAD_DIR_KEY);
126120
}
127121

128122
/**
@@ -131,7 +125,7 @@ public function prodAutoloadDir(): string
131125
*/
132126
public function composerConfigValue(string $key): string
133127
{
134-
return (string)$this->composerConfig->get($key);
128+
return (string) $this->composerConfig->get($key);
135129
}
136130

137131
/**
@@ -143,47 +137,78 @@ public function composerLockPath(): string
143137
$configSource = $this->composerConfig->getConfigSource();
144138
$composerJsonSource = $configSource->getName();
145139

146-
return (string)preg_replace('~\.json$~', '.lock', $composerJsonSource, 1);
140+
return (string) preg_replace('~\.json$~', '.lock', $composerJsonSource, 1);
147141
}
148142

149143
/**
150144
* @return array
151145
*/
152146
public function vipConfig(): array
153147
{
154-
return (array)$this->offsetGet(self::VIP_CONFIG_KEY);
148+
return (array) $this->offsetGet(self::VIP_CONFIG_KEY);
155149
}
156150

157151
/**
158152
* @return array
159153
*/
160154
public function gitConfig(): array
161155
{
162-
return (array)$this->offsetGet(self::GIT_CONFIG_KEY);
156+
return (array) $this->offsetGet(self::GIT_CONFIG_KEY);
163157
}
164158

165159
/**
166160
* @return array
167161
*/
168162
public function wpConfig(): array
169163
{
170-
return (array)$this->offsetGet(self::WP_CONFIG_KEY);
164+
return (array) $this->offsetGet(self::WP_CONFIG_KEY);
171165
}
172166

173167
/**
174168
* @return array
175169
*/
176170
public function pluginsAutoloadConfig(): array
177171
{
178-
return (array)$this->offsetGet(self::PLUGINS_AUTOLOAD_KEY);
172+
return (array) $this->offsetGet(self::PLUGINS_AUTOLOAD_KEY);
179173
}
180174

181175
/**
182176
* @return array
183177
*/
184178
public function devPathsConfig(): array
185179
{
186-
return (array)$this->offsetGet(self::DEV_PATHS_CONFIG_KEY);
180+
return (array) $this->offsetGet(self::DEV_PATHS_CONFIG_KEY);
181+
}
182+
183+
/**
184+
* @return list<non-empty-string>
185+
*/
186+
public function envConfigs(): array
187+
{
188+
$customEnvs = (array) $this->offsetGet(self::CUSTOM_ENV_NAMES_KEY);
189+
if ($customEnvs === []) {
190+
/*
191+
* WordPress supports by default: `local`, `development`, `staging`, and `production`.
192+
* VIP supports by default: `develop`, `preprod`, and `production`.
193+
* This list targets both for larger by-default compatibility.
194+
*/
195+
return ['local', 'develop', 'development', 'staging', 'preprod', 'production', 'all'];
196+
}
197+
$envNames = [];
198+
foreach ($customEnvs as $envName) {
199+
if (!is_string($envName)) {
200+
continue;
201+
}
202+
$envName = trim(strtolower($envName));
203+
if (
204+
preg_match('~^[a-z][a-z0-9_\.\-]+$~', $envName)
205+
&& !in_array($envName, $envNames, true)
206+
) {
207+
$envNames[] = $envName;
208+
}
209+
}
210+
/** @var list<non-empty-string> $envNames */
211+
return $envNames;
187212
}
188213

189214
/**

src/Factory.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the vip-composer-plugin package.
5-
*
6-
* (c) Inpsyde GmbH
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
declare(strict_types=1);
134

145
namespace Inpsyde\VipComposer;

src/Git/EnsureGitIgnore.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the vip-composer-plugin package.
5-
*
6-
* (c) Inpsyde GmbH
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
declare(strict_types=1);
134

145
namespace Inpsyde\VipComposer\Git;

src/Git/GitProcess.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/**
4-
* This file is part of the vip-composer-plugin package.
5-
*
6-
* (c) Inpsyde GmbH
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
declare(strict_types=1);
134

145
namespace Inpsyde\VipComposer\Git;
@@ -44,8 +35,8 @@ public function __construct(
4435
ProcessExecutor $executor = null
4536
) {
4637

47-
$cwd = $workingDir ?: getcwd();
48-
if (!$cwd) {
38+
$cwd = $workingDir ?? getcwd();
39+
if ($cwd === false) {
4940
throw new \Exception('Could not determine current dir');
5041
}
5142

0 commit comments

Comments
 (0)