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堆积如山,我太谨慎了,到处倾倒垃圾,并检查了容器本身,而不是服务。