コード例 #1
0
ファイル: Doppo.php プロジェクト: mmoreram/doppo
 /**
  * Get service instance
  *
  * @param string $serviceName Service Name
  *
  * @return mixed Service instance
  *
  * @throws DoppoNotCompiledException      Container not compiled yet
  * @throws DoppoServiceNotExistsException Service not found
  */
 public function get($serviceName)
 {
     if (!$this->compiled) {
         throw new DoppoNotCompiledException('Container should be compiled before being used');
     }
     /**
      * The service is found as an instance, so we can be ensured that the
      * value inside this position is a valid Service instance
      */
     if (isset($this->serviceInstances[$serviceName])) {
         return $this->serviceInstances[$serviceName];
     }
     /**
      * Otherwise, we must check if the service defined with its name has
      * been compiled
      */
     if (!$this->services->has($serviceName)) {
         throw new DoppoServiceNotExistsException(sprintf('Service "%s" not found', $serviceName));
     }
     return $this->serviceInstances[$serviceName] = $this->buildExistentService($serviceName);
 }