1
|
|
|
<?php namespace Comodojo\Cache\Providers; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Cache\Drivers\PhpRedis as PhpRedisDriver; |
4
|
|
|
use \Comodojo\Cache\Item; |
5
|
|
|
use \Comodojo\Cache\Components\EnhancedCacheItemPoolStats; |
6
|
|
|
use \Comodojo\Foundation\Validation\DataValidation; |
7
|
|
|
use \Comodojo\Foundation\Validation\DataFilter; |
8
|
|
|
use \Psr\Log\LoggerInterface; |
9
|
|
|
use \Comodojo\Exception\CacheException; |
10
|
|
|
use \Exception; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @package Comodojo Cache |
14
|
|
|
* @author Marco Giovinazzi <[email protected]> |
15
|
|
|
* @license MIT |
16
|
|
|
* |
17
|
|
|
* LICENSE: |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25
|
|
|
* THE SOFTWARE. |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
class PhpRedis extends AbstractEnhancedProvider { |
29
|
|
|
|
30
|
|
|
protected $default_properties = [ |
31
|
|
|
"server" => '127.0.0.1', |
32
|
|
|
"port" => 6379, |
33
|
|
|
"timeout" => 0, |
34
|
|
|
"password" => null |
35
|
|
|
]; |
36
|
|
|
|
37
|
28 |
|
public function __construct(array $properties = [], LoggerInterface $logger = null) { |
38
|
|
|
|
39
|
28 |
|
parent::__construct($properties, $logger); |
40
|
|
|
|
41
|
28 |
|
$properties = $this->getProperties(); |
42
|
|
|
|
43
|
28 |
|
if ( empty($properties->server) ) { |
44
|
|
|
throw new InvalidCacheArgumentException("Invalid or unspecified memcached server"); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
28 |
|
$port = DataFilter::filterPort($properties->port, 6379); |
|
|
|
|
48
|
28 |
|
$timeout = DataFilter::filterInteger($properties->timeout, 0, PHP_INT_MAX, 0); |
|
|
|
|
49
|
|
|
|
50
|
|
|
try { |
51
|
|
|
|
52
|
28 |
|
$this->driver = new PhpRedisDriver([ |
53
|
28 |
|
'server' => $properties->server, |
54
|
28 |
|
'port' => $port, |
55
|
28 |
|
'timeout' => $timeout, |
56
|
28 |
|
'password' => $properties->password |
57
|
|
|
]); |
58
|
|
|
|
59
|
28 |
|
$this->test(); |
60
|
|
|
|
61
|
|
|
} catch (Exception $e) { |
62
|
|
|
|
63
|
|
|
throw new CacheException($e->getMessage()); |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
28 |
|
} |
68
|
|
|
|
69
|
|
|
public function getInstance() { |
70
|
|
|
return $this->driver->getInstance(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
1 |
|
public function getStats() { |
77
|
|
|
|
78
|
1 |
|
$info = $this->driver->stats(); |
79
|
|
|
|
80
|
1 |
|
return new EnhancedCacheItemPoolStats( |
81
|
1 |
|
$this->getId(), |
82
|
1 |
|
$this->driver->getName(), |
83
|
1 |
|
$this->getState(), |
84
|
1 |
|
$info['objects'], |
85
|
1 |
|
$info['stats'] |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
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