Example #1
0
 /**
  * Connect to mongo, and get the configured database
  *
  * Will return the active database if called multiple times.
  *
  * @return MongoDb
  */
 public static function connect($host = null, $db = null)
 {
     if (!empty(self::$_db)) {
         return self::$_db;
     }
     if (empty($host)) {
         $host = Xhgui_Config::read('db.host');
     }
     if (empty($db)) {
         $db = Xhgui_Config::read('db.db');
     }
     try {
         self::$_mongo = new MongoClient($host);
         self::$_db = self::$_mongo->{$db};
         return self::$_db;
     } catch (Exception $e) {
         echo "Unable to connect to Mongo<br>\n";
         echo "Exception: " . $e->getMessage() . "<br>\n";
         echo "You may want to ensure that Mongo has been started, and that the config file has the right connection information";
         exit;
     }
 }
Example #2
0
 /**
  * xhgui data storage
  *
  * @param array $settings
  * @return void
  */
 protected function saveToXhgui(array $settings)
 {
     require_once __DIR__ . '/../../../../../Resources/Private/Xhgui/Db.php';
     require_once __DIR__ . '/../../../../../Resources/Private/Xhgui/Db/Mapper.php';
     require_once __DIR__ . '/../../../../../Resources/Private/Xhgui/Profile.php';
     require_once __DIR__ . '/../../../../../Resources/Private/Xhgui/Profiles.php';
     $data = array('profile' => $this->xhprofTrace, 'meta' => array('url' => $_SERVER['REQUEST_URI'], 'SERVER' => $_SERVER, 'get' => $_GET, 'env' => $_ENV, 'simple_url' => preg_replace('/\\=\\d+/', '', $_SERVER['REQUEST_URI']), 'request_ts' => new \MongoDate($_SERVER['REQUEST_TIME']), 'request_date' => date('Y-m-d', $_SERVER['REQUEST_TIME'])));
     $db = \Xhgui_Db::connect($settings['xhgui']['host'], $settings['xhgui']['dbname']);
     $profiles = new \Xhgui_Profiles($db->results);
     $profiles->insert($data);
 }