Skip to content

Commit 0b30c49

Browse files
authored
Merge pull request #235 from stellarwp/bugfix/properly-override-set-php-version
Fix: Preserve staged PHP versions
2 parents 9f00851 + e90c43d commit 0b30c49

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
# [2.1.7] - 2026-02-02
8+
- Fixed - Preserve staged PHP versions (from `slic php-version set X.Y --skip-rebuild`) when a project's `.env.slic.local` file would otherwise override them. Staged versions now correctly take precedence over project-specific PHP version overrides.
9+
710
# [2.1.6] - 2025-12-03
811
- Added - Prevent running slic if the `uopz` extension is enabled with `uopz.exit=0`.
912

slic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
] );
5555

5656
$cli_name = 'slic';
57-
const CLI_VERSION = '2.1.6';
57+
const CLI_VERSION = '2.1.7';
5858

5959
// If the run-time option `-q`, for "quiet", is specified, then do not print the header.
6060
if ( in_array( '-q', $argv, true ) || ( in_array( 'exec', $argv, true ) && ! in_array( 'help', $argv, true ) ) ) {

src/slic.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,19 @@ function setup_slic_env( $root_dir, $reset = false ) {
268268
}
269269

270270
// Load the current session configuration file.
271-
if ( file_exists( $root_dir . '/.env.slic.run' ) ) {
272-
load_env_file( $root_dir . '/.env.slic.run' );
271+
$run_env_file = $root_dir . '/.env.slic.run';
272+
$staged_php_version = null;
273+
274+
if ( file_exists( $run_env_file ) ) {
275+
load_env_file( $run_env_file );
276+
277+
// Read directly from file to check for staged version before a project's .env.slic.local loads.
278+
$run_env = read_env_file($run_env_file);
279+
$is_php_version_staged = ($run_env['SLIC_PHP_VERSION_STAGED'] ?? '') === '1';
280+
281+
if ( $is_php_version_staged && isset( $run_env['SLIC_PHP_VERSION'] ) ) {
282+
$staged_php_version = $run_env['SLIC_PHP_VERSION'];
283+
}
273284
}
274285

275286
/*
@@ -300,6 +311,9 @@ function setup_slic_env( $root_dir, $reset = false ) {
300311
if ( $target_version ) {
301312
putenv( "SLIC_PHP_VERSION=$target_version" );
302313
putenv( "SLIC_PHP_CLI_VERSION=$target_version" );
314+
} elseif ( $staged_php_version !== null ) {
315+
// A PHP version was staged, restore it (project's .env.slic.local may have overwritten it to the wrong version).
316+
putenv( "SLIC_PHP_VERSION=$staged_php_version" );
303317
}
304318

305319
// All the possible env files have been loaded, time to set the db image depending on the PHP version.
@@ -391,6 +405,9 @@ function slic_set_php_version( $version, $require_confirm = false, $skip_rebuild
391405
return;
392406
}
393407

408+
// Set the environment variable so docker-compose build/rebuild operations use the correct PHP version.
409+
putenv( "SLIC_PHP_VERSION=$version" );
410+
394411
rebuild_stack();
395412
update_stack_images();
396413
restart_php_services( true );

0 commit comments

Comments
 (0)