-
-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Based on #4 we have done a migration from .php-version
to Composer config.platform.php
. In almost all cases 8.0
(major & minor) applies, however in some projects we have run into the problem that the Composer resolvement requires also a patch version. Below is an example case.
mkdir symfony-cli && cd symfony-cli
composer init
composer require "symfony/deprecation-contracts:3.0.2"
composer config platform.php "8.0"
composer update --lock
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires symfony/deprecation-contracts == 3.0.2.0 -> satisfiable by symfony/deprecation-contracts[v3.0.2].
- symfony/deprecation-contracts v3.0.2 requires php >=8.0.2 -> your php version (8.0; overridden via config.platform, actual: 8.0.27) does not satisfy that requirement.
unable to run /usr/local/bin/composer update --lock
The Composer package symphony/deprecation-contracts
requires 8.0.2
or later. Fine you would think. So we enter 8.0.10
(or higher).
composer config platform.php "8.0.10"
composer update --lock
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
Hurrah! Composer successfully applies the resolutions.
From a random CLI (without .php-version
and/or Composer config platform php configuration).
php -v
PHP 8.2.1 (cli) (built: Jan 16 2023 14:21:10) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies
Then we ask Symfony CLI if it can tell us which PHP version we are running in a directory containing Composer config platform php.
php -v
WARNING the current dir requires PHP 8.0.10 (composer.json from current dir: ./symfony-cli/composer.json), but this version is not available
PHP 8.2.1 (cli) (built: Jan 16 2023 14:21:10) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies
This is not what I expect, I expect to stay in the PHP minor range. In this specific case 8.0.27
.
symfony local:php:list
+---------+------------------------------------+---------+--------------+-------------+---------+---------+
| Version | Directory | PHP | PHP | PHP | Server | System? |
| | | CLI | FPM | CGI | | |
+---------+------------------------------------+---------+--------------+-------------+---------+---------+
| 8.0.27 | /usr/local/Cellar/php@8.0/8.0.27_1 | bin/php | sbin/php-fpm | bin/php-cgi | PHP FPM | |
| 8.1.14 | /usr/local/Cellar/php@8.1/8.1.14_1 | bin/php | sbin/php-fpm | bin/php-cgi | PHP FPM | |
| 8.2.1 | /usr/local/Cellar/php/8.2.1_1 | bin/php | sbin/php-fpm | bin/php-cgi | PHP FPM | |
+---------+------------------------------------+---------+--------------+-------------+---------+---------+
The current PHP version is selected from composer.json from current dir: /Users/jeffrey/Documents/symfony-cli/composer.json
To control the version used in a directory, create a .php-version file that contains the version number (e.g. 7.2 or 7.2.15),
or define config.platform.php inside composer.json.
If you're using Platform.sh, the version can also be specified in the .platform.app.yaml file.
If we use a PHP version that is present, then everything works properly.
composer config platform.php "8.0.27"
composer update --lock
php -v
PHP 8.0.27 (cli) (built: Jan 16 2023 18:14:33) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.27, Copyright (c) Zend Technologies
with Zend OPcache v8.0.27, Copyright (c), by Zend Technologies
What I've found so far is that the function bestVersion()
does a HasPrefix()
check. Based on the values 8.0.10
and my current PHP version 8.0.27
I do understand the error message.
Lines 143 to 153 in fe41b32
func (s *PHPStore) bestVersion(versionPrefix, source string) (*Version, string, string, error) { | |
// start from the end as versions are always sorted | |
for i := len(s.versions) - 1; i >= 0; i-- { | |
v := s.versions[i] | |
if v.Version == versionPrefix || strings.HasPrefix(v.Version, versionPrefix) { | |
return v, source, "", nil | |
} | |
} | |
return s.fallbackVersion(fmt.Sprintf(`the current dir requires PHP %s (%s), but this version is not available`, versionPrefix, source)) | |
} |
What could work?
Have the bestVersion()
function do a semantic version check.