Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony容器:定义未转换为服务_Php_Symfony - Fatal编程技术网

Php Symfony容器:定义未转换为服务

Php Symfony容器:定义未转换为服务,php,symfony,Php,Symfony,在一个遗留应用程序中,我们引入了容器,在其中添加定义内部扩展 $serviceId = ($alias == 'default') ? 'm6_statsd' : 'm6_statsd.'.$alias; $definition = new Definition('M6Web\Component\Statsd\Client'); $definition->setScope(ContainerInterface::SCOPE_CONTAINER); $def

在一个遗留应用程序中,我们引入了容器,在其中添加
定义
内部
扩展

    $serviceId  = ($alias == 'default') ? 'm6_statsd' : 'm6_statsd.'.$alias;
    $definition = new Definition('M6Web\Component\Statsd\Client');
    $definition->setScope(ContainerInterface::SCOPE_CONTAINER);
    $definition->addArgument($usedServers);

    $container->setDefinition($serviceId, $definition);
//容器的编译方法

private function loadContainer()
{
    // Ok that's just plain bad, but at least it works. I need this as a static because controllers can't access application
    // and I can't put container in models because it would be inherited by front office.
    self::$container = new ContainerBuilder();

    $helpscoutExtension = new HelpscoutExtension();
    self::$container->registerExtension($helpscoutExtension);
    self::$container->loadFromExtension($helpscoutExtension->getAlias());

    $statsdExtension = new StatsdExtension();
    self::$container->registerExtension($statsdExtension);
    self::$container->loadFromExtension($statsdExtension->getAlias());

    $loader = new YamlFileLoader(self::$container, new FileLocator(C_PATH_GLOBAL_CONF));
    $loader->load('bov6.yml');

    self::$container->compile();
    dump(self::$container);
}
容器已编译,但当我转储容器时,它仅显示定义,并且没有可用的服务


请问我错过了什么?为什么定义没有转换为服务?

如果没有为服务调用
$container->get('service')
方法,则不会创建服务


服务在您第一次尝试访问时即被实例化。

您说得对,谢谢。由于Symfony堆积如山,我太谨慎了,到处倾倒垃圾,并检查了容器本身,而不是服务。