compile() public method

That new ServiceConfig will be used to instantiate a service later in the process of creating a service instance.
public compile ( ) : ServiceConfig
return ServiceConfig
Example #1
0
 /**
  * Instantiate service using given service name
  *
  * @param string $serviceName
  *
  * @return object
  * @throws ServiceManagerException
  */
 private function instantiateService($serviceName)
 {
     // Make sure service is registered
     if (!$this->registeredServices->keyExists($serviceName)) {
         throw new ServiceManagerException(ServiceManagerException::SERVICE_DEFINITION_NOT_FOUND, [$serviceName]);
     }
     // Get service config from registered services array
     $config = $this->registeredServices->key($serviceName);
     // Check circular referencing
     if ($this->references->keyExists($serviceName)) {
         throw new ServiceManagerException(ServiceManagerException::SERVICE_CIRCULAR_REFERENCE, [$serviceName]);
     }
     // Set service name reference for circular referencing checks
     $this->references->key($serviceName, $serviceName);
     // Compile ConfigObject into ServiceConfig
     $configCompiler = new ConfigCompiler($serviceName, $config, $this->parameters);
     $this->compiledConfig->key($serviceName, $configCompiler->compile());
     /**
      * @var $config ServiceConfig
      */
     $config = $this->compiledConfig->key($serviceName);
     // Construct service container and get service instance
     $serviceCreator = new ServiceCreator($config);
     $service = $serviceCreator->getService();
     // Unset service name reference
     $this->references->removeKey($serviceName);
     // Store instance if this service has a CONTAINER scope
     if ($config->getScope() == ServiceScope::CONTAINER) {
         $this->instantiatedServices->key($serviceName, $service);
     }
     return $service;
 }