diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index cd5d5c91..f82c1b35 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -164,6 +164,16 @@ protected function createFromInvokable($canonicalName, $requestedName) { $invokable = $this->invokableClasses[$canonicalName]; + if (!class_exists($invokable)) { + throw new Exception\ServiceNotFoundException(sprintf( + '%s: failed retrieving "%s%s" via invokable class "%s"; class does not exist', + get_class($this) . '::' . __FUNCTION__, + $canonicalName, + ($requestedName ? '(alias: ' . $requestedName . ')' : ''), + $invokable + )); + } + if (null === $this->creationOptions || (is_array($this->creationOptions) && empty($this->creationOptions)) ) { diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index d34a15e9..d3203eac 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -68,6 +68,18 @@ public function testSetMultipleCreationOptions() $this->assertEquals(array('key2' => 'value2'), $value['foo']->getCreationOptions()); } + /** + * @group issue-4208 + */ + public function testGetFaultyRegisteredInvokableThrowsException() + { + $this->setExpectedException('Zend\ServiceManager\Exception\ServiceNotFoundException'); + + $pluginManager = new FooPluginManager(); + $pluginManager->setInvokableClass('helloWorld', 'IDoNotExist'); + $pluginManager->get('helloWorld'); + } + public function testAbstractFactoryWithMutableCreationOptions() { $creationOptions = array('key1' => 'value1');