“服务xxx依赖于不存在的服务”这似乎不正确?

时间:2018-07-03 08:52:08

标签: symfony

我有一些要迁移到Symfony 4.1的应用程序。启用container.autowiring.strict_mode: true后,我在恢复自定义Router

时出错
The service ".service_locator.G69Xsbl.Foo\Bundle\Admin\SiteRoutingBundle\Routing\AdminSiteRouter" 
has a dependency on a non-existent service "Symfony\Component\Config\Loader\LoaderInterface".

该类如下:

<?php

namespace Foo\Bundle\Admin\SiteRoutingBundle\Routing;

use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Foo\Bundle\Common\CoreBundle\Manager\SiteManagerInterface;

class AdminSiteRouter extends Router
{
    const USE_SITE_HOST  = true;
    const USE_SITE_PARAM = false;

    protected $siteManager;

    public function setSiteManager(SiteManagerInterface $siteManager)
    {
        $this->siteManager = $siteManager;
    }

    public function generate($name, $parameters = [], $referenceType = self::ABSOLUTE_URL)
    {
        // some code
    }
}

在此类中,或者FrameworkBundle中的扩展类Router都没有对LoaderInterface的依赖。

此类的自动装配配置:

Foo\Bundle\Admin\SiteRoutingBundle\Routing\AdminSiteRouter:
    arguments:
        $resource: '%site_routing_file_path%'
        $options: []
    calls:
        - [setSiteManager, ['@Foo\Bundle\Common\CoreBundle\Manager\SiteManagerInterface']]

1 个答案:

答案 0 :(得分:3)

看起来有两个容器参数引起了问题。使用全新的4.1.1安装,我遇到了相同的错误。使用以下方法修复了该问题:

# services.yaml
App\Service\AdminRouter:
    arguments:
        $container: '@service_container'
        $parameters: '@service_container'
        $resource: 'resource'
        $options: []

我的管理员路由器很简单:

namespace App\Service;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
class AdminRouter extends Router
{
}

作为参考,框架路由器看起来像:

public function __construct(
    ContainerInterface $container, 
    $resource, 
    array $options = array(), 
    RequestContext $context = null, 
    ContainerInterface $parameters = null, 
    LoggerInterface $logger = null)
{

注意两个ContainerInterface参数。我认为这会混淆自动接线。甚至可能是一个错误。