示例#1
0
 /**
  * @param string $url
  * @param string $method
  * @param array  $postData
  * @param array  $getData
  * @return string
  */
 public static function run($url = '/', $method = 'GET', $postData = [], $getData = [])
 {
     $Input = Loader::loadInput();
     $Input->clear();
     $Input->merge('post', $postData);
     $Input->merge('get', $getData);
     return Autoloader::resolve($method, $url);
 }
示例#2
0
 public static final function trySetCurrentUserEntity()
 {
     $token = Loader::loadInput()->input('token');
     if (TRUE === Kit::isString($token) and '' !== $token) {
         $class_name = Loader::includeCore('User/User');
         try {
             self::$currentUser = $class_name::getCurrentUserEntity($token);
             self::$currentInstitution = self::$currentUser->getInstitution()->setReadOnly();
         } catch (Exception $e) {
             self::$currentUser = NULL;
             self::$currentInstitution = NULL;
         }
     }
 }
示例#3
0
 /**
  * Extracts args and handles the request,
  * by choosing the appropriate handler,
  * and calling the appropriate method
  * if $description CAN fit $this->uri.
  * @param string      $description eg. '/project/(num)', '/(num)', '/', '/user/(any)', '(all)'
  * @param mixed       $handler     eg. 'Project',        $this,    an anonymous function
  * @param string|NULL $function    eg. 'view'
  * @param boolean     $is_time_consuming
  * @return boolean
  */
 private final function fitGeneral($description, $handler, $function = NULL, $is_time_consuming = FALSE)
 {
     /**
      * eg. $description : '/project/(id:num)' => '/project/([0-9]+?)'
      *     $this->uri   : '/project/12'
      *     $match_list  : ['/project/12', '12']
      */
     $pattern = $this->getPattern($description);
     // It will attempt to match the whole $this->uri string.
     $uri = rtrim($this->uri, '/');
     // $this->uri contains no GET args.
     if (1 === preg_match($pattern, $uri, $match_list)) {
         preg_match_all('@([^:\\(\\)]+):([^:\\(\\)]+)@', $description, $m, PREG_SET_ORDER);
         $mapping = [];
         foreach ($m as $value) {
             $mapping[$value[1]] = $value[2];
             // 'id' => 'num'
         }
         $Input = Loader::loadInput();
         foreach ($match_list as $key => $value) {
             // [0 => 12, 'id' => 12]
             if (TRUE === Kit::isInt($key)) {
                 unset($match_list[$key]);
             } elseif ('num' === $mapping[$key]) {
                 $Input->setInput($key, intval($value));
             } else {
                 $Input->setInput($key, $value);
             }
         }
         if (TRUE === Kit::isString($handler) or FALSE === $handler instanceof \Closure) {
             // $handler is a string or IS NOT an anonymous function, i.e., an instance.
             Kit::ensureString($function);
             $this->end(call_user_func_array([TRUE === Kit::isString($handler) ? Loader::loadService($handler) : $handler, $function], [$is_time_consuming]));
         } elseif (TRUE === is_callable($handler)) {
             // $handler is an anonymous function.
             $this->end(call_user_func_array($handler, [$is_time_consuming]));
         }
         // CAN FIT!
         return TRUE;
     } else {
         // CAN NOT FIT!
         return FALSE;
     }
 }
示例#4
0
 protected final function loadInput()
 {
     $handler_name = 'Input';
     return $this->{$handler_name} = Loader::loadInput();
 }