/** * @param \ReflectionParameter $parameter * @param $nesting * @return mixed|Value */ public function instantiateParameter($parameter, $nesting, $graph = null) { $hint = null; try { $hint = $parameter->getClass(); } catch (\ReflectionException $e) { } try { if ($hint) { return $this->create($hint->getName(), $nesting, $graph); } elseif (isset($this->variables[$parameter->getName()])) { $preference = $this->variables[$parameter->getName()]->preference; if ($preference instanceof Lifecycle) { $context = empty($preference->class) ? $this : $this->determineContext($preference->class, $graph); return $preference->instantiate($context, $nesting, $graph); } elseif ($preference instanceof ConfigValue) { return $this->instantiateParameter($preference, $nesting, $graph)->get($preference->name); } elseif (!is_string($preference)) { return $preference; } return $this->create($preference, $nesting, $graph); } } catch (MissingDependency $e) { if ($parameter->getClass()) { $e->prependMessage("While creating {$parameter->getClass()->getName()}: "); } else { $e->prependMessage("While creating {$parameter->getName()}: "); } throw $e; } return $this->parent->instantiateParameter($parameter, $nesting, $graph); }