Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit acefa85

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

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

‎src/Client.php‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace MongoDB;
4+
5+
use MongoDB\Driver\Manager;
6+
use MongoDB\Database;
7+
use MongoDB\Collection;
8+
9+
class Client
10+
{
11+
private $manager;
12+
private $wc;
13+
private $rp;
14+
15+
16+
/**
17+
* Constructs new Client 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+
/**
33+
* Select a database
34+
*
35+
* It acts as a bridge to access specific database commands
36+
*
37+
* @param string $databaseName The database to select
38+
* @param WriteConcern $writeConcern Default Write Concern to apply
39+
* @param ReadPreference $readPreferences Default Read Preferences to apply
40+
*/
41+
public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
42+
{
43+
return new Database($this->manager, $databaseName, $writeConcern, $readPreferences);
44+
}
45+
46+
/**
47+
* Select a specific collection in a database
48+
*
49+
* It acts as a bridge to access specific collection commands
50+
*
51+
* @param string $databaseName The database where the $collectionName exists
52+
* @param string $collectionName The collection to select
53+
* @param WriteConcern $writeConcern Default Write Concern to apply
54+
* @param ReadPreference $readPreferences Default Read Preferences to apply
55+
*/
56+
public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
57+
{
58+
return new Collection($this->manager, "{$databaseName}.{$collectionName}", $writeConcern, $readPreferences);
59+
}
60+
61+
}
62+

‎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+
private $manager;
11+
private $ns;
12+
private $wc;
13+
private $rp;
14+
15+
private $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+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /