|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hamburgscleanest\GuzzleAdvancedThrottle\Cache\Adapters; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use hamburgscleanest\GuzzleAdvancedThrottle\Cache\Interfaces\StorageInterface; |
|
7
|
|
|
use hamburgscleanest\GuzzleAdvancedThrottle\RequestInfo; |
|
8
|
|
|
use Illuminate\Cache\CacheManager; |
|
9
|
|
|
use Illuminate\Container\Container; |
|
|
|
|
|
|
10
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class LaravelAdapter |
|
14
|
|
|
* @package hamburgscleanest\GuzzleAdvancedThrottle\Cache\Adapters |
|
15
|
|
|
*/ |
|
16
|
|
|
class LaravelAdapter implements StorageInterface |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** @var CacheManager */ |
|
20
|
|
|
private $_cacheManager; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
|
|
$container = new Container(); |
|
25
|
|
|
|
|
26
|
|
|
// TODO: Set from outside.. |
|
27
|
|
|
$container['config'] = [ |
|
28
|
|
|
'cache.default' => 'file', |
|
29
|
|
|
'cache.stores.file' => [ |
|
30
|
|
|
'driver' => 'file', |
|
31
|
|
|
'path' => __DIR__ . '/cache' |
|
32
|
|
|
] |
|
33
|
|
|
]; |
|
34
|
|
|
$container['files'] = new Filesystem(); // TODO: Remove when config extracted.. |
|
35
|
|
|
|
|
36
|
|
|
$this->_cacheManager = new CacheManager($container); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $host |
|
41
|
|
|
* @param string $key |
|
42
|
|
|
* @param int $requestCount |
|
43
|
|
|
* @param DateTime $expiresAt |
|
44
|
|
|
* @param int $remainingSeconds |
|
45
|
|
|
*/ |
|
46
|
|
|
public function save(string $host, string $key, int $requestCount, DateTime $expiresAt, int $remainingSeconds) : void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->_cacheManager->put( |
|
49
|
|
|
$this->_buildKey($host, $key), |
|
50
|
|
|
RequestInfo::create($requestCount, $expiresAt->getTimestamp(), $remainingSeconds), |
|
51
|
|
|
$remainingSeconds |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $host |
|
57
|
|
|
* @param string $key |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
private function _buildKey(string $host, string $key) : string |
|
61
|
|
|
{ |
|
62
|
|
|
return $host . '.' . $key; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $host |
|
67
|
|
|
* @param string $key |
|
68
|
|
|
* @return RequestInfo|null |
|
69
|
|
|
*/ |
|
70
|
|
|
public function get(string $host, string $key) : ? RequestInfo |
|
71
|
|
|
{ |
|
72
|
|
|
/** @noinspection PhpIncompatibleReturnTypeInspection */ |
|
73
|
|
|
return $this->_cacheManager->get($this->_buildKey($host, $key)); |
|
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
} |
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