_components[$name]); $this->_definition[$name] = $define; if (is_object($define) || $define instanceof \Closure) { $this->_components[$name] = $define; } } /** * @throws \Exception */ public function get(string $name, $throwException = true) { if (isset($this->_components[$name])) { return $this->_components[$name]; } if (isset($this->_definition[$name])) { $definition = $this->_definition[$name]; if (is_object($definition) && !$definition instanceof \Closure) { return $this->_components[$name] = $definition; } return $this->_components[$name] = Kiri::createObject($definition); } else if ($throwException) { throw new \Exception("Unknown component ID: $name"); } return null; } /** * @param array $components */ public function setComponents(array $components) { foreach ($components as $name => $component) { $this->set($name, $component); } } /** * @param $id * @return bool */ public function has($id): bool { return isset($this->_components[$id]) || isset($this->_definition[$id]); } /** * @param $id */ public function remove($id): void { unset($this->_components[$id], $this->_definition[$id]); } }