This commit is contained in:
2021-02-22 18:53:55 +08:00
parent 30f8f2843a
commit e0112e1587
+23 -11
View File
@@ -174,23 +174,35 @@ class Container extends BaseObject
return [$reflection, []];
}
foreach ($constructs->getParameters() as $key => $param) {
if ($param->isOptional()) {
$dependencies[] = $param->getDefaultValue();
} else {
match ($param->getType()) {
'mixed' => $dependencies[] = $param->getDefaultValue(),
'string' => $dependencies[] = '',
'int' => $dependencies[] = 0,
'bool' => $dependencies[] = false,
default => $dependencies[] = Snowflake::createObject($param->getType())
};
}
$dependencies[] = $this->resolveDefaultValue($param);
}
$this->_constructs[$class] = $dependencies;
return [$reflection, $dependencies];
}
/**
* @param $param
* @return false|int|string|null
* @throws NotFindClassException
* @throws ReflectionException
*/
private function resolveDefaultValue($param,): bool|int|string|null
{
if ($param->isOptional()) {
return $param->getDefaultValue();
}
return match ($param->getType()) {
'mixed' => $param->getDefaultValue(),
'string' => '',
'int' => 0,
'bool' => false,
'NULL' => NULL,
default => Snowflake::createObject($param->getType())
};
}
/**
* @param $class
* @return ReflectionClass|null