eee
This commit is contained in:
+22
-3
@@ -91,7 +91,8 @@ class Container implements ContainerInterface
|
||||
*/
|
||||
public function get(string $id): object
|
||||
{
|
||||
if (isset($this->_singletons[$id])) return $this->_singletons[$id];
|
||||
if (isset($this->_singletons[$id]))
|
||||
return $this->_singletons[$id];
|
||||
if (isset($this->_interfaces[$id])) {
|
||||
return $this->_singletons[$id] = $this->make($this->_interfaces[$id]);
|
||||
} else {
|
||||
@@ -166,7 +167,7 @@ class Container implements ContainerInterface
|
||||
}
|
||||
|
||||
if (($handler = $reflect->getConstructor()) !== null) {
|
||||
$construct = $this->getMethodParams($handler);
|
||||
$construct = $this->mergeParams($this->getMethodParams($handler), $construct);
|
||||
}
|
||||
$newInstance = $reflect->newInstanceArgs($construct);
|
||||
|
||||
@@ -174,6 +175,23 @@ class Container implements ContainerInterface
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $default
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
protected function mergeParams(array $default, array $params): array
|
||||
{
|
||||
if (empty($params)) {
|
||||
return $default;
|
||||
}
|
||||
foreach ($params as $key => $value) {
|
||||
$default[$key] = $value;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $reflect
|
||||
* @param array $construct
|
||||
@@ -304,7 +322,8 @@ class Container implements ContainerInterface
|
||||
{
|
||||
$className = $parameters->getDeclaringClass()->getName();
|
||||
$methodName = $parameters->getName();
|
||||
if (!isset($this->_parameters[$className])) $this->_parameters[$className] = [];
|
||||
if (!isset($this->_parameters[$className]))
|
||||
$this->_parameters[$className] = [];
|
||||
if (!isset($this->_parameters[$className][$methodName])) {
|
||||
return $this->_parameters[$className][$methodName] = $this->resolveMethodParams($parameters);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user