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

Commit

Permalink
Show file tree
Hide file tree
Showing 99 changed files with 266 additions and 137 deletions.
11 changes: 3 additions & 8 deletions src/Config.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down Expand Up @@ -59,11 +59,9 @@ public function configure(Di $di)
if (isset($this->data['definition'])) {
$this->configureDefinition($di, $this->data['definition']);
}

if (isset($this->data['instance'])) {
$this->configureInstance($di, $this->data['instance']);
}

}

/**
Expand All @@ -90,8 +88,8 @@ public function configureDefinition(Di $di, $definition)
$definitions[] = $definition;
}
}
$definitions = new DefinitionList($definitions);
$di->setDefinitionList($definitions);
$definitionList = new DefinitionList($definitions);
$di->setDefinitionList($definitionList);
} elseif (isset($definitionData['use_annotations']) && $definitionData['use_annotations']) {
/* @var $runtimeDefinition Definition\RuntimeDefinition */
$runtimeDefinition = $di
Expand Down Expand Up @@ -146,9 +144,7 @@ public function configureDefinition(Di $di, $definition)
}
}
}

}

}

/**
Expand Down Expand Up @@ -200,7 +196,6 @@ public function configureInstance(Di $di, $instanceData)
}
}
}

}

}
2 changes: 1 addition & 1 deletion src/Definition/Annotation/Inject.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Annotation/Instantiator.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/ArrayDefinition.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Builder/InjectionMethod.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/Builder/PhpClass.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/BuilderDefinition.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Definition/ClassDefinition.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down Expand Up @@ -187,9 +187,9 @@ public function hasMethod($class, $method)

if (is_array($this->methods)) {
return array_key_exists($method, $this->methods);
} else {
return null;
}

return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/CompilerDefinition.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down Expand Up @@ -299,7 +299,7 @@ protected function processParams(&$def, Reflection\ClassReflection $rClass, Refl
$def['parameters'][$methodName][$fqName][] = $actualParamName;
$def['parameters'][$methodName][$fqName][] = ($p->getClass() !== null) ? $p->getClass()->getName() : null;
$def['parameters'][$methodName][$fqName][] = !($optional =$p->isOptional());
$def['parameters'][$methodName][$fqName][] = $optional ? $p->getDefaultValue() : null;
$def['parameters'][$methodName][$fqName][] = $optional && $p->isDefaultValueAvailable() ? $p->getDefaultValue() : null;
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/DefinitionInterface.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/IntrospectionStrategy.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/PartialMarker.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/RuntimeDefinition.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down Expand Up @@ -346,7 +346,7 @@ protected function processParams(&$def, Reflection\ClassReflection $rClass, Refl
// set the class name, if it exists
$def['parameters'][$methodName][$fqName][] = $actualParamName;
$def['parameters'][$methodName][$fqName][] = ($p->getClass() !== null) ? $p->getClass()->getName() : null;
$def['parameters'][$methodName][$fqName][] = !($optional =$p->isOptional());
$def['parameters'][$methodName][$fqName][] = !($optional = $p->isOptional() && $p->isDefaultValueAvailable());
$def['parameters'][$methodName][$fqName][] = $optional ? $p->getDefaultValue() : null;
}

Expand Down
34 changes: 18 additions & 16 deletions src/DefinitionList.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down Expand Up @@ -146,9 +146,11 @@ public function getClassSupertypes($class)
foreach ($this as $definition) {
if ($definition->hasClass($class)) {
$supertypes = array_merge($supertypes, $definition->getClassSupertypes($class));
if (!$definition instanceof Definition\PartialMarker) {
return $supertypes;
if ($definition instanceof Definition\PartialMarker) {
continue;
}

return $supertypes;
}
}
return $supertypes;
Expand All @@ -165,9 +167,9 @@ public function getInstantiator($class)
$value = $definition->getInstantiator($class);
if ($value === null && $definition instanceof Definition\PartialMarker) {
continue;
} else {
return $value;
}

return $value;
}
}

Expand All @@ -184,9 +186,9 @@ public function hasMethods($class)
if ($definition->hasClass($class)) {
if ($definition->hasMethods($class) === false && $definition instanceof Definition\PartialMarker) {
continue;
} else {
return $definition->hasMethods($class);
}

return $definition->hasMethods($class);
}
}

Expand All @@ -198,14 +200,14 @@ public function hasMethods($class)
*/
public function hasMethod($class, $method)
{
if (!$this->hasMethods($class)) {
return false;
}

/** @var $definition Definition\DefinitionInterface */
foreach ($this as $definition) {
if ($definition->hasClass($class)) {
if ($definition->hasMethods($class) === false && $definition instanceof Definition\PartialMarker) {
continue;
} else {
return $definition->hasMethods($class);
}
if ($definition->hasMethod($class, $method)) {
return true;
}
}

Expand All @@ -221,11 +223,11 @@ public function getMethods($class)
$methods = array();
foreach ($this as $definition) {
if ($definition->hasClass($class)) {
if ($definition instanceof Definition\PartialMarker) {
$methods = array_merge($definition->getMethods($class), $methods);
} else {
if (!$definition instanceof Definition\PartialMarker) {
return array_merge($definition->getMethods($class), $methods);
}

$methods = array_merge($definition->getMethods($class), $methods);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjectionInterface.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
44 changes: 34 additions & 10 deletions src/Di.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down Expand Up @@ -119,6 +119,30 @@ public function instanceManager()
return $this->instanceManager;
}

/**
* @param $name
* @param array $params
* @param string $method
* @return array
*/
protected function getCallParameters($name, array $params, $method = "__construct")
{
$im = $this->instanceManager;
$class = $im->hasAlias($name) ? $im->getClassFromAlias($name) : $name;
if ($this->definitions->hasClass($class)) {
$callParameters = array();
if ($this->definitions->hasMethod($class, $method)) {
foreach ($this->definitions->getMethodParameters($class, $method) as $param) {
if (isset($params[$param[0]])) {
$callParameters[$param[0]] = $params[$param[0]];
}
}
}
return $callParameters;
}
return $params;
}

/**
* Lazy-load a class
*
Expand All @@ -136,21 +160,21 @@ public function get($name, array $params = array())

$im = $this->instanceManager;

if ($params) {
$fastHash = $im->hasSharedInstanceWithParameters($name, $params, true);
$callParameters = $this->getCallParameters($name, $params);
if ($callParameters) {
$fastHash = $im->hasSharedInstanceWithParameters($name, $callParameters, true);
if ($fastHash) {
array_pop($this->instanceContext);

return $im->getSharedInstanceWithParameters(null, array(), $fastHash);
}
} else {
if ($im->hasSharedInstance($name, $params)) {
if ($im->hasSharedInstance($name, $callParameters)) {
array_pop($this->instanceContext);

return $im->getSharedInstance($name, $params);
return $im->getSharedInstance($name, $callParameters);
}
}
$config = $im->getConfig($name);

$config = $im->getConfig($name);
$instance = $this->newInstance($name, $params, $config['shared']);
array_pop($this->instanceContext);

Expand Down Expand Up @@ -226,8 +250,8 @@ public function newInstance($name, array $params = array(), $isShared = true)
}

if ($isShared) {
if ($params) {
$this->instanceManager->addSharedInstanceWithParameters($instance, $name, $params);
if ($callParameters = $this->getCallParameters($name, $params)) {
$this->instanceManager->addSharedInstanceWithParameters($instance, $name, $callParameters);
} else {
$this->instanceManager->addSharedInstance($instance, $name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Display/Console.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/CircularDependencyException.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ClassNotFoundException.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ExceptionInterface.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Di
*/
Expand Down

0 comments on commit 5725284

Please sign in to comment.