mirror of
https://github.com/macintoshplus/mongo-php-driver.git
synced 2026-04-25 09:28:18 +02:00
Split API classes and interfaces
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
namespace MongoDB;
|
||||
|
||||
interface WriteBatch {
|
||||
function add($document);
|
||||
}
|
||||
|
||||
|
||||
class InsertBatch implements WriteBatch {
|
||||
function add($document) {
|
||||
$this->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) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Command;
|
||||
|
||||
final class Command
|
||||
{
|
||||
/**
|
||||
* @param array|object $document Command document
|
||||
*/
|
||||
public function __construct($document)
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Command;
|
||||
|
||||
// Note: consider combining implementation with \MongoDB\Query\QueryCursor
|
||||
final class CommandCursor implements \MongoDB\Cursor
|
||||
{
|
||||
private $server;
|
||||
private $batchSize;
|
||||
private $cursorId;
|
||||
private $firstBatch;
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @param integer $cursorId
|
||||
* @param array $firstBatch
|
||||
*/
|
||||
public function __construct(Server $server, $cursorId, array $firstBatch)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Command;
|
||||
|
||||
interface CommandResult extends \MongoDB\ServerResult
|
||||
{
|
||||
/**
|
||||
* @return array Original response document from the server
|
||||
*/
|
||||
function getResponse();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB;
|
||||
|
||||
interface Cursor extends ServerResult, \Iterator
|
||||
{
|
||||
/**
|
||||
* @return integer Cursor identifier
|
||||
*/
|
||||
function getId();
|
||||
|
||||
/**
|
||||
* @param integer $batchSize
|
||||
*/
|
||||
function setBatchSize($batchSize);
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
namespace MongoDB;
|
||||
|
||||
class Server {
|
||||
const TYPE_MONGOS = 0x01;
|
||||
const TYPE_STANDALONE = 0x02;
|
||||
const TYPE_ARBITER = 0x03;
|
||||
const TYPE_SECONDARY = 0x04;
|
||||
const TYPE_PRIMARY = 0x05;
|
||||
|
||||
/* These need to be final as they will not be called by the driver to retrieve the
|
||||
* information, these getters are only useful for userland */
|
||||
final function getHostname() {}
|
||||
final function getPort() {}
|
||||
final function getLatency() {}
|
||||
final function getMaxWireVersion() {}
|
||||
final function getMinWireVersion() {}
|
||||
final function getServerType() {}
|
||||
|
||||
/* extracting config info */
|
||||
final function isPassive() {}
|
||||
final function isDelayed() {}
|
||||
|
||||
final function executeQuery($namespace, \MongoDB\Query $query) {}
|
||||
final function executeWrite($namespace, \MongoDB\WriteBatch $batch, WriteOptions $wo) {}
|
||||
}
|
||||
|
||||
|
||||
class Manager extends \SplObjectStorage {
|
||||
function __construct(array $servers, $dbname, $connection_options) {
|
||||
}
|
||||
|
||||
static function fromDSN($dsn) {
|
||||
}
|
||||
|
||||
final function executeQuery($namespace, \MongoDB\Query $query, 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, WriteOptions $wo) {
|
||||
foreach($this->getConnectedServers() as $server) {
|
||||
if ($server->isPrimary()) {
|
||||
return $server->executeWrite($namespace, $batch, $wo);
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoPrimaryAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB;
|
||||
|
||||
final class Manager extends \SplObjectStorage
|
||||
{
|
||||
/**
|
||||
* @param Server[] $servers
|
||||
* @param string $db Database name
|
||||
* @param array $options Connection options
|
||||
*/
|
||||
public function __construct(array $servers, $db, $options)
|
||||
{
|
||||
}
|
||||
|
||||
static public function fromDSN($dsn)
|
||||
{
|
||||
}
|
||||
|
||||
final public function executeCommand($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 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Query;
|
||||
|
||||
final class Query
|
||||
{
|
||||
/**
|
||||
* @param array|object $query Query document
|
||||
* @param array|object $selector Selector document
|
||||
* @param integer $flags Query flags
|
||||
* @param integer $limit Limit
|
||||
* @param integer $skip Skip
|
||||
*/
|
||||
public function __construct($query, $selector, $flags, $skip, $limit)
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Query;
|
||||
|
||||
// Note: consider combining implementation with \MongoDB\Command\CommandCursor
|
||||
final class QueryCursor implements \MongoDB\Cursor
|
||||
{
|
||||
private $server;
|
||||
private $batchSize;
|
||||
private $cursorId;
|
||||
|
||||
/**
|
||||
* @param Server $server
|
||||
* @param integer $cursorId
|
||||
*/
|
||||
public function __construct(Server $server, $cursorId)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Query;
|
||||
|
||||
interface QueryResult extends \MongoDB\ServerResult, \Traversable
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB;
|
||||
|
||||
class Server
|
||||
{
|
||||
const TYPE_MONGOS = 0x01;
|
||||
const TYPE_STANDALONE = 0x02;
|
||||
const TYPE_ARBITER = 0x03;
|
||||
const TYPE_SECONDARY = 0x04;
|
||||
const TYPE_PRIMARY = 0x05;
|
||||
|
||||
/* These need to be final as they will not be called by the driver to
|
||||
* retrieve the information; these getters are only useful for userland.
|
||||
*/
|
||||
final public function getHostname() {}
|
||||
final public function getPort() {}
|
||||
final public function getLatency() {}
|
||||
final public function getMaxWireVersion() {}
|
||||
final public function getMinWireVersion() {}
|
||||
final public function getServerType() {}
|
||||
|
||||
// extracting config info
|
||||
final public function isPassive() {}
|
||||
final public function isDelayed() {}
|
||||
|
||||
final public function executeCommand($namespace, \MongoDB\Command\Command $command, \MongoDB\ReadPreference $rp) {}
|
||||
final public function executeQuery($namespace, \MongoDB\Query\Query $query, \MongoDB\ReadPreference $rp) {}
|
||||
final public function executeWrite($namespace, \MongoDB\Write\WriteBatch $batch, \MongoDB\WriteOptions $wo) {}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB;
|
||||
|
||||
interface ServerError extends ServerResult
|
||||
{
|
||||
/**
|
||||
* @return integer Server error code
|
||||
*/
|
||||
function getCode();
|
||||
|
||||
/**
|
||||
* @return string Server error message
|
||||
*/
|
||||
function getMessage();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB;
|
||||
|
||||
interface ServerResult
|
||||
{
|
||||
/**
|
||||
* @return Server Server on which the result originated
|
||||
*/
|
||||
function getServer();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface BulkResult extends InsertResult, UpdateResult, DeleteResult
|
||||
{
|
||||
// Note: this interface would exist alongside Bulk API in the userland lib
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
final class DeleteBatch extends WriteBatch
|
||||
{
|
||||
private $documents;
|
||||
|
||||
/**
|
||||
* @see WriteBatch::add()
|
||||
*/
|
||||
public function add($document)
|
||||
{
|
||||
$this->documents[] = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Countable::count()
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see WriteBatch::getDocuments()
|
||||
*/
|
||||
public function getDocuments()
|
||||
{
|
||||
return $this->documents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface DeleteResult extends WriteResult
|
||||
{
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
function getNumRemoved();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
final class InsertBatch extends WriteBatch
|
||||
{
|
||||
private $documents;
|
||||
|
||||
/**
|
||||
* @see WriteBatch::add()
|
||||
*/
|
||||
public function add($document)
|
||||
{
|
||||
$this->documents[] = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Countable::count()
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see WriteBatch::getDocuments()
|
||||
*/
|
||||
public function getDocuments()
|
||||
{
|
||||
return $this->documents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface InsertResult extends WriteResult
|
||||
{
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
function getNumInserted();
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
final class UpdateBatch extends WriteBatch
|
||||
{
|
||||
private $documents;
|
||||
|
||||
/**
|
||||
* @see WriteBatch::add()
|
||||
*/
|
||||
public function add($document)
|
||||
{
|
||||
$this->documents[] = $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Countable::count()
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->documents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see WriteBatch::getDocuments()
|
||||
*/
|
||||
public function getDocuments()
|
||||
{
|
||||
return $this->documents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface UpdateResult extends WriteResult
|
||||
{
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
function getNumMatched();
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
function getNumModified();
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
function getNumUpserted();
|
||||
|
||||
/**
|
||||
* @return Upsert[]
|
||||
*/
|
||||
function getUpserts();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
final class Upsert
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
function getId();
|
||||
|
||||
/**
|
||||
* @return integer Batch index of the upsert
|
||||
*/
|
||||
function getIndex();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface WriteBatch extends \Countable
|
||||
{
|
||||
/**
|
||||
* @param array|object Operation/document to add to the batch
|
||||
*/
|
||||
function add($document);
|
||||
|
||||
/**
|
||||
* @return array Array of operations/documents in the batch
|
||||
*/
|
||||
function getDocuments();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface WriteConcernError extends \MongoDB\ServerError
|
||||
{
|
||||
/**
|
||||
* @return array Additional metadata for the error (e.g. {"wtimeout": true})
|
||||
*/
|
||||
function getInfo();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface WriteError extends \MongoDB\ServerError
|
||||
{
|
||||
/**
|
||||
* @return integer Batch index of the error
|
||||
*/
|
||||
function getIndex();
|
||||
|
||||
/**
|
||||
* @return array|object Operation or document responsible for the error
|
||||
*/
|
||||
function getOperation();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace MongoDB\Write;
|
||||
|
||||
interface WriteResult extends \MongoDB\ServerResult
|
||||
{
|
||||
/**
|
||||
* @return array Additional metadata for the operation(s) (e.g. timings)
|
||||
*/
|
||||
function getInfo();
|
||||
|
||||
/**
|
||||
* @return integer Number of operations that were executed
|
||||
*/
|
||||
function getOpCount();
|
||||
|
||||
/**
|
||||
* @return WriteError[]
|
||||
*/
|
||||
function getWriteErrors();
|
||||
|
||||
/**
|
||||
* @return WriteConcernError[]
|
||||
*/
|
||||
function getWriteConcernErrors();
|
||||
}
|
||||
Reference in New Issue
Block a user