has( $id ) ) { throw InvalidService::from_service_id( $id ); } $service = $this->offsetGet( $id ); // Instantiate actual services if they were stored lazily. if ( $service instanceof LazilyInstantiatedService ) { $service = $service->instantiate(); $this->put( $id, $service ); } return $service; } /** * Check whether the container can return a service for the given * identifier. * * @param string $id Identifier of the service to look for. * * @return bool */ public function has( $id ) { return $this->offsetExists( $id ); } /** * Put a service into the container for later retrieval. * * @param string $id Identifier of the service to put into the * container. * @param Service $service Service to put into the container. */ public function put( $id, Service $service ) { $this->offsetSet( $id, $service ); } }