Skip to content

Commit

Permalink
Merge branch 'version-3-next' of github.com:wecodemore/wpstarter into…
Browse files Browse the repository at this point in the history
… dev
  • Loading branch information
nlemoine committed Jul 4, 2024
2 parents d6b7650 + cb0967a commit f649833
Show file tree
Hide file tree
Showing 40 changed files with 617 additions and 429 deletions.
64 changes: 35 additions & 29 deletions .github/workflows/php-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ on:
- '**workflows/php-qa.yml'
- '**.php'
- '**templates/**'
- '**phpcs.xml.dist'
- '**phpcs.xml.dist'
- '**phpunit.xml.dist'
- '**psalm.xml'
- '**composer.json'
pull_request:
paths:
- '**workflows/php-qa.yml'
- '**.php'
- '**templates/**'
- '**phpcs.xml.dist'
- '**phpunit.xml.dist'
- '**psalm.xml'
- '**composer.json'
workflow_dispatch:

concurrency:
Expand All @@ -19,9 +27,9 @@ concurrency:

jobs:

static-qa:
coding-styles:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'skip qa') }}
if: ${{ !contains(github.event.head_commit.message, 'skip cs') }}

steps:
- name: Checkout
Expand All @@ -30,11 +38,11 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
coverage: none
tools: cs2pr

- name: Setup Composer aut for GitHub
- name: Setup Composer auth for GitHub
run: composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
Expand All @@ -45,10 +53,7 @@ jobs:

- name: Annotate code styles for PRs
if: ${{ github.event_name == 'pull_request' }}
run: cs2pr --graceful-warnings phpcs-report.xml

- name: Check Psalm
run: ./vendor/bin/psalm ${{ ((github.event_name == 'pull_request') && '--output-format=github ') || '' }} --no-suggestions --find-unused-psalm-suppress --no-diff --no-cache --no-file-cache
run: cs2pr --graceful-warnings phpcs-report.xm

unit-tests:
runs-on: ubuntu-latest
Expand All @@ -58,28 +63,27 @@ jobs:
strategy:
fail-fast: false
matrix:
php-ver: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
composer-ver: [ '^1', '~2.0.0', '~2.1.0', '~2.2.0', '~2.3.0', '~2.4.0', '~2.5.0' ]
php-ver: [ '7.4', '8.0', '8.1', '8.2' ]
composer-ver: [ '2.0', '2.1', '2.2', '2.3', '2.4', '2.5', '2.6' ]
dependency-versions: [ 'lowest', 'highest' ]
exclude:
- php-ver: '7.1'
composer-ver: '~2.3.0'
- php-ver: '7.1'
composer-ver: '~2.4.0'
- php-ver: '7.1'
composer-ver: '~2.5.0'
- php-ver: '8.1'
composer-ver: '^1'
composer-ver: '2.0'
- php-ver: '8.1'
composer-ver: '2.1'
- php-ver: '8.1'
composer-ver: '~2.0.0'
composer-ver: '2.2'
- php-ver: '8.2'
composer-ver: '^1'
composer-ver: '2.0'
- php-ver: '8.2'
composer-ver: '~2.0.0'
composer-ver: '2.1'
- php-ver: '8.2'
composer-ver: '~2.1.0'
composer-ver: '2.2'
- php-ver: '8.2'
composer-ver: '2.3'
steps:
- name: Update "USE_COVERAGE" env var based on matrix
if: ${{ matrix.php-ver == '7.4' && matrix.composer-ver == '~2.3.0' }}
if: ${{ (matrix.php-ver == '8.0') && (matrix.dependency-versions == 'highest') && (matrix.composer-ver == '2.5') }}
run: echo "USE_COVERAGE=yes" >> $GITHUB_ENV

- name: Checkout
Expand All @@ -96,17 +100,19 @@ jobs:
- name: Adjust Composer dependencies
run: |
composer remove --dev --no-update "roave/security-advisories"
composer require --dev --no-update "composer/composer:${{ matrix.composer-ver }}"
composer require --dev --no-update "composer/composer:~${{ matrix.composer-ver }}.0"
- name: Install dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest
dependency-versions: ${{ matrix.dependency-versions }}

