-
Notifications
You must be signed in to change notification settings - Fork 1
/
result.php
96 lines (94 loc) · 1.83 KB
/
result.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
<?php
namespace ru\olamedia\kanon\mongo;
class result implements \Iterator, \Countable{
private $_className = null;
private $_cursor = null;
private $_asArray = false;
public function __construct($className,\MongoCursor $cursor){
$this->_className = $className;
$this->_cursor = $cursor;
}
/**
*
* @return \MongoCursor
*/
public function getCursor(){
return $this->_cursor;
}
/**
*
* @param boolean $asArray
* @return \ru\olamedia\kanon\mongo\result
*/
public function asArray($asArray = true){
$this->_asArray = $asArray;
return $this;
}
public function count($foundOnly = false){
return $this->_cursor->count($foundOnly);
}
/**
*
* @param string $fieldName
* @return \ru\olamedia\kanon\mongo\result
*/
public function asc($fieldName){
$this->_cursor->sort([
$fieldName => 1
]);
return $this;
}
/**
*
* @param string $fieldName
* @return \ru\olamedia\kanon\mongo\result
*/
public function desc($fieldName){
$this->_cursor->sort([
$fieldName => -1
]);
return $this;
}
public function sort(array $fields){
$this->_cursor->sort($fields);
return $this;
}
public function skip($num){
$this->_cursor->skip($num);
return $this;
}
public function limit($num){
$this->_cursor->limit($num);
return $this;
}
private function _pack($data = []){
if (null === $data){
return null;
}
if ($this->_asArray){
return $data;
}
$className = $this->_className;
return new $className($data);
}
// Iterator
public function rewind(){
$this->_cursor->rewind();
}
public function current(){
return $this->_pack($this->_cursor->current());
}
/**
*
* @return string
*/
public function key(){
return $this->_cursor->key();
}
public function next(){
return $this->_pack($this->_cursor->next());
}
public function valid(){
return $this->_cursor->valid();
}
}