Closed
Description
Symfony version(s) affected
7.1
Description
When the security bundle config is not present, it tries to be helpful and suggest running composer symfony:recipes:install
as long as the InstallRecipesCommand
class from the flex package exists:
The problem with this is that InstallRecipesCommand
extends Composer\Command\BaseCommand
which does not exist when running under the context of Symfony (unless the composer/composer package is installed) so the following error is thrown:
!! Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#4786
!! #message: """
!! Attempted to load class "BaseCommand" from namespace "Composer\Command".\n
!! Did you forget a "use" statement for another namespace?
!! """
!! #code: 0
!! #file: "./vendor/symfony/flex/src/Command/InstallRecipesCommand.php"
!! #line: 25
!! trace: {
!! ./vendor/symfony/flex/src/Command/InstallRecipesCommand.php:25 { …}
!! ./vendor/symfony/error-handler/DebugClassLoader.php:300 { …}
!! Symfony\Component\ErrorHandler\DebugClassLoader->loadClass() {}
!! ./vendor/symfony/security-bundle/DependencyInjection/SecurityExtension.php:94 { …}
!! ./vendor/symfony/dependency-injection/Compiler/MergeExtensionConfigurationPass.php:81 { …}
!! ./vendor/symfony/http-kernel/DependencyInjection/MergeExtensionConfigurationPass.php:40 { …}
!! ./vendor/symfony/dependency-injection/Compiler/Compiler.php:73 { …}
!! ./vendor/symfony/dependency-injection/ContainerBuilder.php:752 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:495 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:740 { …}
!! ./vendor/symfony/http-kernel/Kernel.php:120 { …}
!! ./vendor/symfony/framework-bundle/Console/Application.php:177 { …}
!! ./vendor/symfony/framework-bundle/Console/Application.php:69 { …}
!! ./vendor/symfony/console/Application.php:167 { …}
!! ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49 { …}
!! ./vendor/autoload_runtime.php:34 { …}
!! ./bin/console:13 {
!! ›
!! › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
!! ›
!! arguments: {
!! "/var/www/app/vendor/autoload_runtime.php"
!! }
!! }
!! }
!! }
!! 2024-10-22T09:38:17+01:00 [critical] Uncaught Error: Class "Composer\Command\BaseCommand" not found
!!
How to reproduce
Run the following commands to create a new Symfony project with missing security bundle config:
symfony new my_project_directory --version="7.1.*" --webapp
cd my_project_directory
rm -f config/packages/security.yaml
symfony server:start
Open the browser window and see the following error:
Possible Solution
Could possibly call Composer\InstalledVersions::isInstalled('symfony/flex')
instead of class_exists
Additional Context
No response