-
Notifications
You must be signed in to change notification settings - Fork 208
Split API classes and interfaces #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cd2d37e
Split API classes and interfaces
jmikola 749b2d3
Implement review feedback
jmikola 1cfb4d2
Add cursor flag constants
jmikola bf4ec13
Command execution takes a database name, not a namespace
jmikola 894051f
Specity write options in execute methods, not batch constructors
jmikola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace MongoDB\Command; | ||
|
||
/** | ||
* Value object for a database command document. | ||
*/ | ||
final class Command | ||
{ | ||
private $document; | ||
|
||
/** | ||
* @param array|object $document Command document | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want to have this as both array and object again? |
||
*/ | ||
public function __construct($document) | ||
{ | ||
$this->document = $document; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace MongoDB\Command; | ||
|
||
use MongoDB\Cursor; | ||
use MongoDB\CursorId; | ||
|
||
/** | ||
* Cursor implementation that may be constructed from values found in a | ||
* CommandResult's response document. | ||
* | ||
* The iteration and internal logic is very similar to QueryCursor, so both | ||
* classes should likely share code. The first batch is comparable to the | ||
* documents found in the OP_REPLY message returned by a QueryCursor's original | ||
* OP_QUERY, in that both may be available at the time the cursor is | ||
* constructed. | ||
*/ | ||
final class CommandCursor implements Cursor | ||
{ | ||
private $server; | ||
private $batchSize; | ||
private $cursorId; | ||
private $firstBatch; | ||
|
||
/** | ||
* @param Server $server | ||
* @param CursorId $cursorId | ||
* @param array $firstBatch | ||
*/ | ||
public function __construct(Server $server, CursorId $cursorId, array $firstBatch) | ||
{ | ||
$this->server = $server; | ||
$this->cursorId = $cursorId; | ||
$this->firstBatch = $firstBatch; | ||
} | ||
|
||
// Iterator methods... | ||
|
||
/** | ||
* @return Cursor::getId() | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->cursorId; | ||
} | ||
|
||
/** | ||
* @see Cursor::getServer() | ||
*/ | ||
public function getServer() | ||
{ | ||
return $this->server; | ||
} | ||
|
||
/** | ||
* @see Cursor::isDead() | ||
*/ | ||
public function isDead() | ||
{ | ||
// Return whether the cursor is exhausted and has no more results | ||
} | ||
|
||
/** | ||
* @see \MongoDB\Cursor::setBatchSize() | ||
*/ | ||
public function setBatchSize($batchSize) | ||
{ | ||
$this->batchSize = (integer) $batchSize; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace MongoDB\Command; | ||
|
||
use MongoDB\Server; | ||
|
||
/** | ||
* Result returned by Server and Manager executeCommand() methods. | ||
*/ | ||
final class CommandResult | ||
{ | ||
private $server; | ||
private $responseDocument; | ||
|
||
/** | ||
* @param Server $server | ||
* @param array|object $responseDocument | ||
*/ | ||
public function __construct(Server $server, $responseDocument) | ||
{ | ||
$this->server = $server; | ||
$this->responseDocument = $responseDocument; | ||
} | ||
|
||
/** | ||
* @return array Original response document from the server | ||
*/ | ||
public function getResponseDocument() | ||
{ | ||
return $this->responseDocument; | ||
} | ||
|
||
/** | ||
* @return Server Server from which the result originated | ||
*/ | ||
public function getServer() | ||
{ | ||
return $this->server; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace MongoDB; | ||
|
||
interface Cursor extends \Iterator | ||
{ | ||
/** | ||
* @return CursorId | ||
*/ | ||
function getId(); | ||
|
||
/** | ||
* @return Server Server from which the cursor originated | ||
*/ | ||
function getServer(); | ||
|
||
/** | ||
* @return boolean Whether the cursor is exhausted and has no more results | ||
*/ | ||
function isDead(); | ||
|
||
/** | ||
* @param integer $batchSize | ||
*/ | ||
function setBatchSize($batchSize); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace MongoDB; | ||
|
||
/** | ||
* Value object for the 64-bit cursor identifier. | ||
* | ||
* This is useful for compatibility with 32-bit platforms, and also allows | ||
* Cursor constructors to type-hint against a class. | ||
*/ | ||
final class CursorId | ||
{ | ||
// $id is an internal uint64_t value instead of a class property | ||
|
||
/** | ||
* @param integer|string $id | ||
*/ | ||
public function __construct($id) | ||
{ | ||
// Set internal uint64_t value | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
/* Return string representation of internal uint64_t value. | ||
* | ||
* This can be used to compare two CursorIds on a 32-bit platform. Is | ||
* this functionality necessary, or should we do without any "getter" | ||
* method? | ||
*/ | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and Query do not have getter methods, since I assume their data will be accessed internally. Users shouldn't have any reason to read these objects after creating them.