vendor/knpuniversity/oauth2-client-bundle/src/Client/ClientRegistry.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * OAuth2 Client Bundle
  4.  * Copyright (c) KnpUniversity <http://knpuniversity.com/>
  5.  *
  6.  * For the full copyright and license information, please view the LICENSE
  7.  * file that was distributed with this source code.
  8.  */
  9. namespace KnpU\OAuth2ClientBundle\Client;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. class ClientRegistry
  12. {
  13.     private ContainerInterface $container;
  14.     private array $serviceMap;
  15.     /**
  16.      * ClientRegistry constructor.
  17.      */
  18.     public function __construct(ContainerInterface $container, array $serviceMap)
  19.     {
  20.         $this->container $container;
  21.         $this->serviceMap $serviceMap;
  22.     }
  23.     /**
  24.      * Easy accessor for client objects.
  25.      *
  26.      * @param string $key
  27.      *
  28.      * @return OAuth2ClientInterface
  29.      */
  30.     public function getClient($key)
  31.     {
  32.         if (isset($this->serviceMap[$key])) {
  33.             $client $this->container->get($this->serviceMap[$key]);
  34.             if (!$client instanceof OAuth2ClientInterface) {
  35.                 throw new \InvalidArgumentException(\sprintf('Somehow the "%s" client is not an instance of OAuth2ClientInterface.'$key));
  36.             }
  37.             return $client;
  38.         }
  39.         throw new \InvalidArgumentException(\sprintf('There is no OAuth2 client called "%s". Available are: %s'$keyimplode(', 'array_keys($this->serviceMap))));
  40.     }
  41.     /**
  42.      * Returns all enabled client keys.
  43.      *
  44.      * @return array
  45.      */
  46.     public function getEnabledClientKeys()
  47.     {
  48.         return array_keys($this->serviceMap);
  49.     }
  50. }