Esempio n. 1
0
 private function checkToken()
 {
     $row = Model::ApiAuth()->where(['token', '=', $this->token])->first(true);
     if ($row) {
         $row->setExpiration(time() + 3600)->save();
         return true;
     }
     Api::forbidden();
 }
Esempio n. 2
0
 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();
     }
 }
Esempio n. 3
0
 public function status(array $array, $status = 200)
 {
     $array['status'] = $status;
     Api::render($array);
 }
Esempio n. 4
0
 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();
     }
 }