|
9 | 9 |
|
10 | 10 | namespace Commercetools\Client; |
11 | 11 |
|
12 | | -use Cache\Adapter\Filesystem\FilesystemCachePool; |
13 | 12 | use Commercetools\Exception\InvalidArgumentException; |
14 | 13 | use GuzzleHttp\Client; |
15 | | -use League\Flysystem\Adapter\Local; |
16 | | -use League\Flysystem\Filesystem; |
17 | 14 | use Psr\Cache\CacheItemPoolInterface; |
18 | 15 | use Psr\SimpleCache\CacheInterface; |
| 16 | +use Symfony\Component\Cache\Simple\FilesystemCache; |
19 | 17 |
|
20 | 18 | class OAuthHandlerFactory |
21 | 19 | { |
22 | | - /** |
23 | | - * @psalm-param CacheItemPoolInterface|CacheInterface|null $cache |
24 | | - * @psalm-return CacheItemPoolInterface|CacheInterface |
25 | | - */ |
26 | | - private static function validateCache($cache = null) |
27 | | - { |
28 | | - if ($cache instanceof CacheItemPoolInterface || $cache instanceof CacheInterface) { |
29 | | - return $cache; |
30 | | - } |
31 | | - |
32 | | - $filesystemAdapter = new Local(getcwd()); |
33 | | - $filesystem = new Filesystem($filesystemAdapter); |
34 | | - $cache = new FilesystemCachePool($filesystem); |
35 | | - |
36 | | - return $cache; |
37 | | - } |
38 | | - |
39 | 20 | /** |
40 | 21 | * @psalm-param CacheItemPoolInterface|CacheInterface|null $cache |
41 | 22 | */ |
42 | 23 | public static function ofAuthConfig(AuthConfig $authConfig, $cache = null): OAuth2Handler |
43 | 24 | { |
44 | | - $cache = self::validateCache($cache); |
| 25 | + $cache = CacheValidator::validateCache($cache); |
45 | 26 | switch (true) { |
46 | | - case $authConfig instanceof ClientCredentialsConfig: |
47 | | - $provider = new CachedTokenProvider( |
48 | | - new ClientCredentialTokenProvider( |
49 | | - new Client($authConfig->getOptions()), |
50 | | - $authConfig->getAuthUri(), |
51 | | - $authConfig->getCredentials() |
52 | | - ), |
53 | | - $cache, |
54 | | - $authConfig->getCredentials()->getCacheKey() |
55 | | - ); |
56 | | - break; |
57 | | - default: |
58 | | - throw new InvalidArgumentException('Unknown authorization configuration'); |
| 27 | + case $authConfig instanceof ClientCredentialsConfig: |
| 28 | + $provider = new CachedTokenProvider( |
| 29 | + new ClientCredentialTokenProvider( |
| 30 | + new Client($authConfig->getOptions()), |
| 31 | + $authConfig->getAuthUri(), |
| 32 | + $authConfig->getCredentials() |
| 33 | + ), |
| 34 | + $cache, |
| 35 | + $authConfig->getCredentials()->getCacheKey() |
| 36 | + ); |
| 37 | + break; |
| 38 | + default: |
| 39 | + throw new InvalidArgumentException('Unknown authorization configuration'); |
59 | 40 |
|
60 | 41 | } |
61 | 42 | return self::ofProvider($provider); |
|
0 commit comments