Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/remove-di-exception' of https://github.com/EvanD…
Browse files Browse the repository at this point in the history
…otPro/zf2 into hotfix/di-factory-construction
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Di.php
Expand Up @@ -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');
}
Expand All @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions test/ConfigurationTest.php
Expand Up @@ -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');
}

}

0 comments on commit 698a4d6

Please sign in to comment.