KnpU\OAuth2ClientBundle\DependencyInjection\KnpUOAuth2ClientExtension::load PHP Method

load() public method

Load the bundle configuration.
public load ( array $configs, ContainerBuilder $container )
$configs array
$container Symfony\Component\DependencyInjection\ContainerBuilder
    public function load(array $configs, ContainerBuilder $container)
    {
        $processor = new Processor();
        $configuration = new Configuration();
        $config = $processor->processConfiguration($configuration, $configs);
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
        $loader->load('services.xml');
        $clientConfigurations = $config['clients'];
        $clientServiceKeys = [];
        foreach ($clientConfigurations as $key => $clientConfig) {
            // manually make sure "type" is there
            if (!isset($clientConfig['type'])) {
                throw new InvalidConfigurationException(sprintf('Your "knpu_oauth2_client.clients." config entry is missing the "type" key.', $key));
            }
            $type = $clientConfig['type'];
            unset($clientConfig['type']);
            if (!isset(self::$supportedProviderTypes[$type])) {
                throw new InvalidConfigurationException(sprintf('The "knpu_oauth2_client.clients" config "type" key "%s" is not supported. We support (%s)', $type, implode(', ', self::$supportedProviderTypes)));
            }
            // process the configuration
            $tree = new TreeBuilder();
            $node = $tree->root('knpu_oauth2_client/clients/' . $key);
            $this->buildConfigurationForType($node, $type);
            $processor = new Processor();
            $config = $processor->process($tree->buildTree(), [$clientConfig]);
            $configurator = $this->getConfigurator($type);
            // hey, we should add the provider/client service!
            $clientServiceKey = $this->configureProviderAndClient($container, $type, $key, $configurator->getProviderClass($config), $configurator->getClientClass($config), $configurator->getPackagistName(), $configurator->getProviderOptions($config), $config['redirect_route'], $config['redirect_params'], $config['use_state']);
            $clientServiceKeys[$key] = $clientServiceKey;
        }
        $container->getDefinition('knpu.oauth2.registry')->replaceArgument(1, $clientServiceKeys);
    }

Usage Example

 /**
  * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  * @dataProvider provideBadConfiguration
  */
 public function testBadProvidersConfiguration(array $badProvidersConfig)
 {
     $this->configuration = new ContainerBuilder();
     $loader = new KnpUOAuth2ClientExtension(false);
     $config = array('providers' => $badProvidersConfig);
     $loader->load(array($config), $this->configuration);
 }
All Usage Examples Of KnpU\OAuth2ClientBundle\DependencyInjection\KnpUOAuth2ClientExtension::load