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

getConfigurator() public method

public getConfigurator ( string $type ) : KnpU\OAuth2ClientBundle\DependencyInjection\Providers\ProviderConfiguratorInterface
$type string
return KnpU\OAuth2ClientBundle\DependencyInjection\Providers\ProviderConfiguratorInterface
    public function getConfigurator($type)
    {
        if (!isset($this->configurators[$type])) {
            $class = self::$supportedProviderTypes[$type];
            $this->configurators[$type] = new $class();
        }
        return $this->configurators[$type];
    }

Usage Example

 public function provideTypesAndConfig()
 {
     $tests = [];
     $extension = new KnpUOAuth2ClientExtension();
     foreach (KnpUOAuth2ClientExtension::getAllSupportedTypes() as $type) {
         $configurator = $extension->getConfigurator($type);
         $tree = new TreeBuilder();
         $configNode = $tree->root('testing');
         $configurator->buildConfiguration($configNode->children(), $type);
         /** @var ArrayNode $arrayNode */
         $arrayNode = $tree->buildTree();
         $config = ['client_id' => 'CLIENT_ID_TEST', 'client_secret' => 'CLIENT_SECRET_TEST', 'redirect_route' => 'go_there', 'redirect_params' => [], 'use_state' => rand(0, 1) == 0];
         // loop through and assign some random values
         foreach ($arrayNode->getChildren() as $child) {
             /** @var NodeInterface $child */
             if ($child instanceof ArrayNode) {
                 $config[$child->getName()] = [];
             } else {
                 $config[$child->getName()] = rand();
             }
         }
         $tests[] = [$type, $config];
     }
     return $tests;
 }