From 936f1243b7cbeb05b277f016a73e1947b8c93d66 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 17 Jun 2026 12:38:43 +0530 Subject: [PATCH 1/2] refactor(php): centralize the default PHP version into a single constant Introduce WordPress::DEFAULT_PHP_VERSION and WordPress::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_WP_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 fix the indentation of the 8.x fallback branch and use string literals for the versions so an x.0 version no longer stringifies to "8" in the image name. --- src/Site_WP_Docker.php | 2 +- src/WordPress.php | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Site_WP_Docker.php b/src/Site_WP_Docker.php index b35b2a0..05072ad 100644 --- a/src/Site_WP_Docker.php +++ b/src/Site_WP_Docker.php @@ -67,7 +67,7 @@ public function generate_docker_compose_yml( array $filters = [], $volumes ) { } // PHP configuration. - $php_image_key = ( 'latest' === $filters['php_version'] ? 'easyengine/php8.4' : 'easyengine/php' . $filters['php_version'] ); + $php_image_key = ( 'latest' === $filters['php_version'] ? 'easyengine/php' . WordPress::DEFAULT_PHP_VERSION : 'easyengine/php' . $filters['php_version'] ); $php['service_name'] = [ 'name' => 'php' ]; $php['image'] = [ 'name' => $php_image_key . ':' . $img_versions[ $php_image_key ] ]; diff --git a/src/WordPress.php b/src/WordPress.php index 2b1f666..27ffc5a 100644 --- a/src/WordPress.php +++ b/src/WordPress.php @@ -23,6 +23,19 @@ */ class WordPress extends EE_Site_Command { + /** + * Default PHP version for new sites. Single source of truth: this is also + * the version the `latest` image tag resolves to and the 8.x fallback for + * unsupported requests. Change this one constant to move the default. + */ + const DEFAULT_PHP_VERSION = '8.4'; + + /** + * All PHP versions EasyEngine ships images for. Keep in sync with the + * `--php` options list in the create() docblock. + */ + const SUPPORTED_PHP_VERSIONS = [ '5.6', '7.0', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', 'latest' ]; + /** * @var string $cache_type Type of caching being used. */ @@ -133,7 +146,6 @@ public function __construct() { * [--php=] * : PHP version for site. Currently only supports PHP 5.6, 7.0, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5 and latest. * --- - * default: 8.4 * options: * - 5.6 * - 7.0 @@ -305,7 +317,7 @@ public function create( $args, $assoc_args ) { $this->cache_type = \EE\Utils\get_flag_value( $assoc_args, 'cache' ); $wildcard_flag = \EE\Utils\get_flag_value( $assoc_args, 'wildcard' ); $this->site_data['site_ssl_wildcard'] = 'subdom' === $this->site_data['app_sub_type'] || $wildcard_flag ? true : false; - $this->site_data['php_version'] = \EE\Utils\get_flag_value( $assoc_args, 'php' ); + $this->site_data['php_version'] = \EE\Utils\get_flag_value( $assoc_args, 'php', self::DEFAULT_PHP_VERSION ); $this->site_data['app_admin_url'] = \EE\Utils\get_flag_value( $assoc_args, 'title', $this->site_data['site_url'] ); $this->site_data['app_admin_username'] = \EE\Utils\get_flag_value( $assoc_args, 'admin-user', \EE\Utils\random_name_generator() ); $this->site_data['app_admin_password'] = \EE\Utils\get_flag_value( $assoc_args, 'admin-pass', '' ); @@ -372,7 +384,7 @@ public function create( $args, $assoc_args ) { } $this->site_data['alias_domains'] = substr( $this->site_data['alias_domains'], 0, - 1 ); - $supported_php_versions = [ 5.6, 7.0, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5, 'latest' ]; + $supported_php_versions = self::SUPPORTED_PHP_VERSIONS; if ( ! in_array( $this->site_data['php_version'], $supported_php_versions ) ) { $old_version = $this->site_data['php_version']; $floor = (int) floor( $this->site_data['php_version'] ); @@ -382,9 +394,9 @@ public function create( $args, $assoc_args ) { $this->site_data['php_version'] = 7.4; $old_version .= ' yet'; } elseif ( 8 === $floor ) { - $this->site_data['php_version'] = 8.4; - $old_version .= ' yet'; - } else { + $this->site_data['php_version'] = self::DEFAULT_PHP_VERSION; + $old_version .= ' yet'; + } else { EE::error( 'Unsupported PHP version: ' . $this->site_data['php_version'] ); } \EE::confirm( sprintf( 'EEv4 does not support PHP %s. Continue with PHP %s?', $old_version, $this->site_data['php_version'] ), $assoc_args ); From 4b53f52e2f2727426a2f2ae9d6ae75b289c6c607 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Wed, 17 Jun 2026 12:53:07 +0530 Subject: [PATCH 2/2] refactor(php): tighten version validation and normalize option indentation 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. --- src/WordPress.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/WordPress.php b/src/WordPress.php index 27ffc5a..4a31565 100644 --- a/src/WordPress.php +++ b/src/WordPress.php @@ -157,7 +157,7 @@ public function __construct() { * - 8.2 * - 8.3 * - 8.4 - * - 8.5 + * - 8.5 * - latest * --- * @@ -385,7 +385,7 @@ public function create( $args, $assoc_args ) { $this->site_data['alias_domains'] = substr( $this->site_data['alias_domains'], 0, - 1 ); $supported_php_versions = self::SUPPORTED_PHP_VERSIONS; - if ( ! in_array( $this->site_data['php_version'], $supported_php_versions ) ) { + if ( ! in_array( $this->site_data['php_version'], $supported_php_versions, true ) ) { $old_version = $this->site_data['php_version']; $floor = (int) floor( $this->site_data['php_version'] ); if ( 5 === $floor ) {