예제 #1
0
파일: Page.php 프로젝트: schpill/standalone
 public function can()
 {
     $this->method = strtolower(\Thin\Request::method());
     if (in_array($this->method, ['post', 'put', 'delete'])) {
         $_POST = json_decode(file_get_contents('php://input'), true);
         $this->token = isAke($_POST, 'token', false);
         if ($this->token) {
             $this->checkToken();
         } else {
             Api::forbidden();
         }
     }
 }
예제 #2
0
파일: Rest.php 프로젝트: schpill/standalone
 public static function dispatch()
 {
     static::$method = Request::method();
     $uri = substr(str_replace('/ws/', '/', $_SERVER['REQUEST_URI']), 1);
     $tab = explode('/', $uri);
     if (count($tab) < 3) {
         Api::forbidden();
     }
     $namespace = current($tab);
     $controller = $tab[1];
     $action = $tab[2];
     $tab = array_slice($tab, 3);
     $count = count($tab);
     if (0 < $count && $count % 2 == 0) {
         for ($i = 0; $i < $count; $i += 2) {
             $_REQUEST[$tab[$i]] = $tab[$i + 1];
         }
     }
     $file = APPLICATION_PATH . DS . 'webservices' . DS . $namespace . DS . $controller . '.php';
     if (!File::exists($file)) {
         Api::NotFound();
     }
     require_once $file;
     $class = 'Thin\\' . ucfirst($controller) . 'Ws';
     $i = new $class();
     $methods = get_class_methods($i);
     $call = strtolower(static::$method) . ucfirst($action);
     if (!Arrays::in($call, $methods)) {
         Api::NotFound();
     }
     if (Arrays::in('init', $methods)) {
         $i->init($call);
     }
     $i->{$call}();
     if (Arrays::in('after', $methods)) {
         $i->after();
     }
 }
예제 #3
0
 public static function dispatch($module = null)
 {
     $module = is_null($module) ? 'front' : $module;
     $ever = context()->get('MVC404');
     if (true !== $ever) {
         $file = APPLICATION_PATH . DS . 'config' . DS . SITE_NAME . '_routes.php';
         if (File::exists($file)) {
             $routes = (include $file);
             static::$routes = isAke($routes, $module, []);
         }
         if (count(static::$routes)) {
             $baseUri = Config::get('application.base_uri', '');
             if (strlen($baseUri)) {
                 $uri = strReplaceFirst($baseUri, '', $_SERVER['REQUEST_URI']);
             } else {
                 $uri = $_SERVER['REQUEST_URI'];
             }
             static::$uri = $uri;
             static::$method = Request::method();
             return static::find();
         }
     }
     return false;
 }
예제 #4
0
파일: Router.php 프로젝트: schpill/thin
 public static function ssl()
 {
     Utils::go(repl('http:', 'https:', trim(URLSITE, '/')) . Request::uri());
 }
예제 #5
0
파일: Rest.php 프로젝트: schpill/standalone
 public static function dispatch()
 {
     header("Access-Control-Allow-Origin: *");
     static::$method = Request::method();
     $uri = substr(str_replace('/mobi/', '/', $_SERVER['REQUEST_URI']), 1);
     $tab = explode('/', $uri);
     if (!strlen($uri) || $uri == '/') {
         $namespace = 'static';
         $controller = 'home';
         $action = 'index';
     } else {
         if (count($tab) < 3) {
             self::isForbidden();
         }
         $namespace = current($tab);
         $controller = $tab[1];
         $action = $tab[2];
         $tab = array_slice($tab, 3);
         $count = count($tab);
         if (0 < $count && $count % 2 == 0) {
             for ($i = 0; $i < $count; $i += 2) {
                 $_REQUEST[$tab[$i]] = $tab[$i + 1];
             }
         }
     }
     $file = APPLICATION_PATH . DS . 'mobi' . DS . $namespace . DS . 'controllers' . DS . $controller . '.php';
     // dd($file);
     if (!File::exists($file)) {
         self::is404();
     }
     require_once $file;
     $class = 'Thin\\' . ucfirst($controller) . 'Mobi';
     $i = new $class();
     $methods = get_class_methods($i);
     $call = strtolower(static::$method) . ucfirst($action);
     if (!Arrays::in($call, $methods)) {
         self::is404();
     }
     if (Arrays::in('init', $methods)) {
         $i->init($call);
     }
     $i->{$call}();
     if ($i->view === true) {
         $tpl = APPLICATION_PATH . DS . 'mobi' . DS . $namespace . DS . 'views' . DS . $controller . DS . $action . '.phtml';
         if (File::exists($tpl)) {
             $content = File::read($tpl);
             $content = str_replace('$this->', '$i->', $content);
             $fileTpl = CACHE_PATH . DS . sha1($content) . '.display';
             File::put($fileTpl, $content);
             ob_start();
             include $fileTpl;
             $html = ob_get_contents();
             ob_end_clean();
             File::delete($fileTpl);
             self::render($html);
         } else {
             self::render('OK');
         }
     }
     if (Arrays::in('after', $methods)) {
         $i->after();
     }
 }
