class CustomSawException extends Exception implements ServiceLocatorAwareInterface, SawExceptionInterface
{
protected $serviceLocator;
public function test(){
$this->serviceLocator->get('SomeThing');
}
/**
* Set service locator
*
* @param ServiceLocatorInterface $serviceLocator
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}
/**
* Get service locator
*
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->serviceLocator;
}
時引發的,這是唯一的例外:獲取對空服務定位爲null
()調用我無法弄清楚,爲什麼它拋出異常?
ServiceLocatorAwareInterface
應該注射了ServiceLocator
?
「...是爲此引發的異常」...何時?你打這個班怎麼樣?服務定位器只能在服務管理器正在實例化類時注入。 –