Exemple #1
0
 /**
  * Creates a simplified URL given a standard URL.
  * Does the following transformations:
  *
  * - Remove numeric values after =.
  *
  * @param string $url
  * @return string
  */
 public static function simpleUrl($url)
 {
     $callable = Xhgui_Config::read('profiler.simple_url');
     if (is_callable($callable)) {
         return call_user_func($callable, $url);
     }
     return preg_replace('/\\=\\d+/', '', $url);
 }
Exemple #2
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;
     }
 }
Exemple #3
0
 ignore_user_abort(true);
 flush();
 if (!defined('XHGUI_ROOT_DIR')) {
     require dirname(dirname(__FILE__)) . '/src/bootstrap.php';
 }
 $uri = array_key_exists('REQUEST_URI', $_SERVER) ? $_SERVER['REQUEST_URI'] : null;
 if (empty($uri) && isset($_SERVER['argv'])) {
     $cmd = basename($_SERVER['argv'][0]);
     $uri = $cmd . ' ' . implode(' ', array_slice($_SERVER['argv'], 1));
 }
 $time = array_key_exists('REQUEST_TIME', $_SERVER) ? $_SERVER['REQUEST_TIME'] : time();
 $requestTimeFloat = explode('.', $_SERVER['REQUEST_TIME_FLOAT']);
 if (!isset($requestTimeFloat[1])) {
     $requestTimeFloat[1] = 0;
 }
 if (Xhgui_Config::read('save.handler') === 'file') {
     $requestTs = array('sec' => $time, 'usec' => 0);
     $requestTsMicro = array('sec' => $requestTimeFloat[0], 'usec' => $requestTimeFloat[1]);
 } else {
     $requestTs = new MongoDate($time);
     $requestTsMicro = new MongoDate($requestTimeFloat[0], $requestTimeFloat[1]);
 }
 $data['meta'] = array('url' => $uri, 'SERVER' => $_SERVER, 'get' => $_GET, 'env' => $_ENV, 'simple_url' => Xhgui_Util::simpleUrl($uri), 'request_ts' => $requestTs, 'request_ts_micro' => $requestTsMicro, 'request_date' => date('Y-m-d', $time));
 try {
     $config = Xhgui_Config::all();
     $config += array('db.options' => array());
     $saver = Xhgui_Saver::factory($config);
     $saver->save($data);
 } catch (Exception $e) {
     error_log('xhgui - ' . $e->getMessage());
 }
Exemple #4
0
 public function testClear()
 {
     Xhgui_Config::write('test', 'value');
     $this->assertNull(Xhgui_Config::clear());
     $this->assertNull(Xhgui_Config::read('test'));
 }