Example #1
0
 /**
  * setCallable
  * ID: untuk setting paramater fungsi pada get atau post
  * EN: For setting function parameter at get or post
  * @param array $args
  **/
 private function setCallable($args)
 {
     $route = array_shift($args);
     $real_params = array();
     //Before Middleware
     if (is_array($args[0])) {
         $this->middleware['before'] = array_shift($args);
     }
     if (!is_callable($args[0])) {
         $controller = array_shift($args);
         $real_params['controller'] = $controller;
     }
     //if ($route == '/' && count( $this->route->_getParams() ) <= 0 ) {
     if (preg_match('/(^\\/$)|(^\\/(\\?(\\w|\\d|\\=|\\&|\\-|\\.|_|\\/){0,}){0,}$)/', $route . $this->route->getParamStr(), $matches, PREG_OFFSET_CAPTURE)) {
         //$this->callable = array_pop($args);
         $this->callable = \Closure::bind(array_pop($args), $this, get_class());
         $this->routedStatus = TRUE;
     } else {
         $route_pattern = str_replace('/', '\\/', $route);
         //** ID: Konversi route kedalam pattern parameter optional
         //** EN: Convert route in optional parameter pattern
         $route_pattern = preg_replace('/\\\\\\/\\(:\\w+\\)/', '(\\/\\\\w+){0,}', $route_pattern, -1);
         //** ID: Konversi route kedalam pattern parameter wajib
         //** EN: Cover route in required parameter pattern
         $route_pattern = preg_replace('/:\\w+/', '([\\w+|\\=|\\-|\\_]){1,}', $route_pattern, -1);
         $route_pattern = str_replace('\\/\\w++', '(((\\/){0,}\\w+){0,})', $route_pattern);
         if ($route != '/' && preg_match('/(^' . $route_pattern . '$)|((^' . $route_pattern . ')+(\\?(\\w|\\d|\\=|\\&|\\-|\\.|_|\\/){0,}){0,}$)/', $this->route->getParamStr(), $matches, PREG_OFFSET_CAPTURE)) {
             //$this->callable = array_pop($args);
             $this->callable = \Closure::bind(array_shift($args), $this, get_class());
             $this->routedStatus = TRUE;
             $p = explode('/', $route);
             while (list($key, $value) = each($p)) {
                 if (substr(trim($value), -1) == '+') {
                     if (isset($matches[2][0]) && !empty($matches[2][0])) {
                         $real_params[$value] = explode('/', substr($matches[2][0], 1));
                     } elseif (isset($matches[7][0]) && !empty($matches[7][0])) {
                         $real_params[$value] = explode('/', substr($matches[7][0]), 1);
                     } else {
                         $real_params[$value] = array();
                     }
                 } elseif (substr(trim($value, '/'), 0, 1) == ':') {
                     $getpos = strpos($this->route->_getParams($key), '?') > 0 ? strpos($this->route->_getParams($key), '?') : strlen($this->route->_getParams($key));
                     $real_params[$value] = substr($this->route->_getParams($key), 0, $getpos);
                 } elseif (substr(trim($value, '/'), 0, 2) == '(:' && substr(trim($value, '/'), -1, 1) == ')') {
                     if ($this->route->_getParams($key) != NULL) {
                         $getpos = strpos($this->route->_getParams($key), '?') > 0 ? strpos($this->route->_getParams($key), '?') : strlen($this->route->_getParams($key));
                         $real_params[$value] = substr($this->route->_getParams($key), 0, $getpos);
                     }
                 }
             }
         }
     }
     Route::$_destination = $route;
     $this->route->setParams($real_params);
     //print_r($args);
     //After Middleware
     if (count($args) > 0 && is_array($args[0])) {
         $this->middleware['after'] = array_shift($args);
     }
 }