commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
OAuthHandlerFactory.php
1 <?php
2 
3 declare(strict_types=1);
10 namespace Commercetools\Client;
11 
13 use GuzzleHttp\Client;
14 use Psr\Cache\CacheItemPoolInterface;
15 use Psr\SimpleCache\CacheInterface;
16 
18 {
22  public static function ofAuthConfig(AuthConfig $authConfig, $cache = null): OAuth2Handler
23  {
24  $cache = CacheValidator::validateCache($cache);
25  switch (true) {
26  case $authConfig instanceof ClientCredentialsConfig:
27  $provider = new CachedTokenProvider(
29  new Client($authConfig->getOptions()),
30  $authConfig->getAuthUri(),
31  $authConfig->getCredentials()
32  ),
33  $cache,
34  $authConfig->getCredentials()->getCacheKey()
35  );
36  break;
37  default:
38  throw new InvalidArgumentException('Unknown authorization configuration');
39  }
40  return self::ofProvider($provider);
41  }
42 
43  public static function ofProvider(TokenProvider $provider): OAuth2Handler
44  {
45  return new OAuth2Handler($provider);
46  }
47 }
static ofProvider(TokenProvider $provider)
static ofAuthConfig(AuthConfig $authConfig, $cache=null)