From dd0f7a2e571a61e6bd79839cd96cdeafc4d328f9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 15 May 2012 22:28:07 +0200 Subject: [PATCH 1/3] Fixing test issue (was setting alias injections before alias definition) --- test/DiTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/DiTest.php b/test/DiTest.php index 42ef0186..1210850f 100644 --- a/test/DiTest.php +++ b/test/DiTest.php @@ -634,8 +634,8 @@ public function testDiWillInjectDependenciesForAlias() $classDef->addMethod('setA', false); $classDef->addMethodParameter('setA', 'a', array('type' => 'ZendTest\Di\TestAsset\SetterInjection\A', 'required' => false)); $di->definitions()->addDefinition($classDef, false); - $di->instanceManager()->setInjections('b_alias', array('ZendTest\Di\TestAsset\SetterInjection\A')); $di->instanceManager()->addAlias('b_alias', 'ZendTest\Di\TestAsset\SetterInjection\B'); + $di->instanceManager()->setInjections('b_alias', array('ZendTest\Di\TestAsset\SetterInjection\A')); $b = $di->get('b_alias'); $this->assertInstanceOf('ZendTest\Di\TestAsset\SetterInjection\A', $b->a); From c60b061c1801b6c042675c5d38d9c1fd7ee3f021 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 15 May 2012 22:29:15 +0200 Subject: [PATCH 2/3] Fixing broken test --- src/Di.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Di.php b/src/Di.php index 7227a561..e203c2d5 100644 --- a/src/Di.php +++ b/src/Di.php @@ -208,7 +208,7 @@ public function newInstance($name, array $params = array(), $isShared = true) } } - $this->handleInjectDependencies($instance, $class, $injectionMethods, $supertypeInjectionMethods, $params, $alias); + $this->handleInjectDependencies($instance, $name, $injectionMethods, $supertypeInjectionMethods, $params, $alias); array_pop($this->instanceContext); return $instance; From 068f448b2ace3809845f0b7f5f97148bd265f437 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 15 May 2012 23:20:47 +0200 Subject: [PATCH 3/3] Removing unused method parameter $alias --- src/Di.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Di.php b/src/Di.php index e203c2d5..378c3124 100644 --- a/src/Di.php +++ b/src/Di.php @@ -208,7 +208,7 @@ public function newInstance($name, array $params = array(), $isShared = true) } } - $this->handleInjectDependencies($instance, $name, $injectionMethods, $supertypeInjectionMethods, $params, $alias); + $this->handleInjectDependencies($instance, $name, $injectionMethods, $supertypeInjectionMethods, $params); array_pop($this->instanceContext); return $instance; @@ -236,11 +236,11 @@ public function injectDependencies($instance, array $params = array()) $superTypeInjectionMethods[$interface] = $definitions->getMethods($interface); } } - $this->handleInjectDependencies($instance, null, $injectionMethods, $superTypeInjectionMethods, $params, null); + $this->handleInjectDependencies($instance, null, $injectionMethods, $superTypeInjectionMethods, $params); } - protected function handleInjectDependencies($instance, $name, $injectionMethods, $supertypeInjectionMethods, $params, $alias) + protected function handleInjectDependencies($instance, $name, $injectionMethods, $supertypeInjectionMethods, $params) { $class = get_class($instance); @@ -251,13 +251,13 @@ protected function handleInjectDependencies($instance, $name, $injectionMethods, if ($injectionMethods || $supertypeInjectionMethods) { foreach ($injectionMethods as $injectionMethod => $methodIsRequired) { if ($injectionMethod !== '__construct'){ - $this->resolveAndCallInjectionMethodForInstance($instance, $injectionMethod, $params, $alias, $methodIsRequired, $class); + $this->resolveAndCallInjectionMethodForInstance($instance, $injectionMethod, $params, $name, $methodIsRequired, $class); } } foreach ($supertypeInjectionMethods as $supertype => $supertypeInjectionMethod) { foreach ($supertypeInjectionMethod as $injectionMethod => $methodIsRequired) { if ($injectionMethod !== '__construct') { - $this->resolveAndCallInjectionMethodForInstance($instance, $injectionMethod, $params, $alias, $methodIsRequired, $supertype); + $this->resolveAndCallInjectionMethodForInstance($instance, $injectionMethod, $params, $name, $methodIsRequired, $supertype); } } } @@ -294,7 +294,7 @@ protected function handleInjectDependencies($instance, $name, $injectionMethods, if ($methodParams) { foreach ($methodParams as $methodParam) { if (get_class($objectToInject) == $methodParam[1] || $this->isSubclassOf(get_class($objectToInject), $methodParam[1])) { - $this->resolveAndCallInjectionMethodForInstance($instance, $injectionMethod, array($methodParam[0] => $objectToInject), $alias, true, get_class($instance)); + $this->resolveAndCallInjectionMethodForInstance($instance, $injectionMethod, array($methodParam[0] => $objectToInject), $name, true, get_class($instance)); continue 3; } } @@ -304,7 +304,7 @@ protected function handleInjectDependencies($instance, $name, $injectionMethods, } if ($methodsToCall) { foreach ($methodsToCall as $methodInfo) { - $this->resolveAndCallInjectionMethodForInstance($instance, $methodInfo['method'], $methodInfo['args'], $alias, true, get_class($instance)); + $this->resolveAndCallInjectionMethodForInstance($instance, $methodInfo['method'], $methodInfo['args'], $name, true, get_class($instance)); } } }