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の場合、このためにスローされる例外がある:それは例外がスローされる理由はnullのServiceLocatorは
上のgetの
コール()、私は把握できませんでしたか?
ServiceLocatorAwareInterface
はServiceLocator
を注射していますか?
"...これは例外です。" ...いつですか?どのようにこのクラスに電話していますか?サービス・ロケータは、サービス・マネージャがクラスをインスタンス化している場合にのみ注入できます。 –