This commit is contained in:
2021-02-22 19:26:39 +08:00
parent 43e44c9b7e
commit e3fedc42ec
+4 -7
View File
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace Snowflake\Di; namespace Snowflake\Di;
use Exception;
use ReflectionClass; use ReflectionClass;
use Snowflake\Abstracts\BaseObject; use Snowflake\Abstracts\BaseObject;
use ReflectionException; use ReflectionException;
@@ -125,6 +126,7 @@ class Container extends BaseObject
* @return object * @return object
* @throws NotFindClassException * @throws NotFindClassException
* @throws ReflectionException * @throws ReflectionException
* @throws Exception
*/ */
private function resolve($class, $constrict, $config): object private function resolve($class, $constrict, $config): object
{ {
@@ -133,7 +135,7 @@ class Container extends BaseObject
$dependencies[$index] = $param; $dependencies[$index] = $param;
} }
if (!$reflect->isInstantiable()) { if (!$reflect->isInstantiable()) {
throw new NotFindClassException($reflect->getName()); throw new Exception($reflect->getName() . ' con\'t instantiable');
} }
if (empty($config)) { if (empty($config)) {
return $reflect->newInstanceArgs($dependencies ?? []); return $reflect->newInstanceArgs($dependencies ?? []);
@@ -168,16 +170,11 @@ class Container extends BaseObject
}; };
$constructs = $reflection->getConstructor(); $constructs = $reflection->getConstructor();
if (!($constructs instanceof \ReflectionMethod)) { if (!($constructs instanceof \ReflectionMethod)) {
return [ return [$reflection, $this->_constructs[$class] = []];
$reflection, $this->_constructs[$class] = [
'class' => $class
]
];
} }
foreach ($constructs->getParameters() as $key => $param) { foreach ($constructs->getParameters() as $key => $param) {
$dependencies[] = $this->resolveDefaultValue($param); $dependencies[] = $this->resolveDefaultValue($param);
} }
$dependencies['class'] = $class;
$this->_constructs[$class] = $dependencies; $this->_constructs[$class] = $dependencies;
return [$reflection, $dependencies]; return [$reflection, $dependencies];
} }