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

Commit

Permalink
Zend\Di - ZF2-65
Browse files Browse the repository at this point in the history
    - Fixed Zend\Di\Definition\Builder to return proper array of info for parameters
  • Loading branch information
Ralph Schindler committed Sep 6, 2011
14 parents b38b581 + 9a9f950 + 47a731a + 0967316 + 37f548b + 0df2db0 + e43587e + 5784352 + 93b4f40 + 3208a48 + f5dfded + 8301af5 + d4a4329 + eaf7585 commit c004297
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
14 changes: 8 additions & 6 deletions src/Definition/Builder/InjectionMethod.php
Expand Up @@ -20,13 +20,15 @@ public function getName()
return $this->name;
}

public function addParameter($name, $class = null, $position = self::PARAMETER_POSTION_NEXT)
public function addParameter($name, $class = null, $paramIsOptional = false, $classIsInstantiable = null)
{
if ($position == self::PARAMETER_POSTION_NEXT) {
$this->parameters[$name] = $class;
} else {
throw new \Exception('Implementation for parameter placement is incomplete');
}
$this->parameters[$name] = array(
$class,
$paramIsOptional,
(($classIsInstantiable === null && $class !== null)
? (($classIsInstantiable === null) ? true : (bool) $classIsInstantiable)
: null)
);
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjector.php
Expand Up @@ -5,12 +5,12 @@
class DependencyInjector implements DependencyInjection
{
/**
* @var Zend\Di\Definition
* @var Definition
*/
protected $definition = null;

/**
* @var Zend\Di\InstanceManager
* @var InstanceManager
*/
protected $instanceManager = null;

Expand Down
12 changes: 6 additions & 6 deletions test/Definition/BuilderDefinitionTest.php
Expand Up @@ -36,7 +36,7 @@ public function testBuilderCanBuildClassWithMethods()
$this->assertTrue($definition->hasInjectionMethods('Foo'));
$this->assertTrue($definition->hasInjectionMethod('Foo', 'injectBar'));
$this->assertContains('injectBar', $definition->getInjectionMethods('Foo'));
$this->assertEquals(array('bar' => 'Bar'), $definition->getInjectionMethodParameters('Foo', 'injectBar'));
$this->assertEquals(array('bar' => array('Bar', false, true)), $definition->getInjectionMethodParameters('Foo', 'injectBar'));
}

public function testBuilderCanBuildFromArray()
Expand All @@ -52,21 +52,21 @@ public function testBuilderCanBuildFromArray()
$this->assertTrue($definition->hasClass('My\DbAdapter'));
$this->assertEquals('__construct', $definition->getInstantiator('My\DbAdapter'));
$this->assertEquals(
array('username' => null, 'password' => null),
array('username' => array(null, false, null), 'password' => array(null, false, null)),
$definition->getInjectionMethodParameters('My\DbAdapter', '__construct')
);

$this->assertTrue($definition->hasClass('My\Mapper'));
$this->assertEquals('__construct', $definition->getInstantiator('My\Mapper'));
$this->assertEquals(
array('dbAdapter' => 'My\DbAdapter'),
array('dbAdapter' => array('My\DbAdapter', false, true)),
$definition->getInjectionMethodParameters('My\Mapper', '__construct')
);

$this->assertTrue($definition->hasClass('My\Repository'));
$this->assertEquals('__construct', $definition->getInstantiator('My\Repository'));
$this->assertEquals(
array('mapper' => 'My\Mapper'),
array('mapper' => array('My\Mapper', false, true)),
$definition->getInjectionMethodParameters('My\Repository', '__construct')
);

Expand Down Expand Up @@ -94,8 +94,8 @@ public function testCanCreateInjectionMethodsAndPopulateFromFluentInterface()
$this->assertTrue($builder->hasInjectionMethod('Foo', 'setBar'));
$this->assertTrue($builder->hasInjectionMethod('Foo', 'setConfig'));

$this->assertEquals(array('bar' => 'Bar'), $builder->getInjectionMethodParameters('Foo', 'setBar'));
$this->assertEquals(array('config' => null), $builder->getInjectionMethodParameters('Foo', 'setConfig'));
$this->assertEquals(array('bar' => array('Bar', false, true)), $builder->getInjectionMethodParameters('Foo', 'setBar'));
$this->assertEquals(array('config' => array(null, false, null)), $builder->getInjectionMethodParameters('Foo', 'setConfig'));
}

public function testBuilderCanSpecifyClassToUseWithCreateClass()
Expand Down

0 comments on commit c004297

Please sign in to comment.