Php Symfony 4捆绑包:AuthenticationUtils但不存在此类服务
我正试图创建一个捆绑包(symfony4)来管理我们所有项目的用户,但我遇到了一个问题 无法自动连接“App\Aroban\Bundle\usiaturbundle\Controller\SecurityController::login()”的参数$authenticationUtils:它引用类“Symfony\Component\Security\Http\Authentication\authenticationUtils”,但不存在此类服务 我不明白为什么没有注入服务 在项目的composer.json中,有“symfony/security bundle”:“4.3.*” 在捆绑包中: SecurityController.phpPhp Symfony 4捆绑包:AuthenticationUtils但不存在此类服务,php,service,dependency-injection,bundle,symfony4,Php,Service,Dependency Injection,Bundle,Symfony4,我正试图创建一个捆绑包(symfony4)来管理我们所有项目的用户,但我遇到了一个问题 无法自动连接“App\Aroban\Bundle\usiaturbundle\Controller\SecurityController::login()”的参数$authenticationUtils:它引用类“Symfony\Component\Security\Http\Authentication\authenticationUtils”,但不存在此类服务 我不明白为什么没有注入服务 在项目的comp
<?php
namespace App\Aroban\Bundle\UtilisateurBundle\Controller;
use App\Aroban\Bundle\UtilisateurBundle\Entity\Utilisateur;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Swift_Mailer;
class SecurityController extends AbstractController
{
public function login(AuthenticationUtils $authenticationUtils): Response
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('@Utilisateur/security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}
.......
}
当我执行命令时
php bin/控制台调试:容器| grep安全
我看不到服务
Symfony\Component\Security\Csrf\csrftokenmanager“Security.Csrf.token\u manager”的接口别名Symfony\Component\Security\Csrf\TokenGenerator\TokenGenerator“Security.Csrf.token\u generator”的接口别名
Symfony\Component\Security\Csrf\TokenStorage\TokenStorage“Security.Csrf.token\u storage”的接口别名
条令.orm.security.user.provider Symfony\Bridge\doctor\security\user\EntityUserProvider
maker.security\u config\u更新程序Symfony\Bundle\MakerBundle\security\SecurityConfigUpdater
security.csrf.token\u生成器Symfony\Component\security\csrf\TokenGenerator\UriSafeTokenGenerator
security.csrf.token\u管理器Symfony\Component\security\csrf\CsrfTokenManager
security.csrf.token\u存储Symfony\Component\security\csrf\TokenStorage\SessionTokenStorage
twig.extension.security\u csrf Symfony\Bridge\twig\extension\CsrfExtension
twig.runtime.security\u csrf Symfony\Bridge\twig\Extension\CsrfRuntime
//要搜索特定服务,请使用搜索词重新运行此命令。(例如调试:容器
//日志)
谢谢你的帮助 之后您是否尝试安装了
composer
这将安装在composer.json中指定的依赖项
您可能必须删除composer.lock,以便它安装添加的依赖项(请参阅)。最简单的方法可能是使用composer require symfony/security bundle:4.3,而不是您可能必须删除composer.lock,以便它安装您添加的依赖项(请参阅)。最简单的方法可能是使用
composer require symfony/security bundle:4.3
而不是您可以编辑答案,将此信息放入答案本身。
<?php
namespace App\Aroban\Bundle\UtilisateurBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('utilisateur');
$rootNode = $treeBuilder->getRootNode();
return $treeBuilder;
}
}
<?php
namespace App\Aroban\Bundle\UtilisateurBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader;
class UtilisateurExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
}
}
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
App\Aroban\Bundle\UtilisateurBundle\:
resource: '../../*'
exclude: '../../{Entity,Migrations,Tests,Kernel.php}'
App\Aroban\Bundle\UtilisateurBundle\Controller\:
resource: '../../Controller/*'
tags: ['controller.service_arguments']