|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Phalcon Framework. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Phalcon Team <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Phalcon\Cache; |
|
15
|
|
|
|
|
16
|
|
|
use Phalcon\Cache\Adapter\AdapterInterface; |
|
17
|
|
|
use Phalcon\Factory\AbstractFactory; |
|
18
|
|
|
use Phalcon\Factory\Exception; |
|
19
|
|
|
use Phalcon\Storage\SerializerFactory; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Factory to create Cache adapters |
|
23
|
|
|
* |
|
24
|
|
|
* @property SerializerFactory|null $serializerFactory |
|
25
|
|
|
*/ |
|
26
|
|
|
class AdapterFactory extends AbstractFactory |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var SerializerFactory|null |
|
30
|
|
|
*/ |
|
31
|
|
|
private ?SerializerFactory $serializerFactory; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* AdapterFactory constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param SerializerFactory|null $factory |
|
37
|
|
|
* @param array $services |
|
38
|
|
|
*/ |
|
39
|
22 |
|
public function __construct(SerializerFactory $factory = null, array $services = []) |
|
40
|
|
|
{ |
|
41
|
22 |
|
$this->serializerFactory = $factory; |
|
42
|
|
|
|
|
43
|
22 |
|
$this->init($services); |
|
44
|
22 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create a new instance of the adapter |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $name |
|
50
|
|
|
* @param array $options |
|
51
|
|
|
* |
|
52
|
|
|
* @return AdapterInterface |
|
53
|
|
|
* @throws Exception |
|
54
|
|
|
*/ |
|
55
|
22 |
|
public function newInstance(string $name, array $options = []): AdapterInterface |
|
56
|
|
|
{ |
|
57
|
22 |
|
$this->checkService($name); |
|
58
|
|
|
|
|
59
|
21 |
|
$definition = $this->mapper[$name]; |
|
60
|
|
|
|
|
61
|
21 |
|
return new $definition($this->serializerFactory, $options); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Returns the available adapters |
|
66
|
|
|
*/ |
|
67
|
22 |
|
protected function getAdapters(): array |
|
68
|
|
|
{ |
|
69
|
|
|
return [ |
|
70
|
22 |
|
"apcu" => 'Phalcon\Cache\Adapter\Apcu', |
|
71
|
|
|
"libmemcached" => 'Phalcon\Cache\Adapter\Libmemcached', |
|
72
|
|
|
"memory" => 'Phalcon\Cache\Adapter\Memory', |
|
73
|
|
|
"redis" => 'Phalcon\Cache\Adapter\Redis', |
|
74
|
|
|
"stream" => 'Phalcon\Cache\Adapter\Stream', |
|
75
|
|
|
]; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|