1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arp\LaminasDoctrine\Factory\Cache\Adapter; |
6
|
|
|
|
7
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
8
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotCreatedException; |
9
|
|
|
use Laminas\ServiceManager\Exception\ServiceNotFoundException; |
10
|
|
|
use Psr\Container\ContainerExceptionInterface; |
11
|
|
|
use Psr\Container\ContainerInterface; |
12
|
|
|
use Symfony\Component\Cache\Adapter\ArrayAdapter; |
13
|
|
|
use Symfony\Component\Cache\Exception\InvalidArgumentException; |
14
|
|
|
|
15
|
|
|
final class ArrayAdapterFactory extends AbstractFactory |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array<string, mixed>|null $options |
19
|
|
|
* |
20
|
|
|
* @throws ServiceNotCreatedException |
21
|
|
|
* @throws ServiceNotFoundException |
22
|
|
|
* @throws ContainerExceptionInterface |
23
|
|
|
*/ |
24
|
|
|
public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): ArrayAdapter |
25
|
|
|
{ |
26
|
|
|
$options = $options ?? $this->getServiceOptions($container, $requestedName, 'cache'); |
27
|
|
|
|
28
|
|
|
try { |
29
|
|
|
return new ArrayAdapter( |
30
|
|
|
$options['default_lifetime'] ?? 0, |
31
|
|
|
$options['store_serialized'] ?? 0, |
|
|
|
|
32
|
|
|
$options['max_lifetime'] ?? 0, |
33
|
|
|
$options['max_items'] ?? 0, |
34
|
|
|
); |
35
|
|
|
} catch (InvalidArgumentException $e) { |
36
|
|
|
throw new ServiceNotCreatedException( |
37
|
|
|
sprintf('Failed to create cache adapter \'%s\' due to invalid configuration options', $requestedName), |
38
|
|
|
$e->getCode(), |
39
|
|
|
$e, |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|