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

Commit

Permalink
Zend\Di
Browse files Browse the repository at this point in the history
- Allow new dimension to the type information in definition false means carte-blanche values (no class lookup)
- Fixed newInstance() to early register instance so that setter injection will not cause circular dependencies
  • Loading branch information
Ralph Schindler committed Oct 10, 2011
1 parent a71e9b0 commit 35967e7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ public function newInstance($name, array $params = array(), $isShared = true)
throw new Exception\RuntimeException('Invalid instantiator');
}

if ($isShared) {
if ($params) {
$this->instanceManager->addSharedInstanceWithParameters($object, $name, $params);
} else {
$this->instanceManager->addSharedInstance($object, $name);
}
}

if ($injectionMethods) {
foreach ($injectionMethods as $injectionMethod => $methodIsRequired) {
$this->handleInjectionMethodForObject($object, $injectionMethod, $params, $alias, $methodIsRequired);
Expand Down Expand Up @@ -216,13 +224,7 @@ public function newInstance($name, array $params = array(), $isShared = true)
}
}

if ($isShared) {
if ($params) {
$this->instanceManager->addSharedInstanceWithParameters($object, $name, $params);
} else {
$this->instanceManager->addSharedInstance($object, $name);
}
}


array_pop($this->instanceContext);
return $object;
Expand Down Expand Up @@ -434,6 +436,9 @@ protected function resolveMethodParameters($class, $method, array $callTimeUserP
if (isset($iConfig[$thisIndex]['parameters'][$fqName])) throw \Exception('Implementation incomplete for fq names');

if (is_string($iConfig[$thisIndex]['parameters'][$name])
&& $type === false) {
$computedParams['value'][$fqName] = $iConfig[$thisIndex]['parameters'][$name];
} elseif (is_string($iConfig[$thisIndex]['parameters'][$name])
&& isset($aliases[$iConfig[$thisIndex]['parameters'][$name]])) {
$computedParams['required'][$fqName] = array(
$iConfig[$thisIndex]['parameters'][$name],
Expand Down

0 comments on commit 35967e7

Please sign in to comment.