protected function buildObject(array &$possibleConstructorArgumentValues, $objectType)
{
$constructorArguments = [];
$className = $this->objectManager->getClassNameByObjectName($objectType);
$constructorSignature = $this->getConstructorArgumentsForClass($className);
if (count($constructorSignature)) {
foreach ($constructorSignature as $constructorArgumentName => $constructorArgumentReflection) {
if (array_key_exists($constructorArgumentName, $possibleConstructorArgumentValues)) {
$constructorArguments[] = $possibleConstructorArgumentValues[$constructorArgumentName];
unset($possibleConstructorArgumentValues[$constructorArgumentName]);
} elseif ($constructorArgumentReflection['optional'] === true) {
$constructorArguments[] = $constructorArgumentReflection['defaultValue'];
} elseif ($this->objectManager->isRegistered($constructorArgumentReflection['type']) && $this->objectManager->getScope($constructorArgumentReflection['type']) === Configuration::SCOPE_SINGLETON) {
$constructorArguments[] = $this->objectManager->get($constructorArgumentReflection['type']);
} else {
throw new InvalidTargetException('Missing constructor argument "' . $constructorArgumentName . '" for object of type "' . $objectType . '".', 1268734872);
}
}
$classReflection = new \ReflectionClass($className);
return $classReflection->newInstanceArgs($constructorArguments);
} else {
return new $className();
}
}