|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of Biurad opensource projects. |
|
7
|
|
|
* |
|
8
|
|
|
* PHP version 7.1 and above required |
|
9
|
|
|
* |
|
10
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
11
|
|
|
* @copyright 2019 Biurad Group (https://biurad.com/) |
|
12
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause License |
|
13
|
|
|
* |
|
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
15
|
|
|
* file that was distributed with this source code. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Biurad\Cache; |
|
19
|
|
|
|
|
20
|
|
|
use Biurad\Cache\Exceptions\CacheException; |
|
21
|
|
|
use Doctrine\Common\Cache as DoctrineCache; |
|
22
|
|
|
use Doctrine\Common\Cache\Psr6\CacheAdapter; |
|
23
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
|
24
|
|
|
use Symfony\Component\Cache\DoctrineProvider as SymfonyDoctrineProvider; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create a doctrine cache wrapped with PSR-6. |
|
28
|
|
|
* |
|
29
|
|
|
* @deprecated Deprecated without replacement since doctrine/cache version 1.11. |
|
30
|
|
|
* |
|
31
|
|
|
* @codeCoverageIgnore |
|
32
|
|
|
* |
|
33
|
|
|
* @author Divine Niiquaye Ibok <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class AdapterFactory |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @param object|string $connection Connection or DSN |
|
39
|
|
|
*/ |
|
40
|
|
|
public static function createHandler($connection): CacheItemPoolInterface |
|
41
|
|
|
{ |
|
42
|
|
|
static $adapter; |
|
43
|
|
|
|
|
44
|
|
|
switch (true) { |
|
45
|
|
|
case $connection instanceof DoctrineCache\Cache || $connection instanceof SymfonyDoctrineProvider: |
|
46
|
|
|
return CacheAdapter::wrap($connection); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
case \is_string($connection): |
|
49
|
|
|
if (\in_array($connection, ['array', 'apcu', 'win-cache', 'zend-data'], true)) { |
|
50
|
|
|
$adapter = \sprintf('Doctrine\Common\Cache\%sCache', \ucwords($connection, '-')); |
|
51
|
|
|
|
|
52
|
|
|
return CacheAdapter::wrap(new $adapter()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$connection = self::getPrefixedAdapter($connection, $adapter); |
|
56
|
|
|
|
|
57
|
|
|
if ($connection instanceof DoctrineCache\Cache) { |
|
58
|
|
|
return CacheAdapter::wrap($connection); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
// no break |
|
62
|
|
|
|
|
63
|
|
|
case $connection instanceof \Redis: |
|
64
|
|
|
$adapter = new DoctrineCache\RedisCache(); |
|
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
$adapter->setRedis($connection); |
|
67
|
|
|
|
|
68
|
|
|
break; |
|
69
|
|
|
|
|
70
|
|
|
case $connection instanceof \Memcache: |
|
71
|
|
|
$adapter = new DoctrineCache\MemcacheCache(); |
|
|
|
|
|
|
72
|
|
|
$adapter->setMemcache($connection); |
|
73
|
|
|
|
|
74
|
|
|
break; |
|
75
|
|
|
|
|
76
|
|
|
case $connection instanceof \Memcached: |
|
77
|
|
|
$adapter = new DoctrineCache\MemcachedCache(); |
|
|
|
|
|
|
78
|
|
|
$adapter->setMemcached($connection); |
|
79
|
|
|
|
|
80
|
|
|
break; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if ($adapter instanceof DoctrineCache\Cache) { |
|
84
|
|
|
return CacheAdapter::wrap($adapter); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
throw new CacheException( |
|
88
|
|
|
\sprintf('Unsupported Cache Adapter: %s.', \is_object($connection) ? \get_class($connection) : $connection) |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param mixed $adapter |
|
94
|
|
|
* |
|
95
|
|
|
* @return \Redis|\Memcache|\Memcached|DoctrineCache\Cache|null |
|
96
|
|
|
*/ |
|
97
|
|
|
private static function getPrefixedAdapter(string $connection, $adapter) |
|
98
|
|
|
{ |
|
99
|
|
|
$connection = \parse_url($connection) ?: \explode('://', $connection, 2) ?: []; |
|
100
|
|
|
|
|
101
|
|
|
// Extract parsed connection string. |
|
102
|
|
|
list($scheme, $host, $port) = [ |
|
103
|
|
|
$connection['scheme'] ?? $connection[0] ?? null, |
|
104
|
|
|
$connection['host'] ?? $connection[1] ?? null, |
|
105
|
|
|
$connection['port'] ?? null, |
|
106
|
|
|
]; |
|
107
|
|
|
|
|
108
|
|
|
if (isset($scheme, $host)) { |
|
109
|
|
|
switch ($connectionServer = \ucfirst($scheme)) { |
|
110
|
|
|
case 'Redis': |
|
111
|
|
|
($adapter = new \Redis())->connect($host, $port ?? 6379); |
|
112
|
|
|
|
|
113
|
|
|
break; |
|
114
|
|
|
|
|
115
|
|
|
case 'sqlite': |
|
116
|
|
|
$adapter = new DoctrineCache\SQLite3Cache(new \SQLite3($host), 'doctrine_cache'); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
break; |
|
119
|
|
|
|
|
120
|
|
|
case 'Memcache': |
|
121
|
|
|
case 'Memcache': |
|
122
|
|
|
/** @var \Memcache|\Memcached $adapter */ |
|
123
|
|
|
($adapter = new $connectionServer())->addServer($host, $port ?? 11211); |
|
124
|
|
|
|
|
125
|
|
|
break; |
|
126
|
|
|
|
|
127
|
|
|
case 'Serialize': |
|
128
|
|
|
case 'Serialise': |
|
129
|
|
|
$adapter = new DoctrineCache\PhpFileCache($host); |
|
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
break; |
|
132
|
|
|
|
|
133
|
|
|
case 'Filesystem': |
|
134
|
|
|
case 'File': |
|
135
|
|
|
$adapter = new DoctrineCache\FilesystemCache($host); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return $adapter; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths