Exemple #1
0
<?php

require_once "carbite.php";
Carbite::GET("/hello/@name", function ($req, $res) {
    $res->SetJSON("Hello " . $req->Params()->name);
});
Carbite::Start();
Exemple #2
0
 static function chk($m, $pa, $fu)
 {
     if (strcmp($m, $_SERVER["REQUEST_METHOD"]) == 0) {
         if (!isset(self::$rParts)) {
             $rPath = self::getRoute();
             $qi = strpos($rPath, '?');
             if ($qi) {
                 $rPath = substr($rPath, 0, $qi);
             }
             self::$rParts = array_map('trim', explode('/', $rPath));
         }
         $cParts = explode("/", $pa);
         if (sizeof($cParts) == sizeof(self::$rParts)) {
             $matched = true;
             $p = new stdClass();
             for ($i = 0; $i < sizeof($cParts); $i++) {
                 if (strlen($cParts[$i]) != 0) {
                     if ($cParts[$i][0] == '@') {
                         $f = substr($cParts[$i], 1);
                         $p->{$f} = self::$rParts[$i];
                     } else {
                         if (strcmp($cParts[$i], self::$rParts[$i]) != 0) {
                             $matched = false;
                             break;
                         }
                     }
                 }
             }
             if ($matched) {
                 self::$cbp = $p;
                 self::$cbf = $fu;
             }
         }
     }
 }