Beispiel #1
0
 public function route($url = "index")
 {
     $url = explode('/', $url);
     $user = new \Turner\System\User();
     if (is_null($user::getID())) {
         if (isset($_POST['username']) && isset($_POST['password'])) {
             // Kalau dia mau login
             $user->loadSession($_POST['username'], $_POST['password']);
             // cobalah untuk membuat session tersedia
         } else {
             if (empty($_POST) && $url[0] != 'login') {
                 // Jika ternyata yang diakses bukanlah halaman login
                 header('Location: ' . \Turner\System\App::$information['serverAddr'] . '/login');
             } else {
                 if ($url[0] == 'login') {
                     // Jika sudah ada di login
                     include 'magician/login.php';
                 }
             }
         }
         // tulis isi login.php
         return true;
     } else {
         if (class_exists('\\Turner\\Helper\\' . $url[0]) && count($url) > 0) {
             if (!isset($url[1]) || $url[1] == "") {
                 $url[1] = 'index';
             }
             $url[0] = "\\Turner\\Helper\\" . $url[0];
             $url[1] = strtolower($url[1]) . "Function";
             if (method_exists($url[0], $url[1]) && is_callable([$url[0], $url[1]])) {
                 $calledClass = new $url[0]();
                 call_user_func_array([$calledClass, $url[1]], array_slice($url, 2));
                 return true;
                 /* catch (\Exception $e) {
                         // error_log($e);
                         return false;
                    }
                    */
             }
         } else {
             if ($url[0] == "logout") {
                 \Turner\System\User::clearsessionFunction();
                 return true;
             } else {
                 foreach (self::$singlePage as $link => $directTo) {
                     if (strcmp(strtolower($url[0]), strtolower($link)) == 0) {
                         \Turner\System\App::render($directTo);
                         return true;
                     }
                 }
             }
         }
     }
     include 'magician/Error.php';
     http_response_code(404);
 }