From 7c3754bbc26f18e5bfff066817bf04f691be79d0 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Sat, 8 Oct 2011 08:42:59 -0500 Subject: [PATCH 1/4] Zend\Di + Various other classes - Alter compiler to use reflection to build definitions - Altered various other broken signatures in other classes to make things compile right --- src/Definition/ArrayDefinition.php | 32 ++- src/Definition/CompilerDefinition.php | 333 +++++++++++++++----------- src/DefinitionList.php | 16 +- src/Di.php | 2 +- 4 files changed, 214 insertions(+), 169 deletions(-) diff --git a/src/Definition/ArrayDefinition.php b/src/Definition/ArrayDefinition.php index ff9b4846..23a2c574 100644 --- a/src/Definition/ArrayDefinition.php +++ b/src/Definition/ArrayDefinition.php @@ -28,11 +28,11 @@ public function getClassSupertypes($class) return array(); } - if (!isset($this->dataArray[$class]['superTypes'])) { + if (!isset($this->dataArray[$class]['supertypes'])) { return array(); } - return $this->dataArray[$class]['superTypes']; + return $this->dataArray[$class]['supertypes']; } public function getInstantiator($class) @@ -54,28 +54,24 @@ public function hasMethods($class) return array(); } - if (!isset($this->dataArray[$class]['injectionMethods'])) { + if (!isset($this->dataArray[$class]['methods'])) { return array(); } - return (count($this->dataArray[$class]['injectionMethods']) > 0); + return (count($this->dataArray[$class]['methods']) > 0); } public function hasMethod($class, $method) { if (!isset($this->dataArray[$class])) { - return array(); + return false; } - if (!isset($this->dataArray[$class]['injectionMethods'])) { - return array(); - } - - if (!isset($this->dataArray[$class]['injectionMethods'][$method])) { - return array(); + if (!isset($this->dataArray[$class]['methods'])) { + return false; } - return array_key_exists($method, $this->dataArray[$class]['injectionMethods']); + return array_key_exists($method, $this->dataArray[$class]['methods']); } public function getMethods($class) @@ -84,11 +80,11 @@ public function getMethods($class) return array(); } - if (!isset($this->dataArray[$class]['injectionMethods'])) { + if (!isset($this->dataArray[$class]['methods'])) { return array(); } - return array_keys($this->dataArray[$class]['injectionMethods']); + return $this->dataArray[$class]['methods']; } /** @@ -98,7 +94,7 @@ public function getMethods($class) */ public function hasMethodParameters($class, $method) { - return isset($this->dataArray[$class]['injectionMethods'][$method]); + return isset($this->dataArray[$class]['parameters'][$method]); } public function getMethodParameters($class, $method) @@ -107,15 +103,15 @@ public function getMethodParameters($class, $method) return array(); } - if (!isset($this->dataArray[$class]['injectionMethods'])) { + if (!isset($this->dataArray[$class]['parameters'])) { return array(); } - if (!isset($this->dataArray[$class]['injectionMethods'][$method])) { + if (!isset($this->dataArray[$class]['parameters'][$method])) { return array(); } - return $this->dataArray[$class]['injectionMethods'][$method]; + return $this->dataArray[$class]['parameters'][$method]; } public function toArray() diff --git a/src/Definition/CompilerDefinition.php b/src/Definition/CompilerDefinition.php index 8593d6f3..07f56c94 100644 --- a/src/Definition/CompilerDefinition.php +++ b/src/Definition/CompilerDefinition.php @@ -5,8 +5,12 @@ use Zend\Code\Scanner\DerivedClassScanner, Zend\Code\Scanner\AggregateDirectoryScanner, Zend\Code\Scanner\DirectoryScanner, - Zend\Code\Scanner\FileScanner, - Zend\Code\Scanner\MethodScanner, + + Zend\Di\Definition\Annotation, + Zend\Code\Annotation\AnnotationManager, + Zend\Code\Reflection, +// Zend\Code\Scanner\FileScanner, +// Zend\Code\Scanner\MethodScanner, Zend\Code\Annotation\AnnotationCollection; class CompilerDefinition implements Definition @@ -63,80 +67,76 @@ public function addCodeScannerFile(FileScanner $fileScanner) public function compile() { - $data = array(); - - $introspectionStrategy = $this->getIntrospectionStrategy(); - /* @var $classScanner \Zend\Code\Scanner\DerivedClassScanner */ foreach ($this->directoryScanner->getClasses() as $class) { $this->processClass($class); } - - //return new ArrayDefinition($data); } - public function processClass($className) + public function toArrayDefinition() { - $strategy = $this->introspectionStrategy; - $sClass = $this->directoryScanner->getClass($className, true, true); + return new ArrayDefinition( + $this->classes + ); + } - if (!$sClass->isInstantiable()) { - return; - } + protected function processClass($class) + { + $strategy = $this->introspectionStrategy; // localize for readability - // determine supertypes - $superTypes = array(); - if (($parentClasses = $sClass->getParentClasses()) !== null) { - $superTypes = array_merge($superTypes, $parentClasses); - } - if (($interfaces = $sClass->getInterfaces())) { - $superTypes = array_merge($superTypes, $interfaces); - } + /** @var $rClass \Zend\Code\Reflection\ClassReflection */ + $rClass = new Reflection\ClassReflection($class); + $className = $rClass->getName(); + $matches = null; // used for regex below - $className = $sClass->getName(); + // setup the key in classes $this->classes[$className] = array( - 'superTypes' => $superTypes, - 'instantiator' => null, - 'methods' => array(), - 'parameters' => array() + 'supertypes' => array(), + 'instantiator' => null, + 'methods' => array(), + 'parameters' => array() ); - $def = &$this->classes[$className]; + $def = &$this->classes[$className]; // localize for brevity + + // class annotations? + if ($strategy->getUseAnnotations() == true) { + $annotations = $rClass->getAnnotations($strategy->getAnnotationManager()); + + if (($annotations instanceof AnnotationCollection) + && $annotations->hasAnnotation('Zend\Di\Definition\Annotation\Instantiator')) { + // @todo Instnatiator support in annotations + } + } if ($def['instantiator'] == null) { - if ($sClass->isInstantiable()) { + if ($rClass->isInstantiable()) { $def['instantiator'] = '__construct'; } } - if ($sClass->hasMethod('__construct')) { - $mScanner = $sClass->getMethod('__construct'); - if ($mScanner->isPublic() && $mScanner->getNumberOfParameters() > 0) { - $def['methods']['__construct'] = true; - $this->processParams($def, $sClass, $mScanner); - } + if ($rClass->hasMethod('__construct')) { + $def['methods']['__construct'] = true; // required + $this->processParams($def, $rClass, $rClass->getMethod('__construct')); } - foreach ($sClass->getMethods(true) as $mScanner) { - if (!$mScanner->isPublic()) { - continue; - } - $methodName = $mScanner->getName(); + foreach ($rClass->getMethods(Reflection\MethodReflection::IS_PUBLIC) as $rMethod) { + + $methodName = $rMethod->getName(); - if ($mScanner->getName() === '__construct') { + if ($rMethod->getName() === '__construct') { continue; } if ($strategy->getUseAnnotations() == true) { - - $annotations = $mScanner->getAnnotations($strategy->getAnnotationManager()); + $annotations = $rMethod->getAnnotations($strategy->getAnnotationManager()); if (($annotations instanceof AnnotationCollection) && $annotations->hasAnnotation('Zend\Di\Definition\Annotation\Inject')) { $def['methods'][$methodName] = true; - $this->processParams($def, $sClass, $mScanner); + $this->processParams($def, $rClass, $rMethod); continue; } } @@ -148,61 +148,72 @@ public function processClass($className) preg_match($methodInjectorPattern, $methodName, $matches); if ($matches) { $def['methods'][$methodName] = false; // check ot see if this is required? - $this->processParams($def, $sClass, $mScanner); + $this->processParams($def, $rClass, $rMethod); continue 2; } } + + // method + // by annotation + // by setter pattern, + // by interface + } $interfaceInjectorPatterns = $this->introspectionStrategy->getInterfaceInjectionInclusionPatterns(); // matches the interface injection pattern - /** @var $sInterface \Zend\Code\Scanner\ClassScanner */ - foreach ($sClass->getInterfaces(true) as $sInterface) { + /** @var $rIface \ReflectionClass */ + foreach ($rClass->getInterfaces() as $rIface) { foreach ($interfaceInjectorPatterns as $interfaceInjectorPattern) { - preg_match($interfaceInjectorPattern, $sInterface->getName(), $matches); + preg_match($interfaceInjectorPattern, $rIface->getName(), $matches); if ($matches) { - foreach ($sInterface->getMethods(true) as $sMethod) { - if ($sMethod->getName() === '__construct') { // ctor not allowed in ifaces + foreach ($rIface->getMethods() as $rMethod) { + if ($rMethod->getName() === '__construct') { // ctor not allowed in ifaces continue; } - $def['methods'][$sMethod->getName()] = true; - $this->processParams($def, $sClass, $sMethod); + $def['methods'][$rMethod->getName()] = true; + $this->processParams($def, $rClass, $rMethod); } continue 2; } } } + + //var_dump($this->classes); } - protected function processParams(&$def, DerivedClassScanner $sClass, MethodScanner $sMethod) + protected function processParams(&$def, Reflection\ClassReflection $rClass, Reflection\MethodReflection $rMethod) { - if (count($sMethod->getParameters()) === 0) { + if (count($rMethod->getParameters()) === 0) { return; } - $methodName = $sMethod->getName(); + $methodName = $rMethod->getName(); + + // @todo annotations here for alternate names? $def['parameters'][$methodName] = array(); - foreach ($sMethod->getParameters(true) as $position => $p) { + foreach ($rMethod->getParameters() as $p) { - /** @var $p \Zend\Code\Scanner\ParameterScanner */ + /** @var $p \ReflectionParameter */ $actualParamName = $p->getName(); - $paramName = $this->createDistinctParameterName($actualParamName, $sClass->getName()); + $paramName = $this->createDistinctParameterName($actualParamName, $rClass->getName()); - $fqName = $sClass->getName() . '::' . $sMethod->getName() . ':' . $position; + $fqName = $rClass->getName() . '::' . $rMethod->getName() . ':' . $p->getPosition(); $def['parameters'][$methodName][$fqName] = array(); // set the class name, if it exists $def['parameters'][$methodName][$fqName][] = $actualParamName; - $def['parameters'][$methodName][$fqName][] = ($p->getClass() !== null) ? $p->getClass() : null; + $def['parameters'][$methodName][$fqName][] = ($p->getClass() !== null) ? $p->getClass()->getName() : null; $def['parameters'][$methodName][$fqName][] = !$p->isOptional(); } + } protected function createDistinctParameterName($paramName, $class) @@ -229,116 +240,158 @@ protected function createDistinctParameterName($paramName, $class) return $paramName . (string) $alt; } -// public function compileScannerInstantiator(DerivedClassScanner $scannerClass) +// public function processClass($className) // { -// if ($scannerClass->hasMethod('__construct')) { -// $construct = $scannerClass->getMethod('__construct'); -// if ($construct->isPublic()) { -// return '__construct'; -// } +// $strategy = $this->introspectionStrategy; +// $sClass = $this->directoryScanner->getClass($className, true, true); +// +// if (!$sClass->isInstantiable()) { +// return; // } // -// return null; -// } +// // determine supertypes +// $superTypes = array(); +// if (($parentClasses = $sClass->getParentClasses()) !== null) { +// $superTypes = array_merge($superTypes, $parentClasses); +// } +// if (($interfaces = $sClass->getInterfaces())) { +// $superTypes = array_merge($superTypes, $interfaces); +// } // -// public function compileScannerInjectionMethods(DerivedClassScanner $c) -// { -// // return value -// $methods = array(); +// $className = $sClass->getName(); +// $this->classes[$className] = array( +// 'supertypes' => $superTypes, +// 'instantiator' => null, +// 'methods' => array(), +// 'parameters' => array() +// ); // -// // name of top level class (only, not derived) -// $className = $c->getName(); +// $def = &$this->classes[$className]; // +// if ($def['instantiator'] == null) { +// if ($sClass->isInstantiable()) { +// $def['instantiator'] = '__construct'; +// } +// } // +// if ($sClass->hasMethod('__construct')) { +// $mScanner = $sClass->getMethod('__construct'); +// if ($mScanner->isPublic() && $mScanner->getNumberOfParameters() > 0) { +// $def['methods']['__construct'] = true; +// $this->processParams($def, $sClass, $mScanner); +// } +// } // +// foreach ($sClass->getMethods(true) as $mScanner) { +// if (!$mScanner->isPublic()) { +// continue; +// } // -// /* @var $m ReflectionMethod */ -// foreach ($c->getMethods(true) as $m) { -// //$declaringClassName = $m->getDeclaringClass()->getName(); +// $methodName = $mScanner->getName(); // -// if (!$m->isPublic() || $m->getNumberOfParameters() == 0) { +// if ($mScanner->getName() === '__construct') { // continue; // } // -// $methods[$m->getName()] = $this->compileScannerInjectionMethodParmeters($m); +// if ($strategy->getUseAnnotations() == true) { +// +// $annotations = $mScanner->getAnnotations($strategy->getAnnotationManager()); +// +// if (($annotations instanceof AnnotationCollection) +// && $annotations->hasAnnotation('Zend\Di\Definition\Annotation\Inject')) { +// +// $def['methods'][$methodName] = true; +// $this->processParams($def, $sClass, $mScanner); +// continue; +// } +// } +// +// $methodPatterns = $this->introspectionStrategy->getMethodNameInclusionPatterns(); +// +// // matches a method injection pattern? +// foreach ($methodPatterns as $methodInjectorPattern) { +// preg_match($methodInjectorPattern, $methodName, $matches); +// if ($matches) { +// $def['methods'][$methodName] = false; // check ot see if this is required? +// $this->processParams($def, $sClass, $mScanner); +// continue 2; +// } +// } +// // } // +// $interfaceInjectorPatterns = $this->introspectionStrategy->getInterfaceInjectionInclusionPatterns(); // -//// if ($iRules['enabled']) { -//// foreach ($c->getInterfaces(true) as $i) { -//// -//// // explicitly in the include interfaces -//// if ($iRules['includedInterfaces'] && !in_array($i->getName(), $iRules['includedInterfaces'])) { -//// continue; -//// } -//// // explicity NOT in excluded classes -//// if ($iRules['excludedInterfaces'] && in_array($i->getName(), $iRules['excludedInterfaces'])) { -//// continue; -//// } -//// // if there is a pattern, and it does not match, continue -//// if ($iRules['pattern'] && !preg_match('#' . preg_quote($iRules['pattern'], '#') . '#', $i->getName())) { -//// continue; -//// } -//// foreach ($i->getMethods() as $m) { -//// $methods[$m->getName()] = $this->compileScannerInjectionMethodParmeters( -//// $m, -//// IntrospectionStrategy::TYPE_INTERFACE -//// ); -//// } -//// } -//// } -// -// -// return $methods; +// // matches the interface injection pattern +// /** @var $sInterface \Zend\Code\Scanner\ClassScanner */ +// foreach ($sClass->getInterfaces(true) as $sInterface) { +// foreach ($interfaceInjectorPatterns as $interfaceInjectorPattern) { +// preg_match($interfaceInjectorPattern, $sInterface->getName(), $matches); +// if ($matches) { +// foreach ($sInterface->getMethods(true) as $sMethod) { +// if ($sMethod->getName() === '__construct') { // ctor not allowed in ifaces +// continue; +// } +// $def['methods'][$sMethod->getName()] = true; +// $this->processParams($def, $sClass, $sMethod); +// } +// continue 2; +// } +// } +// } // // } // -// /** -// * Return the parameters for a method -// * -// * 3 item array: -// * #1 - Class name, string if it exists, else null -// * #2 - Optional?, boolean -// * #3 - Instantiable, boolean if class exists, otherwise null -// * -// * @return array -// */ -// public function compileScannerInjectionMethodParmeters(MethodScanner $methodScanner) +// protected function processParams(&$def, DerivedClassScanner $sClass, MethodScanner $sMethod) // { -// $params = array(); -// $parameterScanners = $methodScanner->getParameters(true); +// if (count($sMethod->getParameters()) === 0) { +// return; +// } // -// /* @var $p Zend\Code\Scanner\ParameterScanner */ -// foreach ($parameterScanners as $p) { +// $methodName = $sMethod->getName(); // -// $paramName = $p->getName(); +// $def['parameters'][$methodName] = array(); // -// // create array for this parameter -// $params[$paramName] = array(); +// foreach ($sMethod->getParameters(true) as $position => $p) { // -// // get name, and class if it exists -// $pcName = $p->getClass(); -// if ($this->directoryScanner->hasClass($pcName)) { -// $pc = $this->directoryScanner->getClass($pcName); -// } +// /** @var $p \Zend\Code\Scanner\ParameterScanner */ +// $actualParamName = $p->getName(); // -// if ($pcName) { -// // @todo Should we throw an exception if its an unknown type? -// $params[$paramName][] = $pcName; -// } else { -// $params[$paramName][] = null; -// } +// $paramName = $this->createDistinctParameterName($actualParamName, $sClass->getName()); +// +// $fqName = $sClass->getName() . '::' . $sMethod->getName() . ':' . $position; // -// $params[$paramName][] = $p->isOptional(); +// $def['parameters'][$methodName][$fqName] = array(); // -// if (isset($pc)) { -// $params[$paramName][] = ($pc->isInstantiable()) ? true : false; -// } else { -// $params[$paramName][] = null; +// // set the class name, if it exists +// $def['parameters'][$methodName][$fqName][] = $actualParamName; +// $def['parameters'][$methodName][$fqName][] = ($p->getClass() !== null) ? $p->getClass() : null; +// $def['parameters'][$methodName][$fqName][] = !$p->isOptional(); +// } +// } +// +// protected function createDistinctParameterName($paramName, $class) +// { +// $currentParams = array(); +// if ($this->classes[$class]['parameters'] === array()) { +// return $paramName; +// } +// foreach ($this->classes as $cdata) { +// foreach ($cdata['parameters'] as $mdata) { +// $currentParams = array_merge($currentParams, array_keys($mdata)); // } +// } // +// if (!in_array($paramName, $currentParams)) { +// return $paramName; // } -// return $params; +// +// $alt = 2; +// while (in_array($paramName . (string) $alt, $currentParams)) { +// $alt++; +// } +// +// return $paramName . (string) $alt; // } /** diff --git a/src/DefinitionList.php b/src/DefinitionList.php index 97875a58..069b36e1 100644 --- a/src/DefinitionList.php +++ b/src/DefinitionList.php @@ -13,16 +13,16 @@ public function __construct($definitions) $definitions = array($definitions); } foreach ($definitions as $definition) { - $this->unshift($definition); + $this->push($definition); } } - public function addDefinition(Definition\Definition $definition, $addToTopOfList = true) + public function addDefinition(Definition\Definition $definition, $addToBackOfList = true) { - if ($addToTopOfList) { - $this->unshift($definition); - } else { + if ($addToBackOfList) { $this->push($definition); + } else { + $this->unshift($definition); } } @@ -175,12 +175,8 @@ public function hasMethodParameters($class, $method) public function getMethodParameters($class, $method) { /** @var $definition Definition\Definition */ - $methodParameters = array(); foreach ($this as $definition) { - if ($definition->hasClass($class) && $definition->hasMethod($class, $method)) { - if ($definition instanceof Definition\PartialMarker && $definition->hasMethodParameters($class, $method) === false) { - continue; - } + if ($definition->hasClass($class) && $definition->hasMethod($class, $method) && $definition->hasMethodParameters($class, $method)) { return $definition->getMethodParameters($class, $method); } } diff --git a/src/Di.php b/src/Di.php index 54b56bee..909dcf99 100644 --- a/src/Di.php +++ b/src/Di.php @@ -325,7 +325,7 @@ protected function handleInjectionMethodForObject($object, $method, $params, $al { // @todo make sure to resolve the supertypes for both the object & definition $callParameters = $this->resolveMethodParameters(get_class($object), $method, $params, false, $alias, $methodIsRequired); - if ($callParameters === false) { + if ($callParameters == false) { return; } if ($callParameters !== array_fill(0, count($callParameters), null)) { From d08e5f2db68f3680ea2b65d7d0498b05a59fdee9 Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 10 Oct 2011 10:06:15 -0500 Subject: [PATCH 2/4] Zend\Di - Fixed issue with RuntimeDefinition's hasMethodParameters() - Fixed issue in ClassDefinition with constructors being not-required --- src/Configuration.php | 16 ++++++++-------- src/Definition/ClassDefinition.php | 7 +++++-- src/Definition/RuntimeDefinition.php | 2 +- src/Display/Console.php | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Configuration.php b/src/Configuration.php index b7dc1710..ddadeac5 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -45,8 +45,12 @@ public function configureDefinition(Di $di, $definition) { foreach ($definition as $definitionType => $definitionData) { switch ($definitionType) { + case 'compiler': + // @todo + case 'runtime': + // @todo case 'class': - foreach ($definitionData as $className => $classDefinitionData) { + foreach ($definitionData as $className => $classData) { $classDefinitions = $di->definitions()->getDefinitionsByType('Zend\Di\Definition\ClassDefinition'); foreach ($classDefinitions as $classDefinition) { if (!$classDefinition->hasClass($className)) { @@ -55,9 +59,9 @@ public function configureDefinition(Di $di, $definition) } if (!isset($classDefinition)) { $classDefinition = new Definition\ClassDefinition($className); - $di->definitions()->addDefinition($classDefinition); + $di->definitions()->addDefinition($classDefinition, false); } - foreach ($classDefinitionData as $classDefKey => $classDefData) { + foreach ($classData as $classDefKey => $classDefData) { switch ($classDefKey) { case 'instantiator': $classDefinition->setInstantiator($classDefData); @@ -89,11 +93,6 @@ public function configureDefinition(Di $di, $definition) } } } - break; - case 'compiler': - // @todo - case 'runtime': - // @todo } } @@ -141,5 +140,6 @@ public function configureInstance(Di $di, $instanceData) } } + } diff --git a/src/Definition/ClassDefinition.php b/src/Definition/ClassDefinition.php index c229d0cd..ce3f5a06 100644 --- a/src/Definition/ClassDefinition.php +++ b/src/Definition/ClassDefinition.php @@ -27,15 +27,18 @@ public function setSupertypes(array $supertypes) $this->supertypes = $supertypes; } - public function addMethod($method, $isRequired = false) + public function addMethod($method, $isRequired = null) { + if ($isRequired === null) { + $isRequired = ($method === '__construct') ? true : false; + } $this->methods[$method] = (bool) $isRequired; } public function addMethodParameter($method, $parameterName, array $parameterInfo) { if (!array_key_exists($method, $this->methods)) { - $this->methods[$method] = false; + $this->methods[$method] = ($method === '__construct') ? true : false; } if (!array_key_exists($method, $this->methodParameters)) { diff --git a/src/Definition/RuntimeDefinition.php b/src/Definition/RuntimeDefinition.php index b9640406..428d3800 100644 --- a/src/Definition/RuntimeDefinition.php +++ b/src/Definition/RuntimeDefinition.php @@ -173,7 +173,7 @@ public function hasMethodParameters($class, $method) if (!isset($this->classes[$class])) { return false; } - return (array_key_exists($method, $this->classes[$class])); + return (array_key_exists($method, $this->classes[$class]['parameters'])); } /** diff --git a/src/Display/Console.php b/src/Display/Console.php index f3f243ad..ed43bfcf 100644 --- a/src/Display/Console.php +++ b/src/Display/Console.php @@ -58,8 +58,8 @@ public function render() if ($this->runtimeClasses) echo ' Runtime classes:' . PHP_EOL; - $unKnownRuntimeClasses = array_diff($this->runtimeClasses, $knownClasses); - foreach ($unKnownRuntimeClasses as $runtimeClass) { + $unknownRuntimeClasses = array_diff($this->runtimeClasses, $knownClasses); + foreach ($unknownRuntimeClasses as $runtimeClass) { //$definition = $this->di->definitions()->getDefinitionForClass($runtimeClass); $this->renderClassDefinition($runtimeClass); } From a71e9b074741cc3e4b9b9778b3de0e7b7f6b9c2e Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 10 Oct 2011 10:12:26 -0500 Subject: [PATCH 3/4] Zend\Di - Default now Annotations Off in RuntimeDefinition --- src/Definition/IntrospectionStrategy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Definition/IntrospectionStrategy.php b/src/Definition/IntrospectionStrategy.php index aab1bffc..ce6bcd36 100644 --- a/src/Definition/IntrospectionStrategy.php +++ b/src/Definition/IntrospectionStrategy.php @@ -9,7 +9,7 @@ class IntrospectionStrategy /** * @var bool */ - protected $useAnnotations = true; + protected $useAnnotations = false; /** * @var string[] From 35967e7ffecd3b43ea803203a514ac76918c106b Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 10 Oct 2011 11:56:05 -0500 Subject: [PATCH 4/4] Zend\Di - 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 --- src/Di.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Di.php b/src/Di.php index 909dcf99..53259c0b 100644 --- a/src/Di.php +++ b/src/Di.php @@ -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); @@ -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; @@ -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],