从 2.2.6 升级到 2.3.0 后,我今天早上自己也遇到了同样的问题。
ZF2.3.0 中有一个错误会导致 Di 模块在尝试创建 MvcTranslator 的实例时失败(请参阅:https ://github.com/zendframework/zf2/pull/5959 ,其中@Ocramius 和 noopable 提出了解决方案)。
在将修复程序推广到框架之前,您需要将以下代码更改为Zend\ServiceManager\Di\DiAbstractServiceFactory
:
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
return $this->instanceManager->hasSharedInstance($requestedName)
|| $this->instanceManager->hasAlias($requestedName)
|| $this->instanceManager->hasConfig($requestedName)
|| $this->instanceManager->hasTypePreferences($requestedName)
|| $this->definitions->hasClass($requestedName);
}
至:
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
if ($this->instanceManager->hasSharedInstance($requestedName)
|| $this->instanceManager->hasAlias($requestedName)
|| $this->instanceManager->hasConfig($requestedName)
|| $this->instanceManager->hasTypePreferences($requestedName)
) {
return true;
}
if (! $this->definitions->hasClass($requestedName) || interface_exists($requestedName)) {
return false;
}
return true;
}