【发布时间】:2016-10-18 12:50:50
【问题描述】:
在我的 Bundle 中,我使用 FooBundle/Service/SessionHandler.php 下的 SessionHandler 服务
这得到了一个扩展 Symfony 路由器的定制路由器:
use FooBundle/Routing/Router
(...)
public function __construct(HttpUtils $httpUtils, array $options, Router $router) {
$this->router = $router;
$this->container = $router->getContainer();
$this->defaultLogoutHandler = new DefaultLogoutSuccessHandler($httpUtils);
parent::__construct($httpUtils, $options);
}
这在 Symfony 2.1 中确实有效
在 3.1 中我得到一个例外:
可捕获的致命错误:传递给 FooBundle\Service\SessionHandler::__construct() 的参数 3 必须是 FooBundle\Routing\Router 的实例,给定 Symfony\Bundle\FrameworkBundle\Routing\Router 的实例
这是我的 services.xml 的样子:
<!-- SessionHandler -->
<service id="foo.sessionhandler" class="FooBundle\Service\SessionHandler">
<argument type="service" id="security.http_utils" />
<argument type="collection" id="options" />
<argument type="service" id="router" />
</service>
那么如何让这项服务使用我的定制路由器?
【问题讨论】:
标签: php symfony dependency-injection routing