gpt4 book ai didi

symfony - "Service xxx has a dependency on a non-existent service"这似乎不是真的?

转载 作者:行者123 更新时间:2023-12-03 23:15:41 25 4
gpt4 key购买 nike

我有一些应用程序要迁移到 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
}
}

既不在这个类(class),也不在扩展类(class) Router来自 FrameworkBundle 的依赖于 LoaderInterface .

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

最佳答案

看起来有两个容器参数导致了问题。使用全新的 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 参数。我认为这是令人困惑的 Autowiring 。甚至可能是一个错误。

关于symfony - "Service xxx has a dependency on a non-existent service"这似乎不是真的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51150361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com