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/ZF2-260'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
$callTimeCurValue =& $callTimeUserParams[$name];
}

if (is_string($callTimeCurValue)) {
if ($type !== false && is_string($callTimeCurValue)) {
if ($this->instanceManager->hasAlias($callTimeCurValue)) {
// was an alias provided?
$computedParams['required'][$fqParamPos] = array(
Expand Down Expand Up @@ -525,8 +525,7 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
$iConfigCurValue =& $iConfig[$thisIndex]['parameters'][$name];
}

if (is_string($iConfigCurValue)
&& $type === false) {
if ($type === false && is_string($iConfigCurValue)) {
$computedParams['value'][$fqParamPos] = $iConfigCurValue;
} elseif (is_string($iConfigCurValue)
&& isset($aliases[$iConfigCurValue])) {
Expand Down
21 changes: 21 additions & 0 deletions test/DiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,4 +664,25 @@ public function testInjectionForSetterInjectionWillNotUseSupertypeWhenChildParam
$c = $di->get('ZendTest\Di\TestAsset\InheritanceClasses\C');
$this->assertEquals('b', $c->test);
}

/**
* @group ZF2-260
*/
public function testDiWillInjectClassNameAsStringAtCallTime()
{
$di = new Di;

$classDef = new Definition\ClassDefinition('ZendTest\Di\TestAsset\SetterInjection\D');
$classDef->addMethod('setA', true);
$classDef->addMethodParameter('setA', 'a', array('type' => false, 'required' => true));
$di->definitions()->addDefinition($classDef, false);

$d = $di->get(
'ZendTest\Di\TestAsset\SetterInjection\D',
array('a' => 'ZendTest\Di\TestAsset\SetterInjection\A')
);

$this->assertSame($d->a, 'ZendTest\Di\TestAsset\SetterInjection\A');
}

}
12 changes: 12 additions & 0 deletions test/TestAsset/SetterInjection/D.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace ZendTest\Di\TestAsset\SetterInjection;

class D
{
public $a = null;
public function setA($a)
{
$this->a = $a;
}
}

0 comments on commit a248769

Please sign in to comment.