diff --git a/docs/api/MongoDB/CRUD.php b/docs/api/MongoDB/CRUD.php deleted file mode 100644 index af9453aec..000000000 --- a/docs/api/MongoDB/CRUD.php +++ /dev/null @@ -1,61 +0,0 @@ -documents[] = $document; - } -} - -class UpdateBatch implements WriteBatch { - function add($document) { - $this->documents[] = $document; - } -} - -class DeleteBatch implements WriteBatch { - function add($document) { - $this->documents[] = $document; - } -} - -class Query { - function __construct($query) {} -} -class Command { - function __construct($command) {} -} - - - - -class WriteResults { - - /* Returns nModified, n, nUserted, .. */ - function getNumbers() { - } - - /* Returns how many operations were executed */ - function getOpCount() { - } - - /* Returns the server that the operation was executed on */ - function getServer() { - } - - /* Any stats available from the server */ - function getTimer() { - } -} - -class QueryResults { - function __construct(Server $server, $cursor_id, $firstBatch) { - } -} - - diff --git a/docs/api/MongoDB/Command/Command.php b/docs/api/MongoDB/Command/Command.php new file mode 100644 index 000000000..8b7af5471 --- /dev/null +++ b/docs/api/MongoDB/Command/Command.php @@ -0,0 +1,19 @@ +document = $document; + } +} diff --git a/docs/api/MongoDB/Command/CommandCursor.php b/docs/api/MongoDB/Command/CommandCursor.php new file mode 100644 index 000000000..17364580a --- /dev/null +++ b/docs/api/MongoDB/Command/CommandCursor.php @@ -0,0 +1,70 @@ +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; + } +} diff --git a/docs/api/MongoDB/Command/CommandResult.php b/docs/api/MongoDB/Command/CommandResult.php new file mode 100644 index 000000000..013102bb5 --- /dev/null +++ b/docs/api/MongoDB/Command/CommandResult.php @@ -0,0 +1,40 @@ +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; + } +} diff --git a/docs/api/MongoDB/Cursor.php b/docs/api/MongoDB/Cursor.php new file mode 100644 index 000000000..c920a281c --- /dev/null +++ b/docs/api/MongoDB/Cursor.php @@ -0,0 +1,26 @@ +getConnectedServers() as $server) { - if ($server->matchesReadPreference($rp)) { - return $server->executeQuery($namespace, $query); - } - } - throw new NoServerMatchingReadPreference($rp); - } - - final function executeWrite($namespace, \MongoDB\WriteBatch $batch, WriteOptions $wo) { - foreach($this->getConnectedServers() as $server) { - if ($server->isPrimary()) { - return $server->executeWrite($namespace, $batch, $wo); - } - } - - throw new NoPrimaryAvailable; - } -} - diff --git a/docs/api/MongoDB/Manager.php b/docs/api/MongoDB/Manager.php new file mode 100644 index 000000000..2494d31da --- /dev/null +++ b/docs/api/MongoDB/Manager.php @@ -0,0 +1,175 @@ +query = $query; + $this->selector = $selector; + $this->flags = (integer) $flags; + $this->skip = (integer) $skip; + $this->limit = (integer) $limit; + } +} diff --git a/docs/api/MongoDB/Query/QueryCursor.php b/docs/api/MongoDB/Query/QueryCursor.php new file mode 100644 index 000000000..a06ece593 --- /dev/null +++ b/docs/api/MongoDB/Query/QueryCursor.php @@ -0,0 +1,66 @@ +server = $server; + $this->cursorId = $cursorId; + } + + // Iterator methods... + + /** + * @see 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 Cursor::setBatchSize() + */ + public function setBatchSize($batchSize) + { + $this->batchSize = (integer) $batchSize; + } +} diff --git a/docs/api/MongoDB/ReadPreference.php b/docs/api/MongoDB/ReadPreference.php new file mode 100644 index 000000000..69201aa76 --- /dev/null +++ b/docs/api/MongoDB/ReadPreference.php @@ -0,0 +1,28 @@ +readPreference = (string) $readPreference; + $this->tagSets = $tagSets; + } +} diff --git a/docs/api/MongoDB/Server.php b/docs/api/MongoDB/Server.php new file mode 100644 index 000000000..3074d260a --- /dev/null +++ b/docs/api/MongoDB/Server.php @@ -0,0 +1,190 @@ +host = (string) $host; + $this->port = (integer) $port; + $this->options = $options; + $this->driverOptions = $driverOptions; + + /* Server connections may use a persistent socket connection. Sockets + * will need to be hashed by all relevant arguments, which likely means + * all of Server's constructor arguments. Argument arrays will need to + * be normalized before we compute the hash (i.e. option order shouldn't + * matter). + * + * Actual socket connections should be created lazily. + */ + } + + /** + * @param string $db + * @param Command $command + * @return CommandResult + */ + public function executeCommand($db, Command $command) + { + /* This method does not take a ReadPreference. If connected to mongos, + * it the user's responsibility to set a read preference on the command + * document (if applicable). + */ + } + + /** + * @param string $namespace + * @param Query $query + * @return QueryCursor + */ + public function executeQuery($namespace, Query $query) + { + /* This method does not take a ReadPreference. If connected to mongos, + * it the user's responsibility to set a read preference on the command + * document (if applicable). + */ + } + + /** + * @param string $namespace + * @param WriteBatch $batch + * @return WriteResult + */ + public function executeWrite($namespace, WriteBatch $batch) + { + /* Write options are not taken as an argument, since they are specified + * during WriteBatch construction. + * + * On error, we should consider throwing: + * + * - WriteException: write failed; a WriteResult should be included. + * - ConnectionException: low-level socket error + * + * If a WriteException is thrown, its WriteResult may contain multiple + * write errors and write concern errors. + * + * What exception is used for sending a write to a secondary? Would that + * be a WriteException without a WriteResult attached? + */ + } + + public function getHost() + { + /* This does not return the host name from isMaster, since the "me" + * field is only present in replica set connections. There is also less + * value in providing the driver with the host name by which the server + * identifies (vs. the host name used to connect to it). + */ + return $this->host; + } + + /** + * @return array Connection metadata (e.g. min/maxWireVersion, RS hosts) + */ + public function getInfo() + { + // Return last isMaster result document + } + + /** + * @return integer Server latency in milliseconds + */ + public function getLatency() + { + // Return last ping time in milliseconds (calculated value) + } + + /** + * @return integer + */ + public function getPort() + { + return $this->port; + } + + /** + * @see http://docs.mongodb.org/manual/reference/replica-states/ + * @return integer Replica set node state + */ + public function getState() + { + /* Return the replica set node's state via replSetGetStatus + * + * We may want to create class constants for documented states. + * + * What should this return if the node isn't in a replica set? + */ + } + + /** + * @return integer Server type code + */ + public function getType() + { + /* Return the server's current type code. + * + * The fact that Servers are mutable and this return value is subject to + * change is not a problem, as libmongoc should have its own snapshot of + * the cluster topology for evaluating read preferences. + */ + } + + public function isDelayed() + { + /* Return whether the secondary is delayed. + * + * What should this return for a node that isn't in a replica set? Isn't + * the actual delay time more useful than a boolean? This isn't reported + * in isMaster, so how do we calculate this short of reading the replica + * set configuration? + */ + } + + public function isPassive() + { + /* Return inferred value from isMaster data. + * + * Is this really useful in light of getInfo(), which provides the same + * information, and more? + */ + } +} diff --git a/docs/api/MongoDB/Write/DeleteBatch.php b/docs/api/MongoDB/Write/DeleteBatch.php new file mode 100644 index 000000000..177145b7b --- /dev/null +++ b/docs/api/MongoDB/Write/DeleteBatch.php @@ -0,0 +1,27 @@ +documents[] = $document; + } + + /** + * @see Countable::count() + */ + public function count() + { + return count($this->documents); + } +} diff --git a/docs/api/MongoDB/Write/DeleteResult.php b/docs/api/MongoDB/Write/DeleteResult.php new file mode 100644 index 000000000..9b0fb215c --- /dev/null +++ b/docs/api/MongoDB/Write/DeleteResult.php @@ -0,0 +1,38 @@ +id = $id; + $this->index = (integer) $index; + } + + /** + * @return mixed Document identifier + */ + public function getId() + { + return $this->id; + } + + /** + * @return integer Batch index of the corresponding operation + */ + public function getIndex() + { + return $this->index; + } +} diff --git a/docs/api/MongoDB/Write/InsertBatch.php b/docs/api/MongoDB/Write/InsertBatch.php new file mode 100644 index 000000000..a811008e5 --- /dev/null +++ b/docs/api/MongoDB/Write/InsertBatch.php @@ -0,0 +1,27 @@ +documents[] = $document; + } + + /** + * @see Countable::count() + */ + public function count() + { + return count($this->documents); + } +} diff --git a/docs/api/MongoDB/Write/InsertResult.php b/docs/api/MongoDB/Write/InsertResult.php new file mode 100644 index 000000000..fc01261db --- /dev/null +++ b/docs/api/MongoDB/Write/InsertResult.php @@ -0,0 +1,50 @@ +documents[] = $document; + } + + /** + * @see Countable::count() + */ + public function count() + { + return count($this->documents); + } +} diff --git a/docs/api/MongoDB/Write/UpdateResult.php b/docs/api/MongoDB/Write/UpdateResult.php new file mode 100644 index 000000000..cb5730e28 --- /dev/null +++ b/docs/api/MongoDB/Write/UpdateResult.php @@ -0,0 +1,58 @@ +message = (string) $message; + $this->code = (integer) $code; + $this->info = $info; + } + + /** + * @return integer Server error code + */ + public function getCode() + { + return $this->code; + } + + /** + * @return array Additional metadata for the error (e.g. {"wtimeout": true}) + */ + public function getInfo() + { + return $this->info; + } + + /** + * @return string Server error message + */ + public function getMessage() + { + return $this-message; + } +} diff --git a/docs/api/MongoDB/Write/WriteError.php b/docs/api/MongoDB/Write/WriteError.php new file mode 100644 index 000000000..497cc52fd --- /dev/null +++ b/docs/api/MongoDB/Write/WriteError.php @@ -0,0 +1,60 @@ +message = (string) $message; + $this->code = (integer) $code; + $this->index = (integer) $index; + $this->operation = $operation; + } + + /** + * @return integer Server error code + */ + public function getCode() + { + return $this->code; + } + + /** + * @return integer Batch index of the error + */ + public function getIndex() + { + return $this->index; + } + + /** + * @return string Server error message + */ + public function getMessage() + { + return $this-message; + } + + /** + * @return array|object Operation or document responsible for the error + */ + public function getOperation() + { + return $this->operation; + } +} diff --git a/docs/api/MongoDB/Write/WriteResult.php b/docs/api/MongoDB/Write/WriteResult.php new file mode 100644 index 000000000..946b964a1 --- /dev/null +++ b/docs/api/MongoDB/Write/WriteResult.php @@ -0,0 +1,27 @@ +