@param ServiceLocatorInterface $serviceLocator
@param array                   $config

@return null
559963
private function loadCache($serviceLocator, $config)
    {
        // check if the cache is configured
        if (!isset($config['view_helper']['cache']) || $config['view_helper']['cache'] === null) {
            return null;
        }

        // get the cache, if it's a string, search it among services
        $cache = $config['view_helper']['cache'];
        if (is_string($cache)) {
            $cache = $serviceLocator->get($cache);
        }

        // exception in case cache is not an Adapter that extend the AbstractAdapter of Zend\Cache\Storage
        if ($cache !== null && !($cache instanceof AbstractCacheAdapter)) {
            throw new InvalidArgumentException(
                'Invalid cache provided, you must pass a Cache Adapter that extend 
                Zend\Cache\Storage\Adapter\AbstractAdapter'
            );
        }

        return $cache;
    }
1257818
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        $locations = isset($config['locations'])? $config['locations'] : [];

        return new LocationTranslator($locations);
    }
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()
        );
    }
298953
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /**
         * @var array $config
         */
        $config = $serviceLocator->get('config');

        /**
         * @var \Zend\View\HelperPluginManager $serverUrl
         */
        $serverUrl = $serviceLocator->get('ViewHelperManager');

        /**
         * @var \Zend\Mvc\I18n\Translator $translator
         */
        $translator = $serviceLocator->get('translator');

        return new Index(
            $config,
            $serverUrl,
            $translator
        );
    }
237194
private function loadService($service, $serviceConfig)
    {
        list($app, $bundle, , $entity) = explode('.', $service);
        $resource = implode('.', array($app, $bundle, 'rest', $entity));

        $this->loadReadOnlyRoutes($service, $resource, $serviceConfig);
        if (!($serviceConfig[0] && array_key_exists('read-only', $serviceConfig[0]))) {
            $this->loadWriteRoutes($service, $resource, $serviceConfig);
        }
    }
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);
    }
249250
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config             = $serviceLocator->get('config');
        $sessionOptions     = $serviceLocator->get(SessionOptions::class);
        $sessionConfig      = $config['uthando_session_manager']['config_options'] ?? [];
        /** @var SessionConfig $sessionConfigClass */
        $sessionConfigClass = $sessionOptions->getSessionConfigClass();
        $sessionConfigClass = new $sessionConfigClass() ;

        $sessionConfigClass->setOptions($sessionConfig);

        return $sessionConfigClass;
    }
1250936
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $plugin = new CustomGroups();
        $config = $serviceLocator->getServiceLocator()->get('Config');
        if (isset($config['custom_groups'])) {
            $plugin->setConfig($config['custom_groups']);
        }
        return $plugin;
    }
172410
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        return new \Reliv\RcmConfig\Service\ConfigService(
            $config,
            $serviceLocator
        );
    }
141452
protected function processServices(array $config, Container $container, $alias = "")
    {
        if (!isset($config["services"])) {
            return;
        }
        if (!$this->isAssocArray($config["services"])) {
            throw new ConfigException("The 'services' configuration must be an associative array");
        }

        // scan for abstract definitions
        foreach ($config["services"] as $key => $definition) {

            if (!empty($definition["abstract"])) {
                $this->abstractDefinitions[self::SERVICE_CHAR . $this->referenceResolver->aliasThisKey($key, $alias)] = $definition;
                unset ($config["services"][$key]);
            }
        }

        // process services
        foreach ($config["services"] as $key => $definition) {
            // check if this is an alias of another service
            if (!$this->referenceResolver->keyIsAliased($key)) {
                $key = $this->referenceResolver->aliasThisKey($key, $alias);
            }

            if (!empty($definition["stub"])) {
                $container[$key] = function() use ($key, $definition) {
                    return $this->serviceFactory->createStub($key, $definition);
                };
                continue;
            }

            if (!empty($definition["aliasOf"])) {
                // override any existing definitions for this key
                $aliasedService = $definition["aliasOf"];
                $container[$key] = function() use ($container, $aliasedService, $alias) {
                    return $this->serviceFactory->aliasService($aliasedService, $alias);
                };
                $this->serviceAliases[$key] = true;
                continue;
            }


            // check for collisions
            if (isset($container[$key])) {
                if (isset($this->serviceAliases[$key])) {
                    // this service has been aliased by another service. We can ignore the definition.
                    continue;
                }
                throw new ConfigException(sprintf("Tried to define a service named '%s', but that name already exists in the container", $key));
            }

            if (!$this->isAssocArray($definition)) {
                throw new ConfigException("A service definition must be an associative array");
            }
            
            $maxIterations = 20;
            $currentIterations = 0;
            // check if this definition extends an abstract one
            while (!empty($definition["extends"]) && $currentIterations < $maxIterations) {
                $extends = self::SERVICE_CHAR . $this->referenceResolver->aliasThisKey(ltrim($definition["extends"], self::SERVICE_CHAR), $alias);
                if (!isset($this->abstractDefinitions[$extends])) {
                    throw new ConfigException(
                        sprintf(
                            "The service definition for '%s' extends '%s' but there is no abstract definition of that name",
                            $key,
                            $extends
                        )
                    );
                }

                // As calls gets wiped out by the replace_recursive, so we need to store it and merge it separately
                $calls = !empty($definition["calls"]) ? $definition["calls"] : [];
                if (!empty($this->abstractDefinitions[$extends]["calls"])) {
                    $calls = array_merge($calls, $this->abstractDefinitions[$extends]["calls"]);
                }
                unset($definition["extends"]);
                $definition = array_replace_recursive($this->abstractDefinitions[$extends], $definition);
                $definition["calls"] = $calls;
                $currentIterations++;
            }

            // get class
            if (empty($definition["class"])) {
                throw new ConfigException(sprintf("The service definition for %s does not have a class", $key));
            }
            // get class, resolving parameters if necessary
            try {
                $class = $this->referenceResolver->resolveParameter($definition["class"], $container, $alias);
            } catch (ReferenceException $e) {
                throw new ReferenceException("Error resolving class for '$key'. " . $e->getMessage());
            }

            if (!class_exists($class) && !interface_exists($class)) {
                throw new ConfigException(sprintf("The service class '%s' does not exist", $class));
            }

            // factories
            $factory = [];
            if (!empty($definition["factoryMethod"])) {
                $factory["method"] = $definition["factoryMethod"];
            }

            if (!empty($definition["factoryClass"])) {
                // check for malformed definitions ...
                if (empty($factory["method"])) {
                    throw new ConfigException(sprintf("A factory class was specified for '%s', but no method was set", $key));
                }
                //... and non-existent classes
                try {
                    $factoryClass = $this->referenceResolver->resolveParameter($definition["factoryClass"], $container, $alias);
                } catch (ReferenceException $e) {
                    throw new ReferenceException("Error parsing factory class for '$key'. " . $e->getMessage());
                }
                if (!class_exists($factoryClass)) {
                    throw new ConfigException(
                        sprintf("The factory class '%s', for '%s', does not exist", $factoryClass, $key)
                    );
                }
                // make sure the method actually exists on the class
                if (!method_exists($factoryClass, $factory["method"])) {
                    throw new ConfigException(
                        sprintf(
                            "Invalid factory definition. The method '%s' does not exist on the class '%s'",
                            $factory["method"],
                            $factoryClass
                        )
                    );
                }
                $factory["class"] = $factoryClass;
            }

            if (!empty($definition["factoryService"])) {
                // check for malformed definitions
                if (empty($factory["method"])) {
                    throw new ConfigException(sprintf("A factory service was specified for '%s', but no method was set", $key));
                }
                if (!empty($factory["class"])) {
                    throw new ConfigException(sprintf("The definition for '%s' cannot have both a factory class and a factory service", $key));
                }
                // add the service char if it does not exist
                if ($definition["factoryService"][0] != self::SERVICE_CHAR) {
                    $definition["factoryService"] = "@" . $definition["factoryService"];
                }
                // don't alias the service here, we'll do that later when we're about to use it
                $factory["service"] = $definition["factoryService"];
            }
            
            if (!empty($definition["private"])) {
                // if a service is private, create a random key for it and save the reference against the actual service key 
                $hashedName = md5($key . microtime(true));
                
                $this->referenceResolver->registerPrivateService($hashedName, $key);
                $key = $hashedName;
            }
            
            // arguments
            $arguments = !empty($definition["arguments"])? $definition["arguments"]: [];

            // calls / setters
            $calls = !empty($definition["calls"])? $definition["calls"]: [];
            foreach ($calls as $i => $call) {
                $calls[$i] = $this->processCall($call, $i, $key, $class);
            }

            // tags
            if (!empty($definition["tags"])) {
                if (!is_array($definition["tags"])) {
                    throw new ConfigException(sprintf("Error for service '%s': the tags definition was not in the expected array format", $key));
                }
                foreach ($definition["tags"] as $tag => $tagKey) {
                    // tags are either defined as ' - "#tagName" ' or ' "#tagName": "tagKey" ', so
                    // we have to detect the type of $tag and change the variables around if required
                    if (is_numeric($tag)) {
                        $tag = $tagKey;
                        $tagKey = null;
                    }
                    $tag = self::TAG_CHAR . $tag;
                    if (!isset($container[$tag])) {
                        $container[$tag] = function() {
                            return new TagCollection();
                        };
                    }
                    /** @var TagCollection $collection */
                    $collection = $container[$tag];
                    $collection->addService($key, $this->referenceResolver->resolveParameter($tagKey, $container, $alias));
                }
            }

            // add the definition to the container
            $container[$key] = function() use ($class, $factory, $arguments, $calls, $alias) {
                // parse arguments for injected parameters and services
                return $this->serviceFactory->createService($class, $factory, $arguments, $calls, $alias);
            };

        }
    }
