当我在 zf2 中跟踪代码时,我找不到应用程序服务注册的位置。这是application.php中的代码
public static function init($configuration = array())
{
$smConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : array();
$serviceManager = new ServiceManager(new Service\ServiceManagerConfig($smConfig));
$serviceManager->setService('ApplicationConfig', $configuration);
$serviceManager->get('ModuleManager')->loadModules();
return $serviceManager->get('Application')->bootstrap();
}
代码“$serviceManager->get('Application')”用于获取Application服务。但是应用服务在哪里注册呢?
然后我发现Application服务与ZF2/library/Zend/MoudleManager中的代码行“$this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULES_POST, $this, $this->getEvent())”相关/MoudleManager.php
public function loadModules()
{
if (true === $this->modulesAreLoaded) {
return $this;
}
$this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULES, $this, $this->getEvent());
/**
* Having a dedicated .post event abstracts the complexity of priorities from the user.
* Users can attach to the .post event and be sure that important
* things like config merging are complete without having to worry if
* they set a low enough priority.
*/
$this->getEventManager()->trigger(ModuleEvent::EVENT_LOAD_MODULES_POST, $this, $this->getEvent());
return $this;
}
另一个问题是“ModuleEvent::EVENT_LOAD_MODULES_POST,即loadModules.post。触发函数的第一个参数是函数名。那么loadModules.post是函数吗?它是在哪里定义的?
提前致谢。