Process shard configurations if they exist.

@param array $serviceConnArguments
@param array $resolvedConnConfig
18696
private function processShardConfigurationsIfExist(array &$serviceConnArguments, array $resolvedConnConfig)
    {
        if (array_key_exists('shards', $serviceConnArguments)) {
            foreach ($serviceConnArguments['shards'] as $shardName => &$shardConfig) {
                $this->replaceConnectionArguments($shardConfig, $resolvedConnConfig['shards'][$shardName]);
            }
        }
    }
624837
public static function generalServiceManager(Iterable $serviceConfig = NULL, $selfRefNames= []) {
        if(!static::$serviceManager) {
            if(is_null($serviceConfig))
                throw new ServiceException(sprintf("First call of %s must pass a service configuration", __METHOD__), 13);

            /** @var ServiceManager $man */
            $man = static::$serviceManager = new static($serviceConfig);
            $man->selfReferenceNames = array_merge($man->selfReferenceNames, $selfRefNames);

            if($n = self::getGlobalVariableName())
                $GLOBALS[$n] = $man;
        }
        return static::$serviceManager;
    }
44486
private function manageInheritance()
    {
        $config = $this->serviceConfig;
        if ($config->keyExists('Parent')) {
            $parentServiceName = $this->str($config->key('Parent'))->trimLeft('@')->val();
            $parentConfig = ServiceManager::getInstance()->getServiceConfig($parentServiceName)->toArray(true);
            if (!$parentConfig->keyExists('Abstract')) {
                throw new ServiceManagerException(ServiceManagerException::SERVICE_IS_NOT_ABSTRACT,
                                                  [$config->key('Parent')]
                );
            }
            $config = $this->extendConfig($config, $parentConfig);
        }

        // Check if it's a potentially valid service definition
        if (!$config->keyExists('Class') && !$config->keyExists('Factory')) {
            throw new ServiceManagerException(ServiceManagerException::SERVICE_CLASS_KEY_NOT_FOUND,
                                              [$this->serviceName]
            );
        }

        $this->serviceConfig = $config;
    }
1260477
private function findName($service, ServiceConfig $serviceConfig)
    {
        if ($serviceConfig->has(ServiceConfig::NAME)) {
            return $serviceConfig->get(ServiceConfig::NAME);
        } else {
            foreach ((array) $this->possibleNames as $possibleName) {
                if (isset($service[$possibleName])) {
                    return $possibleName;
                }
            }
        }

        return null;
    }
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);
        }
    }
1187737
public static function configure(ServicesConfig $config)
    {
        $config->validate();

        $gateway = null;
        if (isset($config->merchantId) && !empty($config->merchantId)) {
            $gateway = new RealexConnector();
            $gateway->merchantId = $config->merchantId;
            $gateway->sharedSecret = $config->sharedSecret;
            $gateway->accountId = $config->accountId;
            $gateway->channel = $config->channel;
            $gateway->rebatePassword = $config->rebatePassword;
            $gateway->refundPassword = $config->refundPassword;
            $gateway->timeout = $config->timeout;
            $gateway->serviceUrl = $config->serviceUrl;
            $gateway->hostedPaymentConfig = $config->hostedPaymentConfig;
            $gateway->curlOptions = $config->curlOptions;
            static::$instance = new static($gateway, $gateway);
        } else {
            $gateway = new PorticoConnector();
            $gateway->siteId = $config->siteId;
            $gateway->licenseId = $config->licenseId;
            $gateway->deviceId = $config->deviceId;
            $gateway->username = $config->username;
            $gateway->password = $config->password;
            $gateway->secretApiKey = $config->secretApiKey;
            $gateway->developerId = $config->developerId;
            $gateway->versionNumber = $config->versionNumber;
            $gateway->timeout = $config->timeout;
            $gateway->serviceUrl = $config->serviceUrl . '/Hps.Exchange.PosGateway/PosGatewayService.asmx';
            $gateway->curlOptions = $config->curlOptions;

            $payplanEndPoint = (strpos(strtolower($config->serviceUrl), 'cert.') > 0) ?
                                '/Portico.PayPlan.v2/':
                                '/PayPlan.v2/';
            
            $recurring = new PayPlanConnector();
            $recurring->siteId = $config->siteId;
            $recurring->licenseId = $config->licenseId;
            $recurring->deviceId = $config->deviceId;
            $recurring->username = $config->username;
            $recurring->password = $config->password;
            $recurring->secretApiKey = $config->secretApiKey;
            $recurring->developerId = $config->developerId;
            $recurring->versionNumber = $config->versionNumber;
            $recurring->timeout = $config->timeout;
            $recurring->serviceUrl = $config->serviceUrl . $payplanEndPoint;
            $recurring->curlOptions = $config->curlOptions;

            static::$instance = new static($gateway, $recurring);
        }
    }
