Skip to content

refactor(php): centralize the default PHP version into a single constant - #113

Closed
mrrobot47 wants to merge 2 commits into
EasyEngine:developfrom
mrrobot47:refactor/php-version-constant
Closed

mrrobot47 wants to merge 2 commits into
EasyEngine:developfrom
mrrobot47:refactor/php-version-constant

Conversation

@mrrobot47

Copy link
Copy Markdown
Member

Summary

Centralizes the PHP version into a single source of truth so a default bump is a one-line edit. Mirrors the same change in site-type-wp (EasyEngine/site-type-wp#238).

Introduces two class constants on PHP:

const DEFAULT_PHP_VERSION    = '8.4';
const SUPPORTED_PHP_VERSIONS = [ '5.6', …, '8.5', 'latest' ];

The default 8.4 was previously hardcoded independently in three spots; all now read DEFAULT_PHP_VERSION:

Consumer Before After
Default when --php omitted docblock default: 8.4 get_flag_value( …, 'php', self::DEFAULT_PHP_VERSION )
8.x unsupported-version fallback = 8.4; = self::DEFAULT_PHP_VERSION;
latest → image tag (Site_PHP_Docker) 'easyengine/php8.4' 'easyengine/php' . PHP::DEFAULT_PHP_VERSION

The inline $supported_php_versions array is replaced by SUPPORTED_PHP_VERSIONS.

Why removing the docblock default: works

EE injects a docblock default: into $assoc_args before create() runs, so a docblock default would always win over the constant. Removing it lets the get_flag_value() fallback supply DEFAULT_PHP_VERSION when --php is omitted — making the constant authoritative. Effective default is unchanged (8.4).

Also included

  • String version literals instead of floats — fixes a latent bug where an x.0 version stringifies to "8" in the image name ('easyengine/php' . 8.0 → easyengine/php8).

Notes / tradeoffs for reviewers

  • --help no longer prints default: 8.4 for --php (the options list still shows). Inherent cost of single-sourcing the default in code. Alternative: keep the docblock default: and add a test asserting it equals the constant (drift-proof, but a bump becomes two edits).
  • README regeneration: default: is gone from the docblock, so ee scaffold package-readme will no longer emit the default: 8.4 line that docs: regenerate README for current PHP version support #112 added. Coordinate a README regen after merge (or keep the docblock default per the point above).
  • Irreducible duplication: the docblock options: list and prose still enumerate versions (PHPDoc can't reference a constant), so adding a new version still touches the docblock + SUPPORTED_PHP_VERSIONS. A synopsis↔constant guard test would make that drift-proof — happy to add it.

Introduce PHP::DEFAULT_PHP_VERSION and PHP::SUPPORTED_PHP_VERSIONS as the single
source of truth. The default value was previously hardcoded independently in
three places:

- the `--php` get_flag_value() default
- the 8.x unsupported-version fallback
- the `latest` -> image tag map in Site_PHP_Docker

All three now read DEFAULT_PHP_VERSION, so moving the default is a one-line edit.

The `default:` line is removed from the `--php` docblock so the constant is the
authoritative default: EE injects a docblock default into the args only when one
is declared, so with it gone the get_flag_value() fallback supplies the constant.

Also use string literals for the versions so an x.0 version no longer stringifies
to "8" in the image name.
…ation

Address review feedback on the version-constant refactor:

- Use a strict in_array() check for the supported-version test. Now that
  SUPPORTED_PHP_VERSIONS holds strings and php_version is always a string at
  that point, strict comparison avoids loose numeric matches (e.g. '8' loosely
  matching '8.0') that would otherwise skip the fallback and yield a
  non-existent image tag; such input now routes to the unsupported-version
  fallback instead.
- Normalize the 8.5 entry in the --php options list to a tab to match the
  other entries (it used spaces), keeping the docblock consistent.
mrrobot47 added a commit to mrrobot47/site-type-php that referenced this pull request Nov 19, 2026
`PHP::DEFAULT_PHP_VERSION` ('8.5') now drives the `latest` image in `Site_PHP_Docker`, the 8.x fallback and create()'s own fallback when `--php` is missing, and `PHP::SUPPORTED_PHP_VERSIONS` replaces the inline version list. This carries over the constant refactor of EasyEngine#113.

The `--php` docblock keeps `default: 8.5`: EE's dispatcher injects it before create() runs, so it stays the effective default and `--help` keeps showing it. A docblock can't reference a constant, so a default bump changes both.

No behaviour change.
mrrobot47 added a commit to mrrobot47/site-type-php that referenced this pull request Nov 19, 2026
EE's synopsis check compares `--php` loosely with the options Spyc parses from the docblock (floats such as 8.5 next to strings such as '8.0'), so `8`, `8.10`, `08.5`, `8.60` or ` 8.5` pass it. create() compared loosely too and kept such values as they were, so the compose file asked for images like `easyengine/php8` or `easyengine/php8.10`, which have no tag in img-versions.json, and the create failed late.

create() now trims the value, casts it to a string (the injected docblock default arrives as the float 8.5) and checks it strictly against `SUPPORTED_PHP_VERSIONS`. Surrounding whitespace is dropped; any other spelling that isn't listed gets the existing fallback prompt (`--php=8` asks to continue with 8.5). A non-numeric value that gets through, such as a bare `--php` or `8.5abc` on PHP 7, is refused as unsupported instead of reaching floor(), which throws a TypeError on PHP 8. The fallback versions are strings as well, so the stored version is always a string such as '8.5'.

Carries over the strict check from EasyEngine#113.
@mrrobot47

Copy link
Copy Markdown
Member Author

Superseded by #126 (merged), which carries this change on top of the PHP 8.6 work: PHP::DEFAULT_PHP_VERSION (now 8.5) and PHP::SUPPORTED_PHP_VERSIONS as strings, read by the create() default, the 8.x fallback and the latest image in Site_PHP_Docker, plus the strict in_array. One difference: the docblock default: 8.5 stays, so --help and the README keep showing the default; tests check that it matches the constant.

@mrrobot47 mrrobot47 closed this Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant