modify
This commit is contained in:
@@ -71,20 +71,20 @@ class Container extends BaseObject
|
|||||||
{
|
{
|
||||||
if (isset($this->_singletons[$class])) {
|
if (isset($this->_singletons[$class])) {
|
||||||
return $this->_singletons[$class];
|
return $this->_singletons[$class];
|
||||||
} else if (!isset($this->_constructs[$class])) {
|
}
|
||||||
|
if (!isset($this->_constructs[$class])) {
|
||||||
return $this->resolve($class, $constrict, $config);
|
return $this->resolve($class, $constrict, $config);
|
||||||
}
|
}
|
||||||
$definition = $this->_constructs[$class];
|
$definition = $this->_constructs[$class];
|
||||||
if (is_callable($definition, TRUE)) {
|
if (is_callable($definition, TRUE)) {
|
||||||
return call_user_func($definition, $this, $constrict, $config);
|
return call_user_func($definition, $this, $constrict, $config);
|
||||||
} else if (is_array($definition)) {
|
} else if (is_array($definition)) {
|
||||||
$object = $this->resolveDefinition($definition, $class, $config, $constrict);
|
return $this->resolveDefinition($definition, $class, $config, $constrict);
|
||||||
} else if (is_object($definition)) {
|
} else if (is_object($definition)) {
|
||||||
return $this->_singletons[$class] = $definition;
|
return $this->_singletons[$class] = $definition;
|
||||||
} else {
|
} else {
|
||||||
throw new NotFindClassException($class);
|
throw new NotFindClassException($class);
|
||||||
}
|
}
|
||||||
return $this->_singletons[$class] = $object;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,7 +112,7 @@ class Container extends BaseObject
|
|||||||
} else {
|
} else {
|
||||||
$object = $this->get($class, $definition, $config);
|
$object = $this->get($class, $definition, $config);
|
||||||
}
|
}
|
||||||
return $object;
|
return $this->_singletons[$class] = $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +127,7 @@ class Container extends BaseObject
|
|||||||
private function resolve($class, $constrict, $config): object
|
private function resolve($class, $constrict, $config): object
|
||||||
{
|
{
|
||||||
/** @var ReflectionClass $reflect */
|
/** @var ReflectionClass $reflect */
|
||||||
list($reflect, $dependencies) = $this->resolveDependencies($class);
|
[$reflect, $dependencies] = $this->resolveDependencies($class);
|
||||||
foreach ($constrict as $index => $param) {
|
foreach ($constrict as $index => $param) {
|
||||||
$dependencies[$index] = $param;
|
$dependencies[$index] = $param;
|
||||||
}
|
}
|
||||||
@@ -171,7 +171,7 @@ class Container extends BaseObject
|
|||||||
}
|
}
|
||||||
$constructs = $reflection->getConstructor();
|
$constructs = $reflection->getConstructor();
|
||||||
if ($constructs === null || count($constructs->getParameters()) < 1) {
|
if ($constructs === null || count($constructs->getParameters()) < 1) {
|
||||||
return [$reflection, $this->_constructs[$class] = ['class' => $class]];
|
return [$reflection, $this->_constructs[$class] = []];
|
||||||
}
|
}
|
||||||
$dependencies = [];
|
$dependencies = [];
|
||||||
foreach ($constructs->getParameters() as $key => $param) {
|
foreach ($constructs->getParameters() as $key => $param) {
|
||||||
@@ -182,7 +182,6 @@ class Container extends BaseObject
|
|||||||
$dependencies[] = $c === NULL ? NULL : $c->getName();
|
$dependencies[] = $c === NULL ? NULL : $c->getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var_dump($dependencies);
|
|
||||||
$this->_constructs[$class] = $dependencies;
|
$this->_constructs[$class] = $dependencies;
|
||||||
return [$reflection, $dependencies];
|
return [$reflection, $dependencies];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,9 @@ class Snowflake
|
|||||||
if (!isset($className['class']) || empty($className['class'])) {
|
if (!isset($className['class']) || empty($className['class'])) {
|
||||||
throw new Exception('Object configuration must be an array containing a "class" element.');
|
throw new Exception('Object configuration must be an array containing a "class" element.');
|
||||||
}
|
}
|
||||||
return static::$container->get($className['class'], $construct, $className);
|
$class = $className['class'];
|
||||||
|
unset($className['class']);
|
||||||
|
return static::$container->get($class, $construct, $className);
|
||||||
} else if (is_callable($className, TRUE)) {
|
} else if (is_callable($className, TRUE)) {
|
||||||
return call_user_func($className, $construct);
|
return call_user_func($className, $construct);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user