has($id)) { return $this->resolve($id); } throw new NotFoundException(sprintf('The entry with the id "%s" could not be found')); } /** * Register a shared entry in the container * * @param string $abstract Identifier of the entry to set * @param mixed $instance Entry */ public function instance($abstract, $instance) { $this->instances[$abstract] = $instance; } /** * Returns true if the container can return an entry for the given identifier * Returns false otherwise * * `has($id)` returning true does not mean that `get($id)` will not throw an exception * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface` * * @param string $id Identifier of the entry to look for * * @return bool */ public function has($id) { return isset($this->instances[$id]); } /** * Get the globally available instance of the container * * @return Container */ public static function getInstance() { if (is_null(static::$instance)) { static::$instance = new static; } return static::$instance; } /** * Set the globally available instance of the container * * @param Container $container */ public static function setInstance(Container $container) { static::$instance = $container; } /** * Resolve the requested object * * @param string $abstract * @return mixed */ protected function resolve($abstract) { return $this->instances[$abstract]; } }