Skip to content

Commit 58fb88f

Browse files
committed
Initial draft of suggested API
1 parent 9a075dc commit 58fb88f

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

docs/api/BSON/types.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/* C interfaces */
3+
namespace BSON\Types {
4+
interface Object {
5+
}
6+
7+
interface ArrayObj {
8+
}
9+
10+
interface ObjectID {
11+
}
12+
13+
interface Binary {
14+
const TYPE_GENERIC = 0x00;
15+
const TYPE_FUNCTION = 0x01;
16+
const TYPE_OLD_BINARY = 0x02;
17+
const TYPE_OLD_UUID = 0x03;
18+
const TYPE_UUID = 0x04;
19+
const TYPE_MD5 = 0x05;
20+
const TYPE_USER_DEFINED = 0x80;
21+
22+
function getSubType();
23+
}
24+
25+
interface DateTime {
26+
}
27+
}
28+
29+
/* C objects */
30+
namespace BSON {
31+
32+
class Object implements \BSON\Types\Object {
33+
}
34+
35+
class ArrayDynamic extends \ArrayObject implements \BSON\Types\ArrayObj {
36+
}
37+
38+
class ArrayFixed extends \SplFixedArray implements \BSON\Types\ArrayObj {
39+
}
40+
41+
class ObjectID implements \BSON\Types\ObjectID {
42+
}
43+
44+
class DateTime extends \DateTime implements \BSON\Types\DateTime {
45+
}
46+
47+
48+
49+
function encode($arrayOrObject) {
50+
/* Scalar not allowed */
51+
}
52+
53+
function decode($bson) {
54+
}
55+
56+
function toJSON($bson, $extendedJSON = false) {
57+
}
58+
}
59+
60+
61+

docs/api/MongoDB/CRUD.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
namespace MongoDB;
3+
4+
interface WriteBatch {
5+
function add($document);
6+
}
7+
8+
9+
class InsertBatch implements WriteBatch {
10+
function add($document) {
11+
$this->documents[] = $document;
12+
}
13+
}
14+
15+
class UpdateBatch implements WriteBatch {
16+
function add($document) {
17+
$this->documents[] = $document;
18+
}
19+
}
20+
21+
class DeleteBatch implements WriteBatch {
22+
function add($document) {
23+
$this->documents[] = $document;
24+
}
25+
}
26+
27+
class Query {
28+
function __construct($query) {}
29+
}
30+
class Command {
31+
function __construct($command) {}
32+
}
33+
34+
35+
36+
37+
class WriteResults {
38+
39+
/* Returns nModified, n, nUserted, .. */
40+
function getNumbers() {
41+
}
42+
43+
/* Returns how many operations were executed */
44+
function getOpCount() {
45+
}
46+
47+
/* Returns the server that the operation was executed on */
48+
function getServer() {
49+
}
50+
51+
/* Any stats available from the server */
52+
function getTimer() {
53+
}
54+
}
55+
56+
class QueryResults {
57+
function __construct(Server $server, $cursor_id, $firstBatch) {
58+
}
59+
}
60+
61+

docs/api/MongoDB/Management.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
namespace MongoDB;
3+
4+
class Server {
5+
const TYPE_MONGOS = 0x01;
6+
const TYPE_STANDALONE = 0x02;
7+
const TYPE_ARBITER = 0x03;
8+
const TYPE_SECONDARY = 0x04;
9+
const TYPE_PRIMARY = 0x05;
10+
11+
/* These need to be final as they will not be called by the driver to retrieve the
12+
* information, these getters are only useful for userland */
13+
final function getHostname() {}
14+
final function getPort() {}
15+
final function getLatency() {}
16+
final function getMaxWireVersion() {}
17+
final function getMinWireVersion() {}
18+
final function getServerType() {}
19+
20+
/* extracting config info */
21+
final function isPassive() {}
22+
final function isDelayed() {}
23+
24+
final function executeQuery($namespace, \MongoDB\Query $query) {}
25+
final function executeWrite($namespace, \MongoDB\WriteBatch $batch, WriteOptions $wo) {}
26+
}
27+
28+
29+
class Manager extends \SplObjectStorage {
30+
function __construct(array $servers, $dbname, $connection_options) {
31+
}
32+
33+
static function fromDSN($dsn) {
34+
}
35+
36+
final function executeQuery($namespace, \MongoDB\Query $query, ReadPreference $rp) {
37+
foreach($this->getConnectedServers() as $server) {
38+
if ($server->matchesReadPreference($rp)) {
39+
return $server->executeQuery($namespace, $query);
40+
}
41+
}
42+
throw new NoServerMatchingReadPreference($rp);
43+
}
44+
45+
final function executeWrite($namespace, \MongoDB\WriteBatch $batch, WriteOptions $wo) {
46+
foreach($this->getConnectedServers() as $server) {
47+
if ($server->isPrimary()) {
48+
return $server->executeWrite($namespace, $batch, $wo);
49+
}
50+
}
51+
52+
throw new NoPrimaryAvailable;
53+
}
54+
}
55+

0 commit comments

Comments
 (0)