From cd2d37ef387f7388c10fabbb3facf00bcd490551 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 12 Jun 2014 03:07:57 -0400 Subject: [PATCH] Split API classes and interfaces --- docs/api/MongoDB/CRUD.php | 61 -------------------- docs/api/MongoDB/Command/Command.php | 14 +++++ docs/api/MongoDB/Command/CommandCursor.php | 58 +++++++++++++++++++ docs/api/MongoDB/Command/CommandResult.php | 11 ++++ docs/api/MongoDB/Cursor.php | 16 +++++ docs/api/MongoDB/Management.php | 55 ------------------ docs/api/MongoDB/Manager.php | 50 ++++++++++++++++ docs/api/MongoDB/Query/Query.php | 18 ++++++ docs/api/MongoDB/Query/QueryCursor.php | 47 +++++++++++++++ docs/api/MongoDB/Query/QueryResult.php | 7 +++ docs/api/MongoDB/Server.php | 30 ++++++++++ docs/api/MongoDB/ServerError.php | 16 +++++ docs/api/MongoDB/ServerResult.php | 11 ++++ docs/api/MongoDB/Write/BulkResult.php | 8 +++ docs/api/MongoDB/Write/DeleteBatch.php | 32 ++++++++++ docs/api/MongoDB/Write/DeleteResult.php | 11 ++++ docs/api/MongoDB/Write/InsertBatch.php | 32 ++++++++++ docs/api/MongoDB/Write/InsertResult.php | 11 ++++ docs/api/MongoDB/Write/UpdateBatch.php | 32 ++++++++++ docs/api/MongoDB/Write/UpdateResult.php | 26 +++++++++ docs/api/MongoDB/Write/Upsert.php | 16 +++++ docs/api/MongoDB/Write/WriteBatch.php | 16 +++++ docs/api/MongoDB/Write/WriteConcernError.php | 11 ++++ docs/api/MongoDB/Write/WriteError.php | 16 +++++ docs/api/MongoDB/Write/WriteResult.php | 26 +++++++++ 25 files changed, 515 insertions(+), 116 deletions(-) delete mode 100644 docs/api/MongoDB/CRUD.php create mode 100644 docs/api/MongoDB/Command/Command.php create mode 100644 docs/api/MongoDB/Command/CommandCursor.php create mode 100644 docs/api/MongoDB/Command/CommandResult.php create mode 100644 docs/api/MongoDB/Cursor.php delete mode 100644 docs/api/MongoDB/Management.php create mode 100644 docs/api/MongoDB/Manager.php create mode 100644 docs/api/MongoDB/Query/Query.php create mode 100644 docs/api/MongoDB/Query/QueryCursor.php create mode 100644 docs/api/MongoDB/Query/QueryResult.php create mode 100644 docs/api/MongoDB/Server.php create mode 100644 docs/api/MongoDB/ServerError.php create mode 100644 docs/api/MongoDB/ServerResult.php create mode 100644 docs/api/MongoDB/Write/BulkResult.php create mode 100644 docs/api/MongoDB/Write/DeleteBatch.php create mode 100644 docs/api/MongoDB/Write/DeleteResult.php create mode 100644 docs/api/MongoDB/Write/InsertBatch.php create mode 100644 docs/api/MongoDB/Write/InsertResult.php create mode 100644 docs/api/MongoDB/Write/UpdateBatch.php create mode 100644 docs/api/MongoDB/Write/UpdateResult.php create mode 100644 docs/api/MongoDB/Write/Upsert.php create mode 100644 docs/api/MongoDB/Write/WriteBatch.php create mode 100644 docs/api/MongoDB/Write/WriteConcernError.php create mode 100644 docs/api/MongoDB/Write/WriteError.php create mode 100644 docs/api/MongoDB/Write/WriteResult.php diff --git a/docs/api/MongoDB/CRUD.php b/docs/api/MongoDB/CRUD.php deleted file mode 100644 index af9453ae..00000000 --- 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 00000000..ccdd45c4 --- /dev/null +++ b/docs/api/MongoDB/Command/Command.php @@ -0,0 +1,14 @@ +server = $server; + $this->cursorId = (integer) $cursorId; + $this->firstBatch = $firstBatch; + } + + // Iterator methods... + + /** + * @see \MongoDB\Cursor::getId() + */ + public function getId() + { + return $this->cursorId; + } + + /** + * @see \MongoDB\ServerResult::getServer() + */ + public function getServer() + { + return $this->server; + } + + /** + * @see \MongoDB\Cursor::setBatchSize() + */ + public function setBatchSize($batchSize) + { + $this->batchSize = (integer) $batchSize; + } + + // Note: this expects consistent command response documents from the server + static public function createFromCommandResult(CommandResult $result) + { + // extract $cursorId and $firstBatch from $result->getResponse() + + return new static($result->getServer(), $cursorId, $firstBatch); + } +} diff --git a/docs/api/MongoDB/Command/CommandResult.php b/docs/api/MongoDB/Command/CommandResult.php new file mode 100644 index 00000000..8ba37bf7 --- /dev/null +++ b/docs/api/MongoDB/Command/CommandResult.php @@ -0,0 +1,11 @@ +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 00000000..2b7d5573 --- /dev/null +++ b/docs/api/MongoDB/Manager.php @@ -0,0 +1,50 @@ +getConnectedServers() as $server) { + if ($server->matchesReadPreference($rp)) { + return $server->executeQuery($namespace, $query); + } + } + throw new NoServerMatchingReadPreference($rp); + } + + final public function executeQuery($namespace, \MongoDB\Query $query, \MongoDB\ReadPreference $rp) + { + foreach($this->getConnectedServers() as $server) { + if ($server->matchesReadPreference($rp)) { + return $server->executeQuery($namespace, $query); + } + } + throw new NoServerMatchingReadPreference($rp); + } + + final function executeWrite($namespace, \MongoDB\WriteBatch $batch, \MongoDB\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/Query/Query.php b/docs/api/MongoDB/Query/Query.php new file mode 100644 index 00000000..cd73b3e7 --- /dev/null +++ b/docs/api/MongoDB/Query/Query.php @@ -0,0 +1,18 @@ +server = $server; + $this->cursorId = (integer) $cursorId; + } + + // Iterator methods... + + /** + * @see \MongoDB\Cursor::getId() + */ + public function getId() + { + return $this->cursorId; + } + + /** + * @see \MongoDB\ServerResult::getServer() + */ + public function getServer() + { + return $this->server; + } + + /** + * @see \MongoDB\Cursor::setBatchSize() + */ + public function setBatchSize($batchSize) + { + $this->batchSize = (integer) $batchSize; + } +} diff --git a/docs/api/MongoDB/Query/QueryResult.php b/docs/api/MongoDB/Query/QueryResult.php new file mode 100644 index 00000000..79621f0d --- /dev/null +++ b/docs/api/MongoDB/Query/QueryResult.php @@ -0,0 +1,7 @@ +documents[] = $document; + } + + /** + * @see Countable::count() + */ + public function count() + { + return count($this->documents); + } + + /** + * @see WriteBatch::getDocuments() + */ + public function getDocuments() + { + return $this->documents; + } +} diff --git a/docs/api/MongoDB/Write/DeleteResult.php b/docs/api/MongoDB/Write/DeleteResult.php new file mode 100644 index 00000000..9bf41e59 --- /dev/null +++ b/docs/api/MongoDB/Write/DeleteResult.php @@ -0,0 +1,11 @@ +documents[] = $document; + } + + /** + * @see Countable::count() + */ + public function count() + { + return count($this->documents); + } + + /** + * @see WriteBatch::getDocuments() + */ + public function getDocuments() + { + return $this->documents; + } +} diff --git a/docs/api/MongoDB/Write/InsertResult.php b/docs/api/MongoDB/Write/InsertResult.php new file mode 100644 index 00000000..fe8e3082 --- /dev/null +++ b/docs/api/MongoDB/Write/InsertResult.php @@ -0,0 +1,11 @@ +documents[] = $document; + } + + /** + * @see Countable::count() + */ + public function count() + { + return count($this->documents); + } + + /** + * @see WriteBatch::getDocuments() + */ + public function getDocuments() + { + return $this->documents; + } +} diff --git a/docs/api/MongoDB/Write/UpdateResult.php b/docs/api/MongoDB/Write/UpdateResult.php new file mode 100644 index 00000000..38e7f1a9 --- /dev/null +++ b/docs/api/MongoDB/Write/UpdateResult.php @@ -0,0 +1,26 @@ +