-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
CacheEntryIterator.php
109 lines (98 loc) · 2.33 KB
/
CacheEntryIterator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
namespace Neos\Cache\Frontend;
/*
* This file is part of the Neos.Cache package.
*
* (c) Contributors of the Neos Project - www.neos.io
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Cache\Backend\IterableBackendInterface;
/**
* An iterator for cache entries
*
* @api
*/
class CacheEntryIterator implements \Iterator
{
/**
* @var FrontendInterface
*/
protected $frontend;
/**
* @var IterableBackendInterface
*/
protected $backend;
/**
* Constructs this Iterator
*
* @param FrontendInterface $frontend Frontend of the cache to iterate over
* @param IterableBackendInterface $backend Backend of the cache
*/
public function __construct(FrontendInterface $frontend, IterableBackendInterface $backend)
{
$this->frontend = $frontend;
$this->backend = $backend;
$this->backend->rewind();
}
/**
* Returns the data of the current cache entry pointed to by the cache entry
* iterator.
*
* @return mixed
* @api
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->frontend->get((string) $this->backend->key());
}
/**
* Move forward to the next cache entry
*
* @return void
* @api
*/
#[\ReturnTypeWillChange]
public function next()
{
$this->backend->next();
}
/**
* Returns the identifier of the current cache entry pointed to by the cache
* entry iterator.
*
* @return string
* @api
*/
#[\ReturnTypeWillChange]
public function key(): string
{
return (string) $this->backend->key();
}
/**
* Checks if current position of the cache entry iterator is valid
*
* @return boolean true if the current element of the iterator is valid, otherwise false
* @api
*/
#[\ReturnTypeWillChange]
public function valid(): bool
{
return $this->backend->valid();
}
/**
* Rewind the cache entry iterator to the first element
*
* @return void
* @api
*/
#[\ReturnTypeWillChange]
public function rewind()
{
$this->backend->rewind();
}
}