Skip to content

Add MongoClient and Database objects #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace MongoDB;

use MongoDB\Driver\Manager;
use MongoDB\Database;
use MongoDB\Collection;

class Client
{
private $manager;
private $wc;
private $rp;


/**
* Constructs new Client instance
*
* This is the suggested main entry point using phongo.
* It acts as a bridge to access individual databases and collection tools
* which are provided in this namespace.
*
* @param Manager $uri The MongoDB URI to connect to
* @param WriteConcern $options URI Options
* @param ReadPreference $driverOptions Driver specific options
*/
public function __construct($uri, $options, $driverOptions)
{
$this->manager = new Manager($uri, $options, $driverOptions);
}

/**
* Select a database
*
* It acts as a bridge to access specific database commands
*
* @param string $databaseName The database to select
* @param WriteConcern $writeConcern Default Write Concern to apply
* @param ReadPreference $readPreferences Default Read Preferences to apply
*/
public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
{
return new Database($this->manager, $databaseName, $writeConcern, $readPreferences);
}

/**
* Select a specific collection in a database
*
* It acts as a bridge to access specific collection commands
*
* @param string $databaseName The database where the $collectionName exists
* @param string $collectionName The collection to select
* @param WriteConcern $writeConcern Default Write Concern to apply
* @param ReadPreference $readPreferences Default Read Preferences to apply
*/
public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
{
return new Collection($this->manager, "{$databaseName}.{$collectionName}", $writeConcern, $readPreferences);
}

}

51 changes: 51 additions & 0 deletions src/Database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace MongoDB;

use MongoDB\Driver\Manager;
use MongoDB\Collection;

class Database
{
private $manager;
private $ns;
private $wc;
private $rp;

private $dbname;

/**
* Constructs new Database instance
*
* It acts as a bridge for database specific operations.
*
* @param Manager $manager The phongo Manager instance
* @param string $dbname Fully Qualified database name
* @param WriteConcern $wc The WriteConcern to apply to writes
* @param ReadPreference $rp The ReadPreferences to apply to reads
*/
public function __construct(Manager $manager, $databaseName, WriteConcern $wc = null, ReadPreference $rp = null)
{
$this->manager = $manager;
$this->dbname = $dbname;
$this->wc = $wc;
$this->rp = $rp;
}

/**
* Select a specific collection in this database
*
* It acts as a bridge to access specific collection commands
*
* @param string $collectionName The collection to select
* @param WriteConcern $writeConcern Default Write Concern to apply
* @param ReadPreference $readPreferences Default Read Preferences to apply
*/
public function selectCollection($collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreferences = null)
{
return new Collection($this->manager, "{$this->dbname}.{$collectionName}", $writeConcern, $readPreferences);
}

}