Issues (37)

LoggerCache.php (1 issue)

1
<?php
2
3
namespace WebStream\Log;
4
5
use WebStream\Cache\Driver\ICache;
0 ignored issues
show
The type WebStream\Cache\Driver\ICache was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * LoggerCache
9
 * @author Ryuichi Tanaka
10
 * @since 2016/05/23
11
 * @version 0.7
12
 */
13
class LoggerCache
14
{
15
    /**
16
     * @var ICache キャッシュドライバ
17
     */
18
    private ICache $driver;
19
20
    /**
21
     * @var string キャッシュキー
22
     */
23
    private $key;
24
25
    /**
26
     * @var int キャッシュインデックス
27
     */
28
    private int $index;
29
30
    /**
31
     * constructor
32 142
     * @param ICache $driver キャッシュドライバ
33
     */
34 142
    public function __construct(ICache $driver)
35 142
    {
36 142
        $this->driver = $driver;
37 142
        $this->key = md5(get_class($this));
38
        $this->index = 0;
39
    }
40
41
    /**
42 1
     * destructor
43
     */
44 1
    public function __destruct()
45 1
    {
46
        $this->clear();
47
    }
48
49
    /**
50
     * キャッシュに追加
51 96
     * @param string $content キャッシュデータ
52
     */
53 96
    public function add(string $content)
54 96
    {
55
        $this->driver->add($this->key . $this->index++, $content);
56
    }
57
58
    /**
59
     * キャッシュを返却する
60 1
     * @return array<string> キャッシュデータ
61
     */
62 1
    public function get()
63 1
    {
64 1
        $list = [];
65
        for ($i = 0; $i < $this->index; $i++) {
66
            $list[] = $this->driver->get($this->key . $i);
67 1
        }
68
69
        return $list;
70
    }
71
72
    /**
73
     * キャッシュデータ数を返却する
74 96
     * @return int キャッシュデータ数
75
     */
76 96
    public function length()
77
    {
78
        return $this->index;
79
    }
80
81
    /**
82
     * キャッシュクリア
83
     */
84
    public function clear()
85
    {
86
        $this->driver->clear();
87
    }
88
}
89