예제 #6
0
파일: Helper.php 프로젝트: noikiy/inovi
 function req()
 {
     return Request::instance();
 }
예제 #7
0
파일: Mvc.php 프로젝트: schpill/standalone
 public static function route()
 {
     static::$method = Request::method();
     $pjax = isAke(Request::headers(), 'x-pjax', []);
     static::$pjax = !empty($pjax);
     $uri = substr($_SERVER['REQUEST_URI'], 1);
     if (static::$pjax) {
         static::$method = 'GET';
     }
     if (fnmatch("*?*", $uri) && static::$pjax) {
         $uri = str_replace('?', '/', $uri);
         $uri = str_replace('=', '/', $uri);
         $uri = str_replace('&', '/', $uri);
     }
     if (!strlen($uri)) {
         $controller = 'index';
         $action = 'home';
     } else {
         $tab = explode('/', $uri);
         if (count($tab) == 1) {
             $seg = current($tab);
             if (strlen($seg) == 2) {
                 $_REQUEST['lng'] = strtolower($seg);
                 $controller = 'index';
                 $action = 'home';
             } else {
                 $controller = strtolower($seg);
                 $action = 'index';
             }
         } elseif (count($tab) == 2) {
             $first = current($tab);
             $second = end($tab);
             if (strlen($first) == 2) {
                 $_REQUEST['lng'] = strtolower($first);
                 $controller = $second;
                 $action = 'index';
             } else {
                 $controller = strtolower($first);
                 $action = strtolower($second);
             }
         } else {
             $first = current($tab);
             $second = $tab[1];
             $third = end($tab);
             if (strlen($first) == 2) {
                 $_REQUEST['lng'] = strtolower($first);
                 $controller = $second;
                 $action = 'index';
             } else {
                 $controller = strtolower($first);
                 $action = strtolower($second);
                 $tab = array_slice($tab, 2);
                 $count = count($tab);
                 if (0 < $count && $count % 2 == 0) {
                     for ($i = 0; $i < $count; $i += 2) {
                         $_REQUEST[$tab[$i]] = $tab[$i + 1];
                     }
                 }
             }
         }
     }
     static::$route = ['controller' => $controller, 'action' => $action];
 }
예제 #8
0
파일: Response.php 프로젝트: schpill/thin
 /**
  * Send all of the response headers to the browser.
  *
  * @return void
  */
 public function send_headers()
 {
     $this->foundation->prepare(Request::foundation());
     $this->foundation->sendHeaders();
 }
예제 #9
0
파일: Rest.php 프로젝트: schpill/standalone
 public static function controller($dir, $cn)
 {
     static::$method = Request::method();
     $uri = substr(str_replace('/api/', '/', $_SERVER['REQUEST_URI']), 1);
     $tab = explode('/', $uri);
     dd($tab);
     if (count($tab) < 1) {
         Api::forbidden();
     }
     $action = current($tab);
     $tab = array_slice($tab, 1);
     $count = count($tab);
     if (0 < $count && $count % 2 == 0) {
         for ($i = 0; $i < $count; $i += 2) {
             $_REQUEST[$tab[$i]] = $tab[$i + 1];
         }
     }
     $file = $dir . DS . 'controllers' . DS . 'api.php';
     if (!File::exists($file)) {
         Api::NotFound();
     }
     require_once $file;
     $class = 'Thin\\' . $cn;
     $i = new $class();
     $methods = get_class_methods($i);
     $call = strtolower(static::$method) . ucfirst($action);
     if (!Arrays::in($call, $methods)) {
         Api::NotFound();
     }
     if (Arrays::in('init', $methods)) {
         $i->init($call);
     }
     $i->{$call}();
     if (Arrays::in('after', $methods)) {
         $i->after();
     }
 }