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

Commit

Permalink
Merge remote-tracking branch 'weierophinney/hotfix/remove-subclass-ce…
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Jul 11, 2012
2 parents d0c1a7e + 9f76d61 commit cc47b49
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Zend\Di;

use Closure;
use Zend\Stdlib\SubClass;
use ReflectionClass;

class Di implements DependencyInjectionInterface
{
Expand Down Expand Up @@ -310,7 +310,7 @@ protected function handleInjectDependencies($instance, $injectionMethods, $param
if ($methodParams) {
foreach ($methodParams as $methodParam) {
$objectToInjectClass = $this->getClass($objectToInject);
if ($objectToInjectClass == $methodParam[1] || SubClass::isSubclassOf($objectToInjectClass, $methodParam[1])) {
if ($objectToInjectClass == $methodParam[1] || self::isSubclassOf($objectToInjectClass, $methodParam[1])) {
if ($this->resolveAndCallInjectionMethodForInstance($instance, $typeInjectionMethod, array($methodParam[0] => $objectToInject), $instanceAlias, true, $type)) {
$calledMethods[$typeInjectionMethod] = true;
}
Expand Down Expand Up @@ -583,7 +583,7 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
}
$pInstanceClass = ($this->instanceManager->hasAlias($pInstance)) ?
$this->instanceManager->getClassFromAlias($pInstance) : $pInstance;
if ($pInstanceClass === $type || SubClass::isSubclassOf($pInstanceClass, $type)) {
if ($pInstanceClass === $type || self::isSubclassOf($pInstanceClass, $type)) {
$computedParams['required'][$fqParamPos] = array($pInstance, $pInstanceClass);
continue 2;
}
Expand All @@ -600,7 +600,7 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
}
$pInstanceClass = ($this->instanceManager->hasAlias($pInstance)) ?
$this->instanceManager->getClassFromAlias($pInstance) : $pInstance;
if ($pInstanceClass === $type || SubClass::isSubclassOf($pInstanceClass, $type)) {
if ($pInstanceClass === $type || self::isSubclassOf($pInstanceClass, $type)) {
$computedParams['required'][$fqParamPos] = array($pInstance, $pInstanceClass);
continue 2;
}
Expand Down Expand Up @@ -682,4 +682,27 @@ protected function getClass($instance)
return get_class($instance);
}

/**
* Checks if the object has this class as one of its parents
*
* @see https://bugs.php.net/bug.php?id=53727
* @see https://github.com/zendframework/zf2/pull/1807
*
* @param string $className
* @param string $type
*/
protected static function isSubclassOf($className, $type)
{
if (version_compare(PHP_VERSION, '5.3.7', '>=')) {
return is_subclass_of($className, $type);
}
if (is_subclass_of($className, $type)) {
return true;
}
if (!interface_exists($type)) {
return false;
}
$r = new ReflectionClass($className);
return $r->implementsInterface($type);
}
}

0 comments on commit cc47b49

Please sign in to comment.