我正在尝试迁移到 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}'
我将我的树枝扩展声明为:
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.
并且不知道如何解决它。