This commit is contained in:
2021-04-25 12:05:34 +08:00
parent 355c02490b
commit afdf5f7b47
+19 -3
View File
@@ -143,20 +143,36 @@ class Container extends BaseObject
throw new NotFindClassException($reflect->getName());
}
unset($dependencies['class']);
if (empty($config) || !is_array($config)) {
$object = $reflect->newInstanceArgs($dependencies);
$object = $this->newInstance($reflect, $dependencies);
} else if (!empty($dependencies) && $reflect->implementsInterface('Snowflake\Abstracts\Configure')) {
$dependencies[count($dependencies) - 1] = $config;
$object = $reflect->newInstanceArgs($dependencies);
$object = $this->newInstance($reflect, $dependencies);
} else {
if (!empty($config)) $this->_param[$class] = $config;
$object = $this->onAfterInit($reflect->newInstanceArgs($dependencies), $config);
$object = $this->onAfterInit($this->newInstance($reflect, $dependencies), $config);
}
return $this->propertyInject($reflect, $object);
}
/**
* @param $reflect
* @param $dependencies
* @return mixed
*/
private function newInstance($reflect, $dependencies)
{
if (!empty($dependencies)) {
return $reflect->newInstanceArgs($dependencies);
}
return $reflect->newInstance();
}
/**
* @param ReflectionClass $reflect
* @param $object