1078924
public function createService( ServiceLocatorInterface $serviceLocator )
    {
        // Configure the definitions
        $config     = $serviceLocator->get( 'Configuration' );
        $srvConfig  = isset( $config['modules']['Grid\Core']['settings'] )
                    ? (array) $config['modules']['Grid\Core']['settings']
                    : array();
        return new Definitions( $srvConfig );
    }
288422
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $appConfig = $serviceLocator->get('config');
        $config = array_key_exists('log', $appConfig) ? $appConfig['log'] : array();
        $class = array_key_exists('class', $config) ? $config['class'] : 'Zend\Log\Logger';
        $logger = new $class($config);
        return $logger;
    }
1132648
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $mainCacheManager = new MainCacheManager();
        $logger = $serviceLocator->get('Logger');
        $cacheStorage = $serviceLocator->get('CacheService');
        $dateTimeFactory = $serviceLocator->get('DateTimeFactory');

        $config = $serviceLocator->get('Config');
        if (array_key_exists('cache_manager', $config)) {
            foreach ($config['cache_manager'] as $key => $cacheManagerConfig) {
                if (array_key_exists('service', $cacheManagerConfig)) {
                    /** @var AbstractCacheManager $cacheManager */
                    $cacheManager = $serviceLocator->get($cacheManagerConfig['service']);
                    if ($cacheManager instanceof AbstractCacheManager) {
                        $cacheManager->setLogger($logger);
                        $cacheManager->setCacheStorage($cacheStorage);
                        $cacheManager->setDateTimeFactory($dateTimeFactory);
                        $cacheManager->setKey($key);
                        $cacheManager->setDescription(array_key_exists('description', $cacheManagerConfig) ? $cacheManagerConfig['description'] : $key);
                        if ($cacheManager->getSuffixBuilder() == null) {
                            $cacheManager->setSuffixBuilder(new DefaultSuffixBuilder());
                        }
                        if ($cacheManager->getDataContextBuilder() == null) {
                            $cacheManager->setDataContextBuilder(new DefaultDataContextBuilder());
                        }
                        $mainCacheManager->addCacheManager($key, $cacheManager);
                    } else {
                        $logger->warn("Invalid configuration for cache manager $key : service should extends KmbCache\\Service\\AbstractCacheManager");
                    }
                } else {
                    $logger->warn("Invalid configuration for cache manager $key : missing service");
                }
            }
        }
        return $mainCacheManager;
    }
888912
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
    {
        /** @var ServiceManager $serviceLocator */
        $this->serviceManager = $serviceLocator;
        $this->serviceManager->setAllowOverride(true);
        $this->setPluginManager($serviceLocator);

        return $this;
    }
226494
public function createService(ServiceManager\ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('config');

        $config = (isset($config['yima_widgetator'])) ? $config['yima_widgetator'] : [];
        $config = (isset($config['widgets'])) ? $config['widgets'] : [];

        $widgetContainer = new RegionBoxContainer;
        $widgetContainer->addWidgets($config);

        return $widgetContainer;
    }
157696
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $context = new RequestContext();
        $context->fromRequest($serviceLocator->get('Request'));

        return $context;
    }
1294165
protected function activate($serviceName, $serviceConfig)
    {
        $activator = $this->activatorFactory->getActivator($serviceName, $serviceConfig);

        return $activator->createInstance($this, $serviceName, $serviceConfig);
    }