_services, true)) { $this->_services[$name] = $service; } return $this; } /** * * get a service from the container * * @param string $name * @param array $params * @return mixed * @throws \RuntimeException */ public function get($name, array $params = array()) { if (!isset($this->_services[$name])) { throw new \RuntimeException(sprintf("The service '%s' has not been registered with the container.", $name)); } $service = $this->_services[$name]; return !$service instanceof \Closure ? $service : call_user_func_array($service, $params); } /** * * check if a service has been saved in the container * * @param string $name * @return bool */ public function has($name) { return isset($this->_services[$name]); } /** * * remove a service from the container * * @param string $name * @return \Cube\Di\Container */ public function remove($name) { if (isset($this->_services[$name])) { unset($this->_services[$name]); } return $this; } /** * * clear the container */ public function clear() { $this->_services = array(); } }