我想迁移到Symfony 3.3并使用新功能autowire
/autoconfigure
服务:
因此,在services.yml中,我有:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
# makes classes in src/AppBundle available to be used as services
AppBundle\:
resource: '../../src/AppBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/AppBundle/{Entity,Controller,DQL,Form/DataTransformer,Repository}'
我声明我的Twig扩展如下:
AppBundle\Twig\ImageExtension:
arguments:
$env: "%kernel.environment%"
这项服务的构造函数:
public function __construct(TokenStorage $token, UserRepository $userRepository, RedisCacheService $cache, string $env)
{
$this->env = $env;
$this->user = $token->getToken() ? $token->getToken()->getUser() : false;
$this->userRepository = $userRepository;
$this->cache = $cache;
}
看起来一切都没问题,但我仍然收到这个错误:
(1/1) AutowiringFailedException
Cannot autowire service "AppBundle\Twig\ImageExtension": argument "$env" of method "__construct()" must have a type-hint or be given a value explicitly.
我不知道如何解决这个问题。
env
参数,他谈论的是他的配置无法工作。根据手动绑定的官方文档,他的配置看起来是正确的。 @kRicha:你确定你将Symfony依赖项更新到3.3+吗? - Noémi Salaün3
而不是$env
。或者对其他三个服务使用空引号。argument: ['', '', '', '%kernel.environment%]
- Noémi Salaün