Skip to content

Commit 74a9aac

Browse files
committed
Merge pull request #2 from bjori/split-classes
Split API classes and interfaces
2 parents 080dcb2 + 894051f commit 74a9aac

23 files changed

+1107
-116
lines changed

docs/api/MongoDB/CRUD.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

docs/api/MongoDB/Command/Command.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace MongoDB\Command;
4+
5+
/**
6+
* Value object for a database command document.
7+
*/
8+
final class Command
9+
{
10+
private $document;
11+
12+
/**
13+
* @param array|object $document Command document
14+
*/
15+
public function __construct($document)
16+
{
17+
$this->document = $document;
18+
}
19+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace MongoDB\Command;
4+
5+
use MongoDB\Cursor;
6+
use MongoDB\CursorId;
7+
8+
/**
9+
* Cursor implementation that may be constructed from values found in a
10+
* CommandResult's response document.
11+
*
12+
* The iteration and internal logic is very similar to QueryCursor, so both
13+
* classes should likely share code. The first batch is comparable to the
14+
* documents found in the OP_REPLY message returned by a QueryCursor's original
15+
* OP_QUERY, in that both may be available at the time the cursor is
16+
* constructed.
17+
*/
18+
final class CommandCursor implements Cursor
19+
{
20+
private $server;
21+
private $batchSize;
22+
private $cursorId;
23+
private $firstBatch;
24+
25+
/**
26+
* @param Server $server
27+
* @param CursorId $cursorId
28+
* @param array $firstBatch
29+
*/
30+
public function __construct(Server $server, CursorId $cursorId, array $firstBatch)
31+
{
32+
$this->server = $server;
33+
$this->cursorId = $cursorId;
34+
$this->firstBatch = $firstBatch;
35+
}
36+
37+
// Iterator methods...
38+
39+
/**
40+
* @return Cursor::getId()
41+
*/
42+
public function getId()
43+
{
44+
return $this->cursorId;
45+
}
46+
47+
/**
48+
* @see Cursor::getServer()
49+
*/
50+
public function getServer()
51+
{
52+
return $this->server;
53+
}
54+
55+
/**
56+
* @see Cursor::isDead()
57+
*/
58+
public function isDead()
59+
{
60+
// Return whether the cursor is exhausted and has no more results
61+
}
62+
63+
/**
64+
* @see \MongoDB\Cursor::setBatchSize()
65+
*/
66+
public function setBatchSize($batchSize)
67+
{
68+
$this->batchSize = (integer) $batchSize;
69+
}
70+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace MongoDB\Command;
4+
5+
use MongoDB\Server;
6+
7+
/**
8+
* Result returned by Server and Manager executeCommand() methods.
9+
*/
10+
final class CommandResult
11+
{
12+
private $server;
13+
private $responseDocument;
14+
15+
/**
16+
* @param Server $server
17+
* @param array|object $responseDocument
18+
*/
19+
public function __construct(Server $server, $responseDocument)
20+
{
21+
$this->server = $server;
22+
$this->responseDocument = $responseDocument;
23+
}
24+
25+
/**
26+
* @return array Original response document from the server
27+
*/
28+
public function getResponseDocument()
29+
{
30+
return $this->responseDocument;
31+
}
32+
33+
/**
34+
* @return Server Server from which the result originated
35+
*/
36+
public function getServer()
37+
{
38+
return $this->server;
39+
}
40+
}

docs/api/MongoDB/Cursor.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace MongoDB;
4+
5+
interface Cursor extends \Iterator
6+
{
7+
/**
8+
* @return CursorId
9+
*/
10+
function getId();
11+
12+
/**
13+
* @return Server Server from which the cursor originated
14+
*/
15+
function getServer();
16+
17+
/**
18+
* @return boolean Whether the cursor is exhausted and has no more results
19+
*/
20+
function isDead();
21+
22+
/**
23+
* @param integer $batchSize
24+
*/
25+
function setBatchSize($batchSize);
26+
}

docs/api/MongoDB/CursorId.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace MongoDB;
4+
5+
/**
6+
* Value object for the 64-bit cursor identifier.
7+
*
8+
* This is useful for compatibility with 32-bit platforms, and also allows
9+
* Cursor constructors to type-hint against a class.
10+
*/
11+
final class CursorId
12+
{
13+
// $id is an internal uint64_t value instead of a class property
14+
15+
/**
16+
* @param integer|string $id
17+
*/
18+
public function __construct($id)
19+
{
20+
// Set internal uint64_t value
21+
}
22+
23+
/**
24+
* @return string
25+
*/
26+
public function __toString()
27+
{
28+
/* Return string representation of internal uint64_t value.
29+
*
30+
* This can be used to compare two CursorIds on a 32-bit platform. Is
31+
* this functionality necessary, or should we do without any "getter"
32+
* method?
33+
*/
34+
}
35+
}

docs/api/MongoDB/Management.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)