This commit is contained in:
2021-04-25 16:16:13 +08:00
parent d331ce4349
commit 05cd3dde9e
3 changed files with 54 additions and 18 deletions
+10 -6
View File
@@ -10,11 +10,10 @@ declare(strict_types=1);
namespace Snowflake\Di;
use ReflectionException;
use Snowflake\Exception\ComponentException;
use Snowflake\Abstracts\Component;
use Exception;
use Snowflake\Exception\NotFindClassException;
use JetBrains\PhpStorm\Pure;
use Snowflake\Abstracts\Component;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
/**
@@ -30,6 +29,9 @@ class Service extends Component
private array $_definition = [];
private array $_ids = [];
protected array $_alias = [];
/**
@@ -49,6 +51,8 @@ class Service extends Component
}
throw new ComponentException("Unknown component ID: $id");
}
$this->_ids[] = $id;
if (isset($this->_definition[$id])) {
$config = $this->_definition[$id];
if (is_object($config)) {
@@ -102,9 +106,9 @@ class Service extends Component
* @param $id
* @return bool
*/
public function has($id): bool
#[Pure] public function has($id): bool
{
return isset($this->_definition[$id]) || isset($this->_components[$id]) || isset($this->_alias[$id]);
return in_array($id, $this->_ids);
}
/**