FriendsOfShopware / shopware-cli

CLI for Shopware Account and Shopware 6
MIT License
84 stars 32 forks source link

Use symfony CLI for running PHP when available #311

Closed nussjustin-hmmh closed 9 months ago

nussjustin-hmmh commented 9 months ago

Right now there is no easy way to choose a PHP version / installation for use by shopware-cli. This can be a problem when working on multiple projects with different required PHP versions.

Symfony's CLI tool can automatically detect the correct PHP version / installation to use for a project based on (among other things) a .php-version file or the required PHP version from composer.json files.

This PHP version can than be used by running symfony php instead of php. Similarly there is also a symfony composer command for running composer with the correct PHP version and even a symfony console command for running the bin/console tool.

We can use this to easily support different PHP versions.

This PR introduces a new internal/phpexec package for creating commands for running PHP, composer and bin/console which will automatically use the Symfony CLI if available.

It also updates the existing code to use the new package whenever possible.

The new logic can be disable by setting the SHOPWARE_CLI_NO_SYMFONY_CLI environment variable to 1.

While it would also have been possible to directly import the logic from the symfony-cli repository (which is also written in Go), doing so would be more work as the logic is not in one place and it may end up introducing incompatibilities between the two implementations.

Also unlike the actual CLI interface (symfony php, etc.) the actual source packages are not guaranteed to be stable.