713816
protected function resolveServices()
    {
        // Do real export services when the server is launching.
        $this->app['events']->listen(ServerLaunching::class, function () {
            $services = Arr::get($this->config, 'services');

            if (! is_array($services) || empty($services)) {
                return;
            }

            foreach ($services as $config) {
                $this->resolveService($config);
            }
        });
    }
338969
public function resolveBranchConfig(array $branchConfig)
    {
        $resolver = new OptionsResolver();
        $resolver
            ->setDefaults(array(
                'path' => null,
                'commands' => array(),
                'options' => array(),
            ))
            ->setAllowedTypes('commands', 'array')
            ->setAllowedTypes('options', 'array')
            ->setAllowedTypes('path', array('string', 'null'))
        ;

        try {
            return $resolver->resolve($branchConfig);
        } catch (InvalidArgumentException $exception) {
            $this->logger->critical('Couldn\'t resolve branch config: '.$exception->getTraceAsString());
            throw $exception;
        }
    }
373381
private function createResolvers(array $config, ContainerInterface $container)
    {
        $resolvers = [];

        foreach ($config as $resolver) {
            if ($resolver instanceof Resolver\ResolverInterface) {
                $resolvers[] = $resolver;
                continue;
            }

            if (! is_string($resolver)) {
                continue;
            }

            if ($container->has($resolver)) {
                $resolvers[] = $container->get($resolver);
                continue;
            }

            if (class_exists($resolver)) {
                $resolvers[] = new $resolver();
                continue;
            }
        }

        return $resolvers;
    }
1216145
private function initializeServiceDefinitions(array $mergedConfig, ContainerBuilder $container)
    {
        $initManager = $container->get(ServiceNames::SERVICE_DEFINITION_INITIALIZATION_MANAGER);
        $initManager->initializeServiceDefinitions($mergedConfig, $container);
    }
255005
public function loadReadOnlyRoutes($service, $resource, $serviceConfig)
    {

        $actionOptions = ActionUtils::getRouteOptions($service, $serviceConfig);
        $this->routes->add($resource . '.options', $actionOptions);

        $actionOptionsNoSlash = ActionUtils::getRouteOptions($service, $serviceConfig);
        $actionOptionsNoSlash->setPath(substr($actionOptionsNoSlash->getPath(), 0, -1));
        $this->routes->add($resource . '.optionsNoSlash', $actionOptionsNoSlash);

        $actionHead = ActionUtils::getRouteHead($service, $serviceConfig);
        $this->routes->add($resource . '.head', $actionHead);

        $actionHead = ActionUtils::getRouteHead($service, $serviceConfig, [], true);
        $this->routes->add($resource . '.idHead', $actionHead);

        $actionGet = ActionUtils::getRouteGet($service, $serviceConfig);
        $this->routes->add($resource . '.get', $actionGet);

        $actionAll = ActionUtils::getRouteAll($service, $serviceConfig);
        $this->routes->add($resource . '.all', $actionAll);

        $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'collection');
        $this->routes->add($resource . '.canonicalSchema', $actionOptions);

        $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'collection', true);
        $this->routes->add($resource . '.canonicalSchemaOptions', $actionOptions);

        $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig);
        $this->routes->add($resource . '.canonicalIdSchema', $actionOptions);

        $actionOptions = ActionUtils::getCanonicalSchemaRoute($service, $serviceConfig, 'item', true);
        $this->routes->add($resource . '.canonicalIdSchemaOptions', $actionOptions);

        $actionOptions = ActionUtils::getRouteOptions($service, $serviceConfig, [], true);
        $this->routes->add($resource . '.idOptions', $actionOptions);
    }
