Repository navigation
Dependency Issue with Alchemy 4.0 - test, lint not working #140
Description
Hi again,
Problem:
Features like test and lint added by Alchemy do not work for if PHP version is too high - website says Leaf requires PHP v7.4 or higher, PHP v8.3 was OK for me. Migration to PHP v. 8.5 caused problems.
Creating a new project shows this warning:
PHP Fatal error: Uncaught Error: Call to undefined method Symfony\Component\Console\Application::add() in /home/j/jaclarke/php_web/leaf/uhoh/vendor/leafs/alchemy/bin/alchemy:22
Stack trace:
#0 /home/j/jaclarke/php_web/leaf/uhoh/vendor/bin/alchemy(119): include()
#1 {main}
thrown in /home/j/jaclarke/php_web/leaf/uhoh/vendor/leafs/alchemy/bin/alchemy on line 22
❌ Could not scaffold extra options for uhoh
To reproduce:
On a server running PHP 8.4.1 or higher, install Leaf and try creating a project.
###Cause:
Alchemy 4.0's composer.json claims its requirements are:
"require": {
"ext-json": "*",
"leafs/fs": "*",
"symfony/console": "*",
"symfony/process": "*",
"symfony/yaml": "*"
}
However if PHP >= 8.4.1 is installed, these lines in leafs/alchemy/bin will break:
$app->add(new Leaf\Alchemy\Commands\InstallCommand);
$app->add(new Leaf\Alchemy\Commands\SetupCommand);
Symfony 8 requires PHP >= 8.4.1
Symphony/Console >= 8 replaces Application::add() with Applicaton::addCommand().
Symfony, as of 7.4, had implemented the change by having add() trigger a deprecation notice (present since Symfony 7.4) then call addCommand() :
/**
* @deprecated since Symfony 7.4, use Application::addCommand() instead
*/
public function add(Command $command): ?Command
{
trigger_deprecation('symfony/console', '7.4', 'The "%s()" method is deprecated and will be removed in Symfony 8.0, use "%s::addCommand()" instead.', __METHOD__, self::class);
return $this->addCommand($command);
}
But now the add() function is completely removed.
Solution:
Either add constraints in LeafPHP's composer.json files to limit all Symfony requirements to no higher than major version 7,
"require": {
"ext-json": "*",
"leafs/fs": "*",
"symfony/console": "<8",
"symfony/process": "<8",
"symfony/yaml": "<8"
}
with serious thought about what the minimum required version of Symphony should be.
OR update LeafPHP to guard against this breaking change. yaml-lint guards against this change as follows:
if (method_exists($app = new Application(), 'addCommand')) {
$app->addCommand($command);
} else {
$app->add($command);
}
Temporary Workaround:
In project folder:
- force downgrade to highest release of symfony/console 7 with
leaf install symfony/console@v7.* - run alchemy by hand with
vendor/leafs/alchemy/bin/alchemy install - try a command installed by alchemy:
leaf run lint
Hoping I'm helping and not driving you all crazy!
Activity