Create services from PHP Azure SDK (Blob, Table, Queue, ServiceManagement, ServiceBus).

@param array $config
@param ContainerBuilder $container
979098
protected function loadServices($config, $container)
    {
        if (! isset($config['services'])) {
            return;
        }

        $serviceMethods = array(
            'blob' => 'createBlobService',
            'table' => 'createTableService',
            'queue' => 'createQueueService',
            'service_bus' => 'createServiceBusService',
            'management' => 'createServiceManagementService'
        );

        $serviceClass = array(
            'blob' => 'WindowsAzure\Blob\BlobRestProxy',
            'table' => 'WindowsAzure\Table\TableRestProxy',
            'queue' => 'WindowsAzure\Queue\QueueRestProxy',
            'service_bus' => 'WindowsAzure\ServiceBus\ServiceBusRestProxy',
            'management' => 'WindowsAzure\ServiceManagement\ServiceManagementRestProxy'
        );

        foreach ($config['services'] as $type => $connectionStrings) {
            foreach ($connectionStrings as $name => $connectionString) {
                $def = new Definition($serviceClass[$type]);
                $def->setFactoryService('windows_azure.services_builder');
                $def->setFactoryMethod($serviceMethods[$type]);
                $def->setArguments(array(
                    $connectionString
                ));

                $container->setDefinition(sprintf('windows_azure.%s.%s', $type, $name), $def);
            }
        }
    }
644054
public function load(array $config, ContainerBuilder $container)
    {
        if (!isset($config['framework_path'])) {
            throw new \InvalidArgumentException('Specify `framework_path` parameter for silverstripe_extension');
        }

        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services'));
        $loader->load('silverstripe.yml');

        $behatBasePath = $container->getParameter('behat.paths.base');
        $config['framework_path'] = realpath(sprintf('%s%s%s',
            rtrim($behatBasePath, DIRECTORY_SEPARATOR),
            DIRECTORY_SEPARATOR,
            ltrim($config['framework_path'], DIRECTORY_SEPARATOR)
        ));
        if (!file_exists($config['framework_path']) || !is_dir($config['framework_path'])) {
            throw new \InvalidArgumentException('Path specified as `framework_path` either doesn\'t exist or is not a directory');
        }

        $container->setParameter('behat.silverstripe_extension.framework_path', $config['framework_path']);
        $container->setParameter('behat.silverstripe_extension.admin_url', $config['admin_url']);
        $container->setParameter('behat.silverstripe_extension.login_url', $config['login_url']);
        $container->setParameter('behat.silverstripe_extension.screenshot_path', $config['screenshot_path']);
        $container->setParameter('behat.silverstripe_extension.ajax_timeout', $config['ajax_timeout']);
        if (isset($config['ajax_steps'])) {
            $container->setParameter('behat.silverstripe_extension.ajax_steps', $config['ajax_steps']);
        }
        if (isset($config['region_map'])) {
             $container->setParameter('behat.silverstripe_extension.region_map', $config['region_map']);
        }
    }
1157267
protected function loadConfiguration(array $config, ContainerBuilder $container)
    {
        // Load page nested routes
        $routeConfigurationChain = $container->findDefinition('lp_factory.route_configuration.chain');
        foreach ($config['routes'] as $alias => $routeConfiguration) {
            $routeConfigurationChain->addMethodCall('add', array($alias, $routeConfiguration));
        }

        $routeFactoryId = $config['service_ids']['factory'];
        $treeStrategyId = $config['service_ids']['strategy'];

        // Inject service route factory
        $routeProvider = $container->findDefinition('lp_factory.route_provider');
        $routeProvider->replaceArgument(0, new Reference($routeFactoryId));
        $routeProvider->replaceArgument(3, new Reference($treeStrategyId));

        // Add repository and strategy arguments
        $routeFactory = $container->findDefinition($routeFactoryId);
        $routeFactory->replaceArgument(0, new Reference($config['repository']));
        $routeFactory->replaceArgument(1, new Reference($treeStrategyId));
        $abstractStrategy = $container->findDefinition('lp_factory.route_strategy.abstract');
        $abstractStrategy->replaceArgument(0, new Reference($config['repository']));
    }
1187063
protected function postLoad(array $config, ContainerBuilder $container)
    {
        $this
            ->loadBlocks($config['blocks'], $container)
            ->loadStatics($config['statics'], $container)
            ->loadBuilders($config['builders'], $container)
            ->loadDumpers($config['builders'], $container)
            ->loadProfiles($config['profiles'], $container);
    }
145641
private static function createConfiguration(array $config, ContainerInterface $container = null)
    {
        $cache = $config['cache'];

        if ($container && is_string($config['cache']) && $container->has($config['cache'])) {
            $cache = $container->get($config['cache']);
        }

        return Setup::createConfiguration($config['debug'], $config['proxy_dir'], $cache);
    }
