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/4868' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 20, 2013
2 parents 429d5b0 + f066da4 commit fe45315
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,17 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP

if ($requestedClass != $class && $this->instanceManager->hasConfig($requestedClass)) {
$iConfig['requestedClass'] = $this->instanceManager->getConfig($requestedClass);

if (array_key_exists('parameters', $iConfig['requestedClass'])) {
$newParameters = array();

foreach($iConfig['requestedClass']['parameters'] as $name=>$parameter) {
$newParameters[$requestedClass.'::'.$method.'::'.$name] = $parameter;
}

$iConfig['requestedClass']['parameters'] = $newParameters;
}

if ($requestedAlias) {
$iConfig['requestedAlias'] = $this->instanceManager->getConfig($requestedAlias);
}
Expand Down
31 changes: 31 additions & 0 deletions test/DiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -877,4 +877,35 @@ public function testGetWithParamsWillUseSharedInstance()
$returnedC = $di->get($retrievedInstanceClass, array('params' => array('test')));
$this->assertInstanceOf($retrievedInstanceClass, $returnedC);
}

public function testGetInstanceWithParamsHasSameNameAsDependencyParam()
{
$config = new Config(array(
'definition' => array(
'class' => array(
'ZendTest\Di\TestAsset\AggregateClasses\AggregateItems' => array(
'addItem' => array(
'item' => array('type'=>'ZendTest\Di\TestAsset\AggregateClasses\ItemInterface',
'required'=>true)
)
)
)
),
'instance' => array(
'ZendTest\Di\TestAsset\AggregateClasses\AggregateItems' => array(
'injections' => array(
'ZendTest\Di\TestAsset\AggregateClasses\Item'
)
),
'ZendTest\Di\TestAsset\AggregatedParamClass' => array(
'parameters' => array(
'item' => 'ZendTest\Di\TestAsset\AggregateClasses\AggregateItems'
)
)
)
));

$di = new Di(null, null, $config);
$this->assertCount(1, $di->get('ZendTest\Di\TestAsset\AggregatedParamClass')->aggregator->items);
}
}
21 changes: 21 additions & 0 deletions test/TestAsset/AggregateClasses/AggregateItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset\AggregateClasses;

class AggregateItems implements ItemInterface
{
public $items = array();

public function addItem(ItemInterface $item)
{
$this->items[] = $item;
return $this;
}
}
14 changes: 14 additions & 0 deletions test/TestAsset/AggregateClasses/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset\AggregateClasses;

class Item implements ItemInterface
{
}
16 changes: 16 additions & 0 deletions test/TestAsset/AggregateClasses/ItemInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset\AggregateClasses;


interface ItemInterface
{

}
22 changes: 22 additions & 0 deletions test/TestAsset/AggregatedParamClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Di\TestAsset;

use ZendTest\Di\TestAsset\AggregateClasses\ItemInterface;

class AggregatedParamClass
{
public $aggregator = null;

public function __construct(ItemInterface $item)
{
$this->aggregator = $item;
}
}

0 comments on commit fe45315

Please sign in to comment.