Пример #1
0
 protected function language($matches)
 {
     $language = HTTP::value("language", "post", "");
     if ($language) {
         setcookie("language", $language);
     }
     HTTP::redirectBack();
 }
Пример #2
0
 protected function dispatch()
 {
     $method = strtolower($_SERVER["REQUEST_METHOD"]);
     $method = HTTP::value("http_method", "post", $method);
     $handler = "";
     $resource = substr($_SERVER["REQUEST_URI"], strlen(HTTP::$BASE));
     $qs = strpos($resource, "?");
     if ($qs !== false) {
         $resource = substr($resource, 0, $qs);
     }
     $resource_matched = false;
     do {
         foreach ($this->dispatch_table as $row) {
             $item = preg_split('/\\s+/', $row);
             preg_match("#" . $item[1] . "#", $resource, $matches);
             if (!$matches) {
                 continue;
             }
             $resource_matched = true;
             if (strtolower($item[0]) != $method) {
                 continue;
             }
             $handler = $item[2];
             break;
         }
         if (!$handler) {
             if ($resource_matched) {
                 return $this->error405();
             } else {
                 return $this->error404();
             }
         }
         /* does not exist in table */
         if (substr($handler, 0, 1) == "/") {
             /* alias to other resource */
             $resource = $handler;
             $handler = "";
         }
     } while (!$handler);
     return $this->{$handler}($matches);
 }