create and initialize a service instance

@param string $serviceId
@param array $constructorArguments
@throws ApplicationException
@return ServiceInterface
433060
private function initializeService($serviceId, array $constructorArguments) {
		
		if(!isset($this->config->services[$serviceId])) {
			throw new ApplicationException(sprintf("Service '%s' not configured.", $serviceId));
		}

		$configData = $this->config->services[$serviceId];

		// get class name

		$class	= $configData['class'];

		// create instance and pass additional parameters to constructor

		try {
			$service = new $class(...$constructorArguments);
		}
		catch(\Exception $e) {
			throw new ApplicationException(sprintf("Instancing of service '%s' failed. Error: %s", $serviceId, $e->getMessage()));
		}

		// check whether instance implements ServiceInterface  

		if(!$service instanceof ServiceInterface) {
			throw new ApplicationException(sprintf("Service '%s' (class %s) does not implement the ServiceInterface.", $serviceId, $class));
		}

		// set parameters
		
		$service->setParameters($configData['parameters']);
		
		return $service;

	}
423421
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');
        $config = $config[self::CONFIG_KEY];

        if (is_null($config))
            throw new \RuntimeException(_('Config could not be found!'));

        FacebookSession::setDefaultApplication($config['appId'], $config['secret']);

        try {
            $helper = new FacebookCanvasLoginHelper();
            $session = $helper->getSession();

            $this->setAccessToken($session->getAccessToken());
        } catch (FacebookRequestException $ex) {
            StaticLogger::save($ex->__toString(), 'facebook.log');
        } catch (\Exception $ex) {
            StaticLogger::save($ex->__toString(), 'facebook.log');
        }

        return $session;
    }
1216068
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $this->getConfig($serviceLocator);

        if (!isset($config['cache'])) {
            return null;
        }

        $config = $config['cache'];
        /* @var $cache CacheProvider|Cache */
        $cache = null;
        $cacheFactory = $this->getCacheFactory($config);
        $cache = $cacheFactory->newInstance($config);

        if (isset($config['namespace'])) {
            $cache->setNamespace(trim($config['namespace']));
        }

        return $cache;
    }
334679
private function activate($container, ArrayResolver $serviceConfig, $serviceName)
    {
        $this->typeInitializer->initialize($container, $serviceConfig);

        $activator = $this->activatorFactory->getActivator($serviceName, $serviceConfig);

        return $activator->createInstance($container, $serviceConfig, $serviceName);
    }
1192164
public function createInstance(Container $container, ArrayResolver $serviceConfig, $serviceName)
    {
        $activator = $this->getActivator($serviceName, $serviceConfig->resolveStrict('builder'));

        return $activator->createInstance($container, $serviceConfig, $serviceName);
    }
1268765
public function createInstance($serviceProviderClass, array $serviceClasses)
    {
        if (!class_exists($serviceProviderClass, false)) {
            if (!$this->serviceProviderLoader->canLoad($serviceProviderClass)) {
                $dependencyGraph = $this->dependencyResolver->execute($serviceClasses);
                $source = $this->serviceProviderGenerator->generate($serviceProviderClass, $dependencyGraph);
                $this->serviceProviderLoader->write($serviceProviderClass, $source);
            }

            $this->serviceProviderLoader->load($serviceProviderClass);
        }

        return new $serviceProviderClass();
    }
1062760
private function assertCorrectService(ContainerBuilder $container, $serviceId)
    {
        $definition = $container->findDefinition($serviceId);
        $reflection = new ReflectionClass($definition->getClass());
        if (!$reflection->implementsInterface(WorkerRunnerInterface::class)) {
            throw new InvalidArgumentException('Runner service has to implement WorkerRunnerInterface.');
        }
    }
128212
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        if (!is_array($config)) {
            throw new \RuntimeException("Expected application config to be an array. Got " . gettype($config));
        }

        if (! isset($config['system_data_dir'])) {
            throw new \RuntimeException("Missing system_data_dir key in application configuration. Please add the key to your config and point it to the data directory of your application!");
        }

        return DataLocation::fromPath($serviceLocator->get('config')['system_data_dir']);
    }
47663
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsPluginManager */
        $moduleOptionsPluginManager = $serviceLocator->get(ModuleOptionsPluginManagerInterface::class);
        /** @var ModuleOptionsInterface $moduleOptions */
        $moduleOptions = $moduleOptionsPluginManager->get(ModuleOptionsInterface::class);

        $managerRegistryOptions = $moduleOptions->getManagerRegistry();


        $buildListConnectionsResult = $this->getEventManager()->trigger(static::EVENT_BUILD_LIST_CONNECTIONS, $this);
        $listConnectionsResult = [];
        foreach ($buildListConnectionsResult as $item) {
            if (is_array($item)) {
                $listConnectionsResult = ArrayUtils::merge($listConnectionsResult, $item);
            }
        }
        $listConnectionsResult = ArrayUtils::merge($listConnectionsResult, $managerRegistryOptions->getConnections());


        $buildListObjectManagersResult = $this->getEventManager()->trigger(static::EVENT_BUILD_LIST_OBJECT_MANAGERS, $this);
        $listObjectManagersResult = [];
        foreach ($buildListObjectManagersResult as $item) {
            if (is_array($item)) {
                $listObjectManagersResult = ArrayUtils::merge($listObjectManagersResult, $item);
            }
        }
        $listObjectManagersResult = ArrayUtils::merge($listObjectManagersResult, $managerRegistryOptions->getObjectManagers());

        return new ManagerRegistry(
            ManagerRegistry::NAME,
            $listConnectionsResult,
            $listObjectManagersResult,
            $managerRegistryOptions->getDefaultConnection(),
            $managerRegistryOptions->getDefaultManager(),
            $managerRegistryOptions->getProxyInterfaceName()
        );
    }
