Skip to content

[SecurityBundle] Class not found error when checking for existence of flex InstallRecipesCommand #58624

Closed
@andyexeter

Description

@andyexeter

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:

if (!array_filter($configs)) {
$hint = class_exists(InstallRecipesCommand::class) ? 'Try running "composer symfony:recipes:install symfony/security-bundle".' : 'Please define your settings for the "security" config section.';
throw new InvalidConfigurationException('The SecurityBundle is enabled but is not configured. '.$hint);
}

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:

Screenshot from 2024-10-22 09-58-42

Possible Solution

Could possibly call Composer\InstalledVersions::isInstalled('symfony/flex') instead of class_exists

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy