1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
use Alcaeus\MongoDbAdapter\AbstractCursor; |
17
|
|
|
use Alcaeus\MongoDbAdapter\TypeConverter; |
18
|
|
|
|
19
|
|
|
class MongoCommandCursor extends AbstractCursor implements MongoCursorInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $command; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* MongoCommandCursor constructor. |
28
|
|
|
* @param MongoClient $connection |
29
|
|
|
* @param string $ns |
30
|
|
|
* @param array $command |
31
|
|
|
*/ |
32
|
|
|
public function __construct(MongoClient $connection, $ns, array $command = []) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($connection, $ns); |
35
|
|
|
|
36
|
|
|
$this->command = $command; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param MongoClient $connection |
41
|
|
|
* @param string $hash |
42
|
|
|
* @param array $document |
43
|
|
|
* @return MongoCommandCursor |
44
|
|
|
*/ |
45
|
|
|
public static function createFromDocument(MongoClient $connection, $hash, array $document) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
throw new \Exception('Not implemented'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \MongoDB\Driver\Cursor |
52
|
|
|
*/ |
53
|
|
|
protected function ensureCursor() |
54
|
|
|
{ |
55
|
|
|
if ($this->cursor === null) { |
56
|
|
|
$convertedCommand = TypeConverter::fromLegacy($this->command); |
57
|
|
|
if (isset($convertedCommand->cursor)) { |
58
|
|
|
if ($convertedCommand->cursor === true || $convertedCommand->cursor === []) { |
59
|
|
|
$convertedCommand->cursor = new \stdClass(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->cursor = $this->db->command($convertedCommand, $this->getOptions()); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this->cursor; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function getCursorInfo() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
'ns' => $this->ns, |
76
|
|
|
'limit' => 0, |
77
|
|
|
'batchSize' => $this->batchSize, |
78
|
|
|
'skip' => 0, |
79
|
|
|
'flags' => 0, |
80
|
|
|
'query' => $this->command, |
81
|
|
|
'fields' => null, |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
protected function getIterationInfo() |
89
|
|
|
{ |
90
|
|
|
$iterationInfo = parent::getIterationInfo(); |
91
|
|
|
|
92
|
|
|
if ($iterationInfo['started_iterating']) { |
93
|
|
|
$iterationInfo += [ |
94
|
|
|
'firstBatchAt' => $iterationInfo['at'], |
95
|
|
|
'firstBatchNumReturned' => $iterationInfo['numReturned'], |
96
|
|
|
]; |
97
|
|
|
$iterationInfo['at'] = 0; |
98
|
|
|
$iterationInfo['numReturned'] = 0; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return $iterationInfo; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function __sleep() |
108
|
|
|
{ |
109
|
|
|
return ['command'] + parent::__sleep(); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.