243184
protected function dbalLoad(array $config, ContainerBuilder $container)
    {
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('dbal.xml');

        if (empty($config['default_connection'])) {
            $keys                         = array_keys($config['connections']);
            $config['default_connection'] = reset($keys);
        }

        $this->defaultConnection = $config['default_connection'];

        $container->setAlias('database_connection', sprintf('doctrine.dbal.%s_connection', $this->defaultConnection));
        $container->getAlias('database_connection')->setPublic(true);
        $container->setAlias('doctrine.dbal.event_manager', new Alias(sprintf('doctrine.dbal.%s_connection.event_manager', $this->defaultConnection), false));

        $container->setParameter('doctrine.dbal.connection_factory.types', $config['types']);

        $connections = [];

        foreach (array_keys($config['connections']) as $name) {
            $connections[$name] = sprintf('doctrine.dbal.%s_connection', $name);
        }

        $container->setParameter('doctrine.connections', $connections);
        $container->setParameter('doctrine.default_connection', $this->defaultConnection);

        foreach ($config['connections'] as $name => $connection) {
            $this->loadDbalConnection($name, $connection, $container);
        }
    }
951598
public function configureFilesystemAdapter(ContainerBuilder $container, array $config): void
    {
        // add the default configuration for the S3 filesystem
        if ($container->hasDefinition('bkstg.core.adapter.filesystem.do_spaces') && isset($config['filesystem'])) {
            $container->getDefinition('bkstg.core.adapter.filesystem.do_spaces')
                ->replaceArgument(0, new Reference('bkstg.core.adapter.service.do_spaces'))
                ->replaceArgument(1, $config['filesystem']['bucket'])
                ->replaceArgument(
                    2,
                    [
                        'create' => $config['filesystem']['create'],
                        'region' => $config['filesystem']['region'],
                        'directory' => $config['filesystem']['directory'],
                        'ACL' => $config['filesystem']['acl'],
                    ]
                )
            ;

            if (3 === $config['filesystem']['sdk_version']) {
                $arguments = [
                    'region' => $config['filesystem']['region'],
                    'version' => $config['filesystem']['version'],
                ];

                if (isset($config['filesystem']['secretKey'], $config['filesystem']['accessKey'])) {
                    $arguments['credentials'] = [
                        'secret' => $config['filesystem']['secretKey'],
                        'key' => $config['filesystem']['accessKey'],
                    ];
                }

                if (isset($config['filesystem']['endpoint'])) {
                    $arguments['endpoint'] = $config['filesystem']['endpoint'];
                } else {
                    $arguments['endpoint'] = sprintf(
                        'https://%s.digitaloceanspaces.com',
                        $config['filesystem']['region']
                    );
                }

                $container->getDefinition('bkstg.core.adapter.service.do_spaces')
                    ->replaceArgument(0, $arguments)
                ;
            } else {
                $container->getDefinition('bkstg.core.adapter.service.do_spaces')
                    ->replaceArgument(0, [
                        'secret' => $config['filesystem']['secretKey'],
                        'key' => $config['filesystem']['accessKey'],
                    ])
                ;
            }
        } else {
            $container->removeDefinition('bkstg.core.adapter.filesystem.do_spaces');
            $container->removeDefinition('bkstg.core.filesystem.do_spaces');
        }
    }
952735
public function getConfiguration(array $config, ContainerBuilder $container)
    {
        $configuration = $this->getConfigurationInstance();
        if ($configuration) {
            $container->addObjectResource($configuration);
        }

        return $configuration;
    }
210209
private function configurePlugins(ContainerBuilder $container, array $config)
    {
        if (!empty($config['authentication'])) {
            $this->configureAuthentication($container, $config['authentication']);
        }
        unset($config['authentication']);

        foreach ($config as $name => $pluginConfig) {
            $pluginId = 'httplug.plugin.'.$name;

            if ($this->isConfigEnabled($container, $pluginConfig)) {
                $def = $container->getDefinition($pluginId);
                $this->configurePluginByName($name, $def, $pluginConfig, $container, $pluginId);
            }
        }
    }
1334361
public function load(array $config, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $config);

        $container->setParameter('open_orchestra_api.controller.http_exception_controller', $config['http_exception_controller']);
        $container->setParameter('open_orchestra_api.token.expiration_time', $config['token_expiration_time']);
        $container->setParameter('open_orchestra_api.handlers.datetime.default_format', \DateTime::ISO8601);
        $container->setParameter('open_orchestra_api.handlers.datetime.default_timezone', date_default_timezone_get());
        $container->setParameter('open_orchestra_api.handlers.datetime.cdata', true);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
        $loader->load('transformer.yml');
        $loader->load('oauth2.yml');
        $loader->load('security.yml');
    }
1269616
public function configureProfiler(ContainerBuilder $container, array $config)
    {
        // Setup the data collector service for Symfony profiler
        $dataCollectorDef = new Definition(PheanstalkDataCollector::class);
        $dataCollectorDef->setPublic(false);
        $dataCollectorDef->addTag('data_collector', ['id' => 'pheanstalk', 'template' => $config['profiler']['template']]);
        $dataCollectorDef->addArgument(new Reference('leezy.pheanstalk.pheanstalk_locator'));

        $container->setDefinition('leezy.pheanstalk.data_collector', $dataCollectorDef);
    }
