コード例 #1
0
ファイル: Request.php プロジェクト: solofo-ralitera/oron
 public function __construct(array $REQUEST = array())
 {
     /**
     Si appel par ligne de commande
         fill global $REQUEST
         ex :    php index.php Train/search gare_deb_heure=0000 gare_date=15/07/2015
                 php index.php import/cron
     TODO url param !!!
     */
     if (count($REQUEST) == 0 && isset($_SERVER["argv"]) && is_array($_SERVER["argv"])) {
         chdir(dirname($_SERVER["SCRIPT_FILENAME"]));
         $inp = $_SERVER["argv"][1];
         $inp = preg_replace("!^/!", "", $inp);
         $_SERVER["PATH_INFO"] = "/" . $inp;
         /*
         $aInp = explode(":", $inp, 2);
         if(isset($aInp[0]) && trim($aInp[0]) !== "") {
             // replace / or \ par _ : Core/Server => Core_Server
             // eg : php index.php test/test:testCmd => test_test:testCmd
             //      php index.php Core/Server:_server => Core_Server:_server
             $aInp[0] = preg_replace("/[\/\\\]/", "_", $aInp[0]);
             $REQUEST["service"] = $aInp[0];
         }
         if(isset($aInp[1]) && trim($aInp[1]) !== "") {
             $REQUEST["request"] = trim($aInp[1]);
         }
         */
         // Add other params to $REQUEST
         for ($ar = 2; $ar < count($_SERVER["argv"]); $ar++) {
             $param = $_SERVER["argv"][$ar];
             $aP = explode("=", $param, 2);
             $REQUEST[$aP[0]] = $aP[1];
         }
     }
     // Apply route mask
     $confRoute = Config::get("route");
     if (!empty($confRoute) && isset($_SERVER["PATH_INFO"])) {
         if (is_array($confRoute)) {
             foreach ($confRoute as $mask => $route) {
                 if (preg_match("!{$mask}!i", $_SERVER["PATH_INFO"])) {
                     $_SERVER["PATH_INFO"] = preg_replace("!{$mask}!i", $route, $_SERVER["PATH_INFO"]);
                     FirePHP::fbLog("info", "Routing to " . $_SERVER["PATH_INFO"]);
                     break;
                 }
             }
         } else {
             FirePHP::fbLog("error", "ROUTE config must be an array of mask/route");
         }
     }
     /**
     Custom made Redirect Url
         eg: index.php/Test/ => Test:main
             index.php/Core/server/info/ => Core_Server:info
             index.php/Test/demo => Test:main(demo)
             index.php/Test/Main/demo => Test:main(demo)
             index.php/Test/Main/demo/id => Test:main(demo, id)
     */
     if (isset($_SERVER["PATH_INFO"]) && !empty($_SERVER["PATH_INFO"])) {
         $url = $this->Parse();
         $service = $url["service"];
         $request = $url["request"];
         // Si url compose de Service/Request/Param1/Param2/...
         if ($service !== null) {
             $REQUEST["service"] = $service;
         }
         if ($service !== null) {
             $REQUEST["request"] = $request;
         }
     }
     //Store standard params
     foreach ($REQUEST as $key => $value) {
         $key = str_replace(" ", "_", $key);
         $key = CString::stripAccent($key);
         // Strip tags on $REQUEST if magic quote active
         if (get_magic_quotes_gpc()) {
             $value = stripslashes($value);
         }
         $this->{$key} = $value;
     }
 }