Commit 1b4de41b authored by Hannes Magnusson's avatar Hannes Magnusson

Merge pull request #2 from bjori/mc-and-db-objects

Add MongoClient and Database objects
parents e15c2bd5 94ff4deb
<?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);
}
}
<?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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment