diff --git a/src/Di.php b/src/Di.php index 53259c0b..93e73461 100644 --- a/src/Di.php +++ b/src/Di.php @@ -175,8 +175,6 @@ public function newInstance($name, array $params = array(), $isShared = true) } } elseif (is_callable($instantiator)) { $object = $this->createInstanceViaCallback($instantiator, $params, $alias); - // @todo make sure we can create via a real object factory - throw new \Exception('incomplete implementation'); } else { throw new Exception\RuntimeException('Invalid instantiator'); } @@ -191,7 +189,9 @@ public function newInstance($name, array $params = array(), $isShared = true) if ($injectionMethods) { foreach ($injectionMethods as $injectionMethod => $methodIsRequired) { - $this->handleInjectionMethodForObject($object, $injectionMethod, $params, $alias, $methodIsRequired); + if ($injectionMethod !== '__construct'){ + $this->handleInjectionMethodForObject($object, $injectionMethod, $params, $alias, $methodIsRequired); + } } $instanceConfiguration = $instanceManager->getConfiguration($name); diff --git a/test/ConfigurationTest.php b/test/ConfigurationTest.php index 67fd7a18..e2b1711b 100644 --- a/test/ConfigurationTest.php +++ b/test/ConfigurationTest.php @@ -72,5 +72,52 @@ public function testConfigurationCanConfigureBuilderDefinitionFromIni() } + public function testCanSetInstantiatorToStaticFactory() + { + $config = new Configuration(array( + 'definition' => array( + 'class' => array( + 'ZendTest\Di\TestAsset\DummyParams' => array( + 'instantiator' => array('ZendTest\Di\TestAsset\StaticFactory', 'factory'), + ), + 'ZendTest\Di\TestAsset\StaticFactory' => array( + 'methods' => array( + 'factory' => array( + 'struct' => array( + 'type' => 'ZendTest\Di\TestAsset\Struct', + 'required' => true, + ), + 'params' => array( + 'required' => true, + ), + ), + ), + ), + ), + ), + 'instance' => array( + 'ZendTest\Di\TestAsset\DummyParams' => array( + 'parameters' => array( + 'struct' => 'ZendTest\Di\TestAsset\Struct', + 'params' => array( + 'foo' => 'bar', + ), + ), + ), + 'ZendTest\Di\TestAsset\Struct' => array( + 'parameters' => array( + 'param1' => 'hello', + 'param2' => 'world', + ), + ), + ), + )); + $di = new Di(); + $di->configure($config); + $dummyParams = $di->get('ZendTest\Di\TestAsset\DummyParams'); + $this->assertEquals($dummyParams->params['param1'], 'hello'); + $this->assertEquals($dummyParams->params['param2'], 'world'); + $this->assertEquals($dummyParams->params['foo'], 'bar'); + } }