190458
public function load(ContainerBuilder $container, array $config) {
        // Client initializer definition
        $clientInitializerDefinition = new Definition(
            ApiClientAwareInitializer::class,
            [
                $config['apiClient']
            ]
        );
        $clientInitializerDefinition->addTag(ContextExtension::INITIALIZER_TAG);

        // Definition for the array contains comparator
        $comparatorDefinition = new Definition(ArrayContainsComparator::class);

        // Comparator initializer definition
        $comparatorInitializerDefinition = new Definition(
            ArrayContainsComparatorAwareInitializer::class,
            [
                new Reference(self::COMPARATOR_SERVICE_ID)
            ]
        );
        $comparatorInitializerDefinition->addTag(ContextExtension::INITIALIZER_TAG);

        // Add all definitions to the container
        $container->setDefinition(self::APICLIENT_INITIALIZER_SERVICE_ID, $clientInitializerDefinition);
        $container->setDefinition(self::COMPARATOR_SERVICE_ID, $comparatorDefinition);
        $container->setDefinition(self::COMPARATOR_INITIALIZER_SERVICE_ID, $comparatorInitializerDefinition);
    }
639283
public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $this->config = $this->processConfiguration($configuration, $configs);

        foreach (ServicesFactory::getAvailableServices() as $service) {
            $serviceKey = StringUtil::camelcaseToUnderscore($service);
            $definition = new Definition('Aws\\'.$service.'\\'.$service.'Client', array($this->getConfig($serviceKey)));
            $definition->setPublic(true);
            $container->setDefinition('aws.'.$serviceKey, $definition);
        }
    }
406328
public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration( $configuration, $configs );

        $loader = new Loader\YamlFileLoader( $container, new FileLocator( __DIR__.'/../Resources/config' ) );
        $loader->load( 'services.yml' );

        //Services to use are stored as parameters and will be processes by Compiler\ServiceAliasesPass
        $container->setParameter( self::FACADE_SERVICE_ID, $config['facade'] );
        $container->setParameter( self::FORM_PROVIDER_SERVICE_ID, $config['providers']['form'] );
        $container->setParameter( self::HANDLER_PROVIDER_SERVICE_ID, $config['providers']['handler'] );
        $container->setParameter( self::RESPONSE_PROVIDER_SERVICE_ID, $config['providers']['response'] );
    }
985771
public function loadInternal(array $config, ContainerBuilder $container)
    {
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.yml');

        $bundles = $container->getParameter('kernel.bundles');

        $directories = [];
        if ($config['metadata']['auto_detection']) {
            foreach ($bundles as $name => $class) {
                $ref                                   = new \ReflectionClass($class);
                $directories[$ref->getNamespaceName()] = dirname($ref->getFileName()) . '/Resources/config/fixture';
            }
        }

        foreach ($config['metadata']['directories'] as $directory) {
            $directory['path'] = rtrim(str_replace('\\', '/', $directory['path']), '/');
            if ('@' === $directory['path'][0]) {
                preg_match('~^@([a-z0-9_]+)~i', $directory['path'], $match);

                if (isset($match[1])) {
                    list($prefixedBundleName, $bundleName) = $match;
                    if (!isset($bundles[$bundleName])) {
                        throw new RuntimeException(sprintf('The bundle "%s" has not been registered with AppKernel. Available bundles: %s', $bundleName, implode(', ', array_keys($bundles))));
                    }
                    $ref = new \ReflectionClass($bundles[$bundleName]);
                    $directory['path'] = dirname($ref->getFileName()).substr($directory['path'], strlen($prefixedBundleName));
                }
            }
            $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/');
        }

        $container
            ->getDefinition('trappar_alice_generator.metadata.file_locator')
            ->addArgument($directories);

        $container
            ->getDefinition(YamlWriter::class)
            ->addArgument($config['yaml']['inline'])
            ->addArgument($config['yaml']['indent']);

        $container
            ->getDefinition(ValueVisitor::class)
            ->addArgument($config['strictTypeChecking']);
    }
163704
public function process(ContainerBuilder $container)
    {
        $pool = $container->getDefinition('admin.configuration.pool');
        // get tagged services
        $configurations = array();
        foreach ($container->findTaggedServiceIds('admin.configuration') as $id => $attributes) {
            $configurations[$id] = $attributes;
        }
        $pool->addMethodCall('setConfigurations', array($configurations));
    }
718983
public function configureConnections(ContainerBuilder $container, array $config)
    {
        // Create a connection locator that will reference all existing connection
        $connectionLocatorDef = new Definition(PheanstalkLocator::class);
        $container->setDefinition('leezy.pheanstalk.pheanstalk_locator', $connectionLocatorDef);
        $container->setParameter('leezy.pheanstalk.pheanstalks', $config['pheanstalks']);
    }