Ejemplo n.º 1
0
function array2obj($arr, $rec = true, $pretty_props = true, $sufix = '_')
{
    $c = new stdClass();
    add_props($c, $arr, $rec, $pretty_props, $sufix);
    return $c;
}
Ejemplo n.º 2
0
 static function parse_request()
 {
     self::$params = new RequestParams();
     # Get method
     self::$method = $_SERVER['REQUEST_METHOD'];
     self::$remote_ip = $_SERVER['REMOTE_ADDR'];
     if (self::$method === 'POST') {
         self::$post = true;
     } elseif (self::$method === 'GET') {
         self::$get = true;
     }
     self::$abs_url =& $_SERVER['REQUEST_URI'];
     self::$url = preg_replace('~\\?.*~', '', $_SERVER['REQUEST_URI']);
     if (!System::$conf->php_parses_routes) {
         if (empty($_GET['URLtoken'])) {
             exit_with_status(404);
             die('Impossible to find route. Bad htaccess config?');
         }
         # $_GET is filled with parameters from htaccess.
         # Parse them accordingly and fill $_GET with url parameters.
         list($_GET['controller'], $_GET['action']) = explode('@', $_GET['URLtoken']);
         empty($_GET['controller']) && exit_with_status(404);
         empty($_GET['action']) && ($_GET['action'] = 'index');
         unset($_GET['URLtoken']);
         foreach ($_GET as $param => $value) {
             if (!property_exists('Request', $param)) {
                 continue;
             }
             self::${$param} = $value;
             unset($_GET[$param]);
         }
         empty(self::$format) && (self::$format = 'html');
         # Parse GET params from $abs_url
         if (!is_bool(strpos(self::$abs_url, '?'))) {
             $get_params = urldecode(substr(self::$abs_url, strpos(self::$abs_url, '?') + 1));
             $get_params = explode('&', $get_params);
             foreach ($get_params as $gp) {
                 $param = explode('=', $gp);
                 if (empty($param[0]) || empty($param[1])) {
                     continue;
                 }
                 $_GET[$param[0]] = $param[1];
             }
         }
     }
     # Get post/get parameters
     add_props(self::$params, $_GET, false);
     add_props(self::$params, $_POST, false);
     self::$get_params =& $_GET;
     self::$post_params =& $_POST;
 }