我正在使用Symfony 4.2
这是我要自动连线的班级配置:
services:
_defaults:
autowire: true
# autoconfigure: true
Cyrene\components\:
resource: '../../app/components/*'
tags: ['controller.service_arguments']
exclude:
- '../../app/components/common/*'
路径是正确的,因为使用symfony的debug:container
命令,它确实向我显示了“组件”文件夹中的所有类。
但是使用symfony的debug:autowiring
命令,即使它们具有标签controller.service_arguments
,它也不会自动显示。它不会显示我的任何类。
我在这里做错了什么?
我也面临着另一个问题...
尽管我使用的是一个自动装配类,例如Psr\Log\LoggerInterface
(默认情况下可以从symfony自动装配),但是symfony不会将其传递给构造函数:
use Cyrene\core\actions\AbstractAdminAction;
use Psr\Log\LoggerInterface;
class OverviewIndexAction extends AbstractAdminAction
{
public function __construct(LoggerInterface $logger, OverviewIndexResponder $responder)
{
$this->responder = $responder;
}
我收到此错误消息:[...] Too few arguments to function Cyrene\components\admin\application\overview\index\OverviewIndexAction::__construct(), 0 passed [...] but exactly 2 expected [...]
这使我想到自动布线通常不起作用的假设。
$logger
应该已经自动接线,因为它与symfony的debug:autowiring
命令一起列出。 OverviewIndexResponder $responder
与OverviewIndexAction
在相同的路径/名称空间中,因此没有use
。
答案 0 :(得分:0)
有趣的是,当您问别人时,通常会发现问题所在。
问题是,我自己的ControllerResolver
没有扩展正确的超类。
这是正确的:
use Symfony\Component\HttpKernel\Controller\ContainerControllerResolver as SymfonyControllerResolver;
class ControllerResolver extends SymfonyControllerResolver
ContainerControllerResolver
负责注入正确的对象。
尽管自动装配有效,但debug:autowiring
仍未列出我的课程。
答案 1 :(得分:0)
如果您使用的是Symfony 4.2.0,则此版本中存在错误。
要解决该问题,请尝试:
{BCE → A}