591535
public function configureOptionsResolver(OptionsResolver $resolver)
    {
        parent::configureOptionsResolver($resolver);
        $resolver->setRequired([
            self::OPTION_NOSQL_DRIVER,
            self::OPTION_COLLECTION_PREFIX,
            self::OPTION_COLLECTION_NAME,
            self::OPTION_METHOD
        ]);

        $resolver->setAllowedTypes(self::OPTION_COLLECTION_NAME, ['string']);
        $resolver->setAllowedTypes(self::OPTION_COLLECTION_PREFIX, ['string']);
        $resolver->setAllowedTypes(self::OPTION_NOSQL_DRIVER, ['string']);
        $resolver->setAllowedTypes(self::OPTION_METHOD, ['string']);
    }
720654
public function registerTypesAndConfig(ConfigurationService $config)
    {
        $services = $this->container->getServiceIds();
        foreach ($services as $service) {
            if (substr($service, 0, 14) == "midnight_type.") {
                if (!$config->has("type", $service)) {
                    $this->container->get($service)->initialize();
                    $config->set("type", $service, $this->container->get($service)->getCacheLevel());
                }
            } elseif (substr($service, 0, 16) == "midnight_config.") {
                $serv = $this->container->get($service);
                $c = $serv->getConfiguration();
                foreach ($c as $key => $data) {
                    if (!$config->has("configuration", $key)) {
                        $config->set("configuration", $key, $data["default"]);
                    }
                }
                $toolbar = $serv->addToolbar($this->container->get("router"));
                foreach($toolbar as $name => $path){
                    if (!$config->has("toolbar", $name)) {
                        $config->set("toolbar", $name, $path);
                    }
                }
                $templates = $serv->registerTemplate();
                foreach($templates as $name => $template){
                    if (!$config->has("template", $template)) {
                        $config->set("template", $name, $template);
                    }
                }

            }
        }
    }
1284715
public function resolveService(array $config)
    {
        $middleware = $this->gatherInvokerMiddleware(array_merge(
            $this->config['middleware'] ?? [],
            $config['middleware'] ?? []
        ));

        return (new ServiceComponent($this->app, $config))
            ->setContext($this->context)
            ->setDispatcher($this->dispatcher)
            ->setMiddleware($middleware)
            ->export();
    }
918097
private function resolveConstructorArguments(ReflectionMethod $constructor, array $arguments)
    {
        $constructorParameters = $constructor->getParameters();

        foreach ($constructorParameters as $position => $parameter) {
            if ($parameter->getClass() && ServiceMocker::class === $parameter->getClass()->getName()) {
                $arguments[$position] = $this->serviceMocker;
            }
        }

        return $arguments;
    }
271442
public static function configure_server($options = array())
    {
        self::$solr_options = array_merge(self::$solr_options, $options);
        self::$merged_solr_options = null;

        self::$service_singleton = null;
        self::$service_core_singletons = array();
    }
1260215
private function processSlaveConfigurationsIfExist(array &$serviceConnArguments, array $resolvedConnConfig)
    {
        if (array_key_exists('slaves', $serviceConnArguments)) {
            foreach ($serviceConnArguments['slaves'] as $slaveName => &$slaveConfig) {
                $this->replaceConnectionArguments($slaveConfig, $resolvedConnConfig['slaves'][$slaveName]);
            }
        }
    }