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

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.     /** @var ContainerInterface */
  14.     private $container;
  15.     /** @var array */
  16.     private $serviceMap;
  17.     /**
  18.      * ClientRegistry constructor.
  19.      */
  20.     public function __construct(ContainerInterface $container, array $serviceMap)
  21.     {
  22.         $this->container $container;
  23.         $this->serviceMap $serviceMap;
  24.     }
  25.     /**
  26.      * Easy accessor for client objects.
  27.      *
  28.      * @param string $key
  29.      *
  30.      * @return OAuth2ClientInterface
  31.      */
  32.     public function getClient($key)
  33.     {
  34.         if (isset($this->serviceMap[$key])) {
  35.             $client $this->container->get($this->serviceMap[$key]);
  36.             if (!$client instanceof OAuth2ClientInterface) {
  37.                 throw new \InvalidArgumentException(sprintf('Somehow the "%s" client is not an instance of OAuth2ClientInterface.'$key));
  38.             }
  39.             return $client;
  40.         }
  41.         throw new \InvalidArgumentException(sprintf('There is no OAuth2 client called "%s". Available are: %s'$keyimplode(', 'array_keys($this->serviceMap))));
  42.     }
  43.     /**
  44.      * Returns all enabled client keys.
  45.      *
  46.      * @return array
  47.      */
  48.     public function getEnabledClientKeys()
  49.     {
  50.         return array_keys($this->serviceMap);
  51.     }
  52. }