Created
January 20, 2012 15:30
-
-
Save PhilKershaw/1647890 to your computer and use it in GitHub Desktop.
PHP Mongo extension class for AppFog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* AppFogMongo Class | |
* Designed for AppFog Platform as a Service (PaaS). Obtains the connection details and esteblishes a connection to the Db. Extends PHPs Mongo Class. | |
* | |
* @author Phil Kershaw | |
*/ | |
class AppFogMongo extends Mongo | |
{ | |
/** | |
* Contructor | |
* Captures the Db connection details from the VCAP_SERVICES environment variable and establishes a connection to the Db | |
* | |
*/ | |
public function __construct() | |
{ | |
$services_json = json_decode(getenv("VCAP_SERVICES"), true); | |
$$mongo_config = $services_json["mongodb-1.8"][0]["credentials"]; | |
$username = $$mongo_config["username"]; | |
$password = $$mongo_config["password"]; | |
$hostname = $$mongo_config["hostname"]; | |
$port = $$mongo_config["port"]; | |
$db = $$mongo_config["db"]; | |
$this->db = parent::__construct("mongodb://${hostname}:${port}", array( | |
'username' => $username, | |
'password' => $password, | |
'db' => $db | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment