-
Notifications
You must be signed in to change notification settings - Fork 3
/
AdaptorCacheFactory.php
38 lines (31 loc) · 1.18 KB
/
AdaptorCacheFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
declare(strict_types=1);
namespace WShafer\PSR11FlySystem\Cache;
use League\Flysystem\Cached\Storage\Adapter;
use WShafer\PSR11FlySystem\Exception\MissingConfigException;
use WShafer\PSR11FlySystem\Exception\MissingServiceException;
use WShafer\PSR11FlySystem\FlySystemFactory;
use WShafer\PSR11FlySystem\FlySystemManager;
class AdaptorCacheFactory extends ContainerAwareCacheAbstract
{
public function __invoke(array $options)
{
if (empty($options['adaptor'])) {
throw new MissingConfigException(
'Unable to locate cache file adaptor in config'
);
}
$adaptor = $options['adaptor'];
$fileName = $options['fileName'] ?? 'file_cache';
$ttl = $options['ttl'] ?? null;
/** @var FlySystemManager $manager */
$manager = FlySystemFactory::getFlySystemManager($this->getContainer());
$adaptorManager = $manager->getAdaptorManager();
if (!$adaptorManager->has($adaptor)) {
throw new MissingServiceException(
'Unable to locate file system: '.$adaptor
);
}
return new Adapter($adaptorManager->get($adaptor), $fileName, $ttl);
}
}