Skip to content

Commit 8c5b4db

Browse files
committed
Add MongoClient and Database objects
1 parent e15c2bd commit 8c5b4db

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

src/Database.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace MongoDB;
4+
5+
use MongoDB\Driver\Manager;
6+
use MongoDB\Collection;
7+
8+
class Database
9+
{
10+
protected $manager;
11+
protected $ns;
12+
protected $wc;
13+
protected $rp;
14+
15+
protected $dbname;
16+
17+
/**
18+
* Constructs new Database instance
19+
*
20+
* It acts as a bridge for database specific operations.
21+
*
22+
* @param Manager $manager The phongo Manager instance
23+
* @param string $dbname Fully Qualified database name
24+
* @param WriteConcern $wc The WriteConcern to apply to writes
25+
* @param ReadPreference $rp The ReadPreferences to apply to reads
26+
*/
27+
public function __construct(Manager $manager, $databaseName, WriteConcern $wc = null, ReadPreference $rp = null)
28+
{
29+
$this->manager = $manager;
30+
$this->dbname = $dbname;
31+
$this->wc = $wc;
32+
$this->rp = $rp;
33+
}
34+
35+
public function selectCollection($collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
36+
{
37+
return new Collection($this->manager, "{$this->dbname}.{$collectionName}", $writeConcern, $readPreferences);
38+
}
39+
40+
}
41+
42+

src/MongoClient.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace MongoDB;
4+
5+
use MongoDB\Driver\Manager;
6+
use MongoDB\Database;
7+
use MongoDB\Collection;
8+
9+
class MongoClient
10+
{
11+
protected $manager;
12+
protected $wc;
13+
protected $rp;
14+
15+
16+
/**
17+
* Constructs new MongoClient instance
18+
*
19+
* This is the suggested main entry point using phongo.
20+
* It acts as a bridge to access individual databases and collection tools
21+
* which are provided in this namespace.
22+
*
23+
* @param Manager $uri The MongoDB URI to connect to
24+
* @param WriteConcern $options URI Options
25+
* @param ReadPreference $driverOptions Driver specific options
26+
*/
27+
public function __construct($uri, $options, $driverOptions)
28+
{
29+
$this->manager = new Manager($uri, $options, $driverOptions);
30+
}
31+
32+
public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
33+
{
34+
return new Database($this->manager, "{$databaseName}", $writeConcern, $readPreferences);
35+
}
36+
37+
public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
38+
{
39+
return new Collection($this->manager, "{$databaseName}.{$collectionName}", $writeConcern, $readPreferences);
40+
}
41+
42+
}
43+

0 commit comments

Comments
 (0)