1223596
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var array $config */
        $config = $serviceLocator->get('Config')['eye4web_abac']['assertion_manager'];

        $pluginManager = new AssertionPluginManager(new Config($config));
        $pluginManager->setServiceLocator($serviceLocator);

        return $pluginManager;
    }
579548
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;
    }
1230998
private function _registerService($className, $constructorType) {
        if (!class_exists($className)) {
            $errorMsg = sprintf(self::ERROR_CLASS_NOT_FOUND, $className);
            throw new ulfberhtException($errorMsg);
        } elseif ($this->has($className)) {
            $errorMsg = sprintf(self::ERROR_CLASS_ALREADY_DEFINED, $className);
            throw new ulfberhtException($errorMsg);
        }

        $this->_services[$className] = new serviceWrapper(
            $className,
            $constructorType
        );
        $this->_serviceDependencyGraph->addResource($className);
        $this->_serviceDependencyGraph->addDependencies(
            $className,
            $this->_services[$className]->dependencies
        );
    }
1230531
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $appServiceLocator = $serviceLocator instanceof AbstractPluginManager ? $serviceLocator->getServiceLocator() : $serviceLocator;

        /** @var array $appConfig */
        $appConfig = $appServiceLocator->get('config');
        $moduleConfig = array_key_exists(Module::CONFIG_KEY, $appConfig) ? $appConfig[Module::CONFIG_KEY] : [];

        return new ModuleOptions($moduleConfig);
    }
531577
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        // handle configuration
        $config = $serviceLocator->get('Config');
        $viewConfig = isset($config['view']) ? $config['view'] : array();

        $className = isset($viewConfig['classname']) ? $viewConfig['classname'] : 'HumusMvc\View\View';
        $view = new $className($viewConfig);
        if (!$view instanceof View) {
            throw new InvalidArgumentException('View object must extend HumusMvc\View\View');
        }
        $view->setHelperPluginManager($serviceLocator->get('ViewHelperManager'));

        if (isset($viewConfig['doctype'])) {
            $view->doctype()->setDoctype(strtoupper($viewConfig['doctype']));
            if (isset($viewConfig['charset']) && $view->doctype()->isHtml5()) {
                $view->headMeta()->setCharset($viewConfig['charset']);
            }
        }

        if (isset($viewConfig['contentType'])) {
            $view->headMeta()->appendHttpEquiv('Content-Type', $viewConfig['contentType']);
        }

        if (isset($viewConfig['assign']) && is_array($viewConfig['assign'])) {
            $view->assign($viewConfig['assign']);
        }

        if (isset($viewConfig['useViewRenderer']) && true === (bool) $viewConfig['useViewRenderer']) {
            $viewRenderer = ControllerActionHelper::getStaticHelper('viewRenderer');
            $viewRenderer->setView($view);
        }
        return $view;
    }
159016
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var PluginManager $serviceLocator */
        /** @var ServiceManager $serviceManager */
        $serviceManager = $serviceLocator->getServiceLocator();

        $writeRevisionLog = new WriteRevisionLog();

        /** @var AuthenticationService $authenticationService */
        $authenticationService = $serviceManager->get('Zend\Authentication\AuthenticationService');
        $writeRevisionLog->setAuthenticationService($authenticationService);

        /** @var RevisionRepositoryInterface $revisionRepository */
        $revisionRepository = $serviceManager->get('RevisionRepository');
        $writeRevisionLog->setRevisionRepository($revisionRepository);

        /** @var DateTimeFactoryInterface $dateTimeFactory */
        $dateTimeFactory = $serviceManager->get('DateTimeFactory');
        $writeRevisionLog->setDateTimeFactory($dateTimeFactory);

        return $writeRevisionLog;
    }
1319332
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $service = new Environment();

        /** @var EnvironmentRepositoryInterface $environmentRepository */
        $environmentRepository = $serviceLocator->get('EnvironmentRepository');
        $service->setEnvironmentRepository($environmentRepository);

        return $service;
    }
1120614
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsManager */
        $moduleOptionsManager = $serviceLocator->get(ModuleOptionsPluginManagerInterface::class);

        /** @var DoctrineObjectManagerInterface $doctrineObjectManager */
        $doctrineObjectManager = $serviceLocator->get(DoctrineObjectManagerInterface::class);

        return new ObjectManagerAutoDetector($moduleOptionsManager, $doctrineObjectManager);
    }