This commit is contained in:
xl
2023-11-16 23:01:58 +08:00
parent ae11af9a7b
commit d3cc7e7afe
+7 -8
View File
@@ -86,7 +86,9 @@ class Container implements ContainerInterface
if ($id === ContainerInterface::class) { if ($id === ContainerInterface::class) {
return $this; return $this;
} }
if (!isset($this->_singletons[$id])) { if (isset($this->_singletons[$id])) {
return $this->_singletons[$id];
}
if (isset($this->_interfaces[$id])) { if (isset($this->_interfaces[$id])) {
$id = $this->_interfaces[$id]; $id = $this->_interfaces[$id];
} }
@@ -94,7 +96,6 @@ class Container implements ContainerInterface
if (!$this->_singletons[$id]) { if (!$this->_singletons[$id]) {
throw new Exception('Class that cannot be instantiated。'); throw new Exception('Class that cannot be instantiated。');
} }
}
return $this->_singletons[$id]; return $this->_singletons[$id];
} }
@@ -106,11 +107,11 @@ class Container implements ContainerInterface
*/ */
public function parse(string $id): object public function parse(string $id): object
{ {
if (isset($this->_singletons[$id])) { if (!isset($this->_singletons[$id])) {
return $this->_singletons[$id];
}
return $this->make($id); return $this->make($id);
} }
return $this->_singletons[$id];
}
/** /**
@@ -195,7 +196,6 @@ class Container implements ContainerInterface
$attribute->newInstance()->dispatch($object); $attribute->newInstance()->dispatch($object);
} }
} }
$this->resolveProperties($reflect, $object); $this->resolveProperties($reflect, $object);
if (method_exists($object, 'init') && $object::class !== 'Symfony\Component\Console\Application') { if (method_exists($object, 'init') && $object::class !== 'Symfony\Component\Console\Application') {
call_user_func([$object, 'init']); call_user_func([$object, 'init']);
@@ -217,8 +217,7 @@ class Container implements ContainerInterface
foreach ($properties as $property) { foreach ($properties as $property) {
$propertyAttributes = $property->getAttributes(); $propertyAttributes = $property->getAttributes();
foreach ($propertyAttributes as $attribute) { foreach ($propertyAttributes as $attribute) {
if (!class_exists($attribute->getName()) || if (!class_exists($attribute->getName()) || in_array(ValidatorInterface::class, class_implements($attribute->getName()))) {
in_array(ValidatorInterface::class, class_implements($attribute->getName()))) {
continue; continue;
} }
if ($class instanceof InjectProxyInterface) { if ($class instanceof InjectProxyInterface) {