From 1c674c2a0f708d79487a4a05644526c954c1b146 Mon Sep 17 00:00:00 2001 From: inhere Date: Thu, 9 Jan 2020 23:25:57 +0800 Subject: [PATCH] update some for bean --- src/bean/src/Container.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bean/src/Container.php b/src/bean/src/Container.php index d80c8c535..9b4836dfd 100644 --- a/src/bean/src/Container.php +++ b/src/bean/src/Container.php @@ -390,24 +390,25 @@ public function getSession(string $name, string $sid) * * When class name will return all of instance for class name * - * @return object + * @return object|mixed * @throws InvalidArgumentException */ public function get($id) { - // It is singleton + // It is singleton bean if (isset($this->singletonPool[$id])) { return $this->singletonPool[$id]; } - // Prototype by clone + // Prototype bean by clone if (isset($this->prototypePool[$id])) { return clone $this->prototypePool[$id]; } - // Alias name + // Has alias name $aliasId = $this->aliases[$id] ?? ''; - if ($aliasId) { + // Fix: $aliasId !== $id deny loop get + if ($aliasId && $aliasId !== $id) { return $this->get($aliasId); } @@ -432,7 +433,7 @@ public function get($id) /* @var ObjectDefinition $objectDefinition */ $objectDefinition = $this->objectDefinitions[$id]; - // Prototype + // Prototype bean return $this->safeNewBean($objectDefinition->getName()); } @@ -920,8 +921,8 @@ private function newBean(string $beanName, string $id = '') // Inject properties values $this->newProperty($reflectObject, $reflectionClass, $propertyInjects, $id); - // Alias - if (!empty($alias)) { + // Alias name + if ($alias && $alias !== $beanName) { $this->aliases[$alias] = $beanName; }