-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSearch.php
More file actions
71 lines (54 loc) · 1.42 KB
/
Search.php
File metadata and controls
71 lines (54 loc) · 1.42 KB
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
<?php
namespace Virm\Search;
use Virm\Search\Engine\EngineInterface;
class Search implements \Iterator, \ArrayAccess
{
protected $limit = null;
/**
* @var \Virm\Search\Engine\EngineInterface
*/
protected $engine = null;
protected $start = 0;
protected $data = array();
protected $position = 0;
public function __construct(EngineInterface $engine, $limit = 10)
{
$this->engine = $engine;
$this->limit = $limit;
}
public function valid()
{
return $this->position < min($this->limit, $this->engine->getCount());
}
public function next()
{
++$this->position;
}
public function current()
{
if( ! isset($this->data[$this->position - $this->start])) {
$this->data = $this->engine->getResultSet($this->position);
$this->start = $this->position;
}
return $this->data[$this->position - $this->start];
}
public function key()
{
return $this->position;
}
public function rewind()
{
$this->position = 0;
}
public function offsetExists ($offset)
{
return $offset < min($this->limit, $this->engine->getCount());
}
public function offsetGet($offset )
{
$this->position = $offset;
return $this->current();
}
public function offsetUnset($offset) {}
public function offsetSet($offset, $value){}
}