- name: Check Psalm
if: ${{ matrix.dependency-versions == 'highest' }}
run: ./vendor/bin/psalm ${{ ((github.event_name == 'pull_request') && '--output-format=github ') || '' }} --no-suggestions --no-diff --no-cache --no-file-cache --php-version=${{ matrix.php-ver }}

- name: Run unit tests
run: |
./vendor/bin/phpunit --atleast-version 9 && ./vendor/bin/phpunit --migrate-configuration || echo 'Config does not need updates.'
./vendor/bin/phpunit ${{ ((env.USE_COVERAGE == 'yes') && '--coverage-html=coverage-report') || '--no-coverage' }}
run: ./vendor/bin/phpunit ${{ ((env.USE_COVERAGE == 'yes') && '--coverage-html=coverage-report') || '--no-coverage' }}

- name: Upload coverage report
uses: actions/upload-artifact@v3
Expand All @@ -121,7 +127,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php-ver: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php-ver: [ '7.4', '8.0', '8.1', '8.2' ]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ WP Starter is the easiest and fastest way to bootstrap WordPress sites entirely

# System Requirements

- PHP 7.1+
- [Composer](https://getcomposer.org/) >= 1.10
- PHP 7.4+
- [Composer](https://getcomposer.org/) >= 2.0



### Composer - PHP Support Table

| Composer ↓ / PHP → | 7.1 | 7.2 | 7.3 | 7.4 | 8.0 | 8.1 | 8.2 |
| :----------------: | :--: | :--: | :--: | :--: | :--: | :--: | :--: |
| 1.10 || | | || - | - |
| 2.0 | | | ||| - | - |
| 2.1 | | | | ||| - |
| 2.2 | | | | ||| |
| 2.3 | - | | | | || |
| 2.4 | - | | | | || |
| 2.5 | - | | | | || |
| Composer ↓ / PHP → | 7.4 | 8.0 | 8.1 | 8.2 |
|:------------------:|:---:|:---:|:---:|:---:|
| 2.0 ||| - | - |
| 2.1 ||| - | - |
| 2.2 ||| - | - |
| 2.3 |||| - |
| 2.4 |||||
| 2.5 |||||
| 2.6 |||||



Expand Down
34 changes: 22 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@
"issues": "https://github.com/wecodemore/wpstarter/issues",
"source": "https://github.com/wecodemore/wpstarter"
},
"repositories": [
{
"type": "composer",
"url": "https://raw.githubusercontent.com/inpsyde/wp-stubs/main",
"only": [
"inpsyde/wp-stubs-versions"
]
}
],
"require": {
"php": ">=7.1 < 8.3",
"php": ">=7.4 < 8.3",
"ext-curl": "*",
"ext-dom": "*",
"ext-filter": "*",
Expand All @@ -36,20 +45,20 @@
"ext-mbstring": "*",
"ext-mysqli": "*",
"ext-SPL": "*",
"composer-plugin-api": "^1.10 || ^2",
"composer/installers": "^1.12.0 || ^2",
"symfony/dotenv": "^3.4 || ^5 || ^6 || ^7"
"composer-plugin-api": "^2",
"composer/installers": "^2",
"symfony/dotenv": "^5 || ^6 || ^7"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"composer/package-versions-deprecated": "^1.11.99",
"composer/composer": "^2.5.4",
"symfony/process": "^3.4.47 || ^5.4.19 || ^6 || ^7",
"wp-cli/wp-cli": "^2.7.1",
"inpsyde/php-coding-standards": "^1.0.0",
"vimeo/psalm": "^4.30.0 || ^5",
"phpunit/phpunit": "^7.5.20 || ^9.6.3",
"mockery/mockery": "^1.3.6",
"composer/composer": "^2.6.5",
"symfony/process": "^5.4.19 || ^6 || ^7",
"wp-cli/wp-cli": "^v2.9.0",
"inpsyde/php-coding-standards": "^2@dev",
"vimeo/psalm": "^5.15.0",
"phpunit/phpunit": "^9.6.13",
"mockery/mockery": "^1.6.6",
"mikey179/vfsstream": "^1.6.11"
},
"autoload": {
Expand Down Expand Up @@ -83,7 +92,8 @@
"qa": [
"@cs",
"@psalm",
"@tests:unit:no-cov"
"@tests:unit:no-cov",
"@tests:integration"
]
},
"extra": {
Expand Down
4 changes: 2 additions & 2 deletions docs/01-Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ Of course, this is the bare minimum. WP Starter is quite powerful and flexible a

## Requirements

- PHP 7.1+
- Composer
- PHP 7.4+
- Composer 2.0+


------
Expand Down
32 changes: 27 additions & 5 deletions docs/02-Environment-Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,23 @@ In PHP there are two functions: [`getevn`](http://php.net/manual/en/function.get

There's nothing in PHP core that parse env files, but is no surprise that there are different libraries to do that.

WP Starter uses one of these libraries: the **[Symfony Dotenv Component](https://symfony.com/doc/3.4/components/dotenv.html).**
WP Starter uses one of these libraries: the **[Symfony Dotenv Component](https://symfony.com/components/Dotenv).**



### About `putenv()` and `getenv()`

These two PHP functions are problematic as they are not thread safe. So **recent versions of WP Starter** (as well as recent version of Symfony Dotenv Component) **do not use `putenv()` by default** to store in the environment the values loaded via `.env` files.

Even if `.env` files are discouraged in production where thread safety is important, we still prefer to have a safe behavior by default and not use `putenv()`. This means that environment variables loaded from WP Starter `.env` files will not be available to `getenv()`.

There are different ways those values could be read instead:

- Because WP Starter converts environment variables to constants (after converting to the correct type), one approach is to access values constants.
- Directly access super globals: `$_ENV['var_name'] ?? $_SERVER['var_name'] ?? null`.
- Make use of WP Starter helper, like ` WeCodeMore\WpStarter\Env\Helpers::readVar('var_name');` This approach has the benefit of obtaining "filtered values". E. g. obtaining the intended type instead of always a string.

If any of the above can be used for some reason, it is still possible to let WP Starter use `putenv()` to load environments by setting the `use-putenv` configuration to `true`.



Expand All @@ -82,6 +98,8 @@ Moreover, **if the "actual environment" contains all the variables WP Starter an

Configuring WP Starter to **bypass** the loading of env files is accomplished via the **`WPSTARTER_ENV_LOADED`** env variable, which when set tells WP Starter to assume all variables are in the actual environment.



### Important security note about `.env` file

WP Starter loads an `.env` file found in the project root folder, and it is worth noting that if no additional configuration is made, project root is also the folder assumed as webroot for the project.
Expand Down Expand Up @@ -121,7 +139,7 @@ If there's a plugin that supports a constant like `"AWESOME_PLUGIN_CONFIG"`, by
So you might need to write code like:

```php
$config = getenv('AWESOME_PLUGIN_CONFIG');
$config = $_ENV['AWESOME_PLUGIN_CONFIG'] ?? $_SERVER['AWESOME_PLUGIN_CONFIG'] ?? null;
if ($config) {
define('AWESOME_PLUGIN_CONFIG', $config);
}
Expand All @@ -131,6 +149,8 @@ There are many places in which such code can be placed, for example a MU plugin.

Alternatively WP Starter can be instructed to do something like this automatically.



### Let WP Starter define constants for custom env vars

WP Starter supports an environment variable called `WP_STARTER_ENV_TO_CONST` containing a list of of comma-separated environment variables to be turned into constants:
Expand Down Expand Up @@ -165,6 +185,8 @@ As described above, all WordPress configuration constants are natively supported

Moreover, there are a few env variables that have a special meaning for WP Starter.



### DB check env vars

During its bootstrap process, before doing any operation on the system, WP Starter checks if the environment is already setup for database connection.
Expand All @@ -181,6 +203,8 @@ The three env vars are registered in the order they are listed above: if one is
Sometime it might be desirable to bypass this WP Starter check and there's a way to accomplish that via the `skip-db-check` setting.
Learn more about that in the [_"WP-Starter-Configuration"_ chapter](04-WP-Starter-Configuration.md).



### WordPress Configuration

Those are a few env vars that are used in `wp-config.php` that WP Starter generates.
Expand Down Expand Up @@ -226,9 +250,7 @@ The filter is executed very late (so could be added in MU plugins, plugins and e
For example, to only allow cache in production a code like the following can be used:

```php
add_filter('wpstarter.skip-cache-env', function ($skip, $envName) {
return $skip || $envName !== 'production';
});
add_filter('wpstarter.skip-cache-env', fn ($skip, $envName) => $skip || $envName !== 'production');
```


Expand Down
Loading

0 comments on commit f649833

Please sign in to comment.