private static function set_controller_and_action()
 {
     # verificando se o config da rota atual é um array com
     # varias opções, ou apenas a definição básica da rota
     is_array(static::$routes[static::$current]) ? $route = explode(' ', static::$routes[static::$current]['location']) : ($route = explode(' ', static::$routes[static::$current]));
     static::$controller = $route[0];
     static::$action = @$route[1] ?: 'index';
 }
Ejemplo n.º 2
0
 /**
  * Parse Response of Soap Requests with parent::__doRequest()
  *
  * @param string $method
  * @param array $args
  *
  * @throws SoapFault $ex
  * @return string $result
  */
 public function getResponseResult($method, $args)
 {
     static::$action = static::GET_RESULT;
     try {
         $result = parent::__call($method, $args);
     } catch (SoapFault $ex) {
         throw $ex;
     }
     static::$action = '';
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Finds the model associated with the current URL and returns it.
  * 
  * @param class $type The model class, in case you want to narrow down the search
  * @return object The model
  */
 public static function currentModel($type = null)
 {
     if (isset(static::$model)) {
         return static::$model;
     }
     $url = static::original_uri();
     if (empty($url)) {
         $url = '/';
     } else {
         $url = '/' . trim($url, '/');
     }
     $model = static::getItemByUrl($url, $type);
     if ($model === null) {
         $segments = explode('/', $url);
         $url = implode('/', array_slice($segments, 0, -1));
         static::$root = empty($url);
         static::$action = array_pop($segments);
         $model = static::getItemByUrl($url, $type);
     }
     if (is_null($model)) {
         return null;
     }
     return static::setCurrentModel($model);
 }
Ejemplo n.º 4
0
 /**
  * Checks if particular action for current controller exist.
  *
  * @static
  * @param    string $sActionName
  * @return   boolean
  * @throws   Exception\Router
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 private static function checkActionExistance($sActionName)
 {
     $sFullActionName = 'action' . $sActionName;
     if (method_exists(static::$controllerName, $sFullActionName)) {
         static::$action = $sFullActionName;
         return TRUE;
     }
     $sMsg = 'Action "' . $sFullActionName . '" in "' . static::$controllerName . '" controller does not exist.';
     Log::insert($sMsg, 'ERROR');
     if (Config::get('base.mode') == 'development') {
         throw new Exception\Router($sMsg);
     } else {
         return FALSE;
     }
 }
 /**
  * Set value for the action attribute of the filter form
  *
  * @param   string  $action  Value for the action attribute of the form
  *
  * @return  void
  *
  * @since   3.0
  */
 public static function setAction($action)
 {
     static::$action = $action;
 }
Ejemplo n.º 6
0
 protected static function route()
 {
     $root = static::$pageRoot;
     $dir = '';
     $redirect = false;
     $status = 200;
     $request = static::removePrefix(static::$request, static::$script ?: '');
     $request = static::removePrefix($request, static::$baseUrl);
     if (static::$original === null) {
         static::$original = $request;
     }
     $questionMarkPosition = strpos($request, '?');
     $hasGet = $questionMarkPosition !== false;
     if ($hasGet) {
         $request = substr($request, 0, $questionMarkPosition);
     }
     $parts = explode('/', $request);
     for ($i = count($parts); $i >= 0; $i--) {
         if ($i == 0) {
             $dir = '';
         } else {
             $dir = implode('/', array_slice($parts, 0, $i)) . '/';
         }
         if (file_exists($root . $dir) && is_dir($root . $dir)) {
             $parameters = array_slice($parts, $i, count($parts) - $i);
             if (count($parameters)) {
                 $part = array_shift($parameters);
                 $matches = glob($root . $dir . $part . '(*).phtml');
                 if (count($matches) == 0) {
                     array_unshift($parameters, $part);
                     $matches = glob($root . $dir . 'index(*).phtml');
                 }
             } else {
                 $matches = glob($root . $dir . 'index(*).phtml');
             }
             $csrfOk = static::$method == 'GET' ? true : Session::checkCsrfToken();
             if (!$csrfOk) {
                 $status = 403;
                 $matches = glob($root . 'error/forbidden(*).phtml');
                 $dir = '';
                 $i = count($parts);
             }
             if (!static::$allowGet && $hasGet) {
                 $status = 405;
                 $matches = glob($root . 'error/method_not_allowed(*).phtml');
                 $dir = '';
                 $i = count($parts);
             }
             if (count($matches) == 0) {
                 $status = 404;
                 $matches = glob($root . 'error/not_found(*).phtml');
                 $dir = '';
                 $i = count($parts);
             }
             if (count($matches) == 0) {
                 static::error('Could not find 404');
             }
             if (count($matches) > 1) {
                 static::error('Mutiple views matched: ' . implode(', ', $matches));
             }
             list($view, $template) = static::extractParts($matches[0], $root, $dir);
             static::$url = $dir . $view;
             static::$view = static::$pageRoot . $dir . $view . '(' . $template . ').phtml';
             static::$template = $template != 'none' ? static::$templateRoot . $template : false;
             $matches = glob($root . $dir . $view . '().php');
             if (count($matches) == 0) {
                 $matches = glob($root . $dir . $view . '($*).php');
             }
             if (count($matches) == 0) {
                 static::$action = false;
             }
             if (count($matches) > 1) {
                 static::error('Mutiple actions matched: ' . implode(', ', $matches));
             }
             static::$parameters = array();
             if (count($matches) == 1) {
                 static::$action = $matches[0];
                 $parameterNames = static::extractParameterNames($matches[0], $root, $dir, $view);
                 if (substr(static::$url, -7) == '//index') {
                     $redirect = substr(static::$url, 0, -7);
                 }
                 if (substr(static::$original, -6) == '/index') {
                     $redirect = substr(static::$url, 0, -6);
                 }
                 if (count($parameters) > count($parameterNames)) {
                     if (substr(static::$url, -6) == '/index') {
                         static::$url = substr(static::$url, 0, -6);
                     }
                     if (count($parameterNames)) {
                         $redirect = static::$url . '/' . implode('/', array_slice($parameters, 0, count($parameterNames)));
                     } else {
                         $redirect = static::$url;
                     }
                 }
                 $parameters = array_map('urldecode', $parameters);
                 if (count($parameters) < count($parameterNames)) {
                     for ($i = count($parameters); $i < count($parameterNames); $i++) {
                         array_push($parameters, null);
                     }
                 }
                 if (!$redirect && count($parameterNames)) {
                     static::$parameters = array_combine($parameterNames, $parameters);
                 }
             }
             break;
         }
     }
     if (Debugger::$enabled) {
         $method = static::$method;
         $request = '/' . static::$original;
         $url = '/' . static::$url;
         $viewFile = static::$view;
         $actionFile = static::$action;
         $templateFile = static::$template;
         $parameters = array();
         $parameters['url'] = static::$parameters;
         $parameters['get'] = $_GET;
         $parameters['post'] = $_POST;
         Debugger::set('router', compact('method', 'csrfOk', 'request', 'url', 'dir', 'view', 'template', 'viewFile', 'actionFile', 'templateFile', 'parameters'));
         Debugger::set('status', $status);
     }
     if ($redirect) {
         static::redirect($redirect);
     }
 }
Ejemplo n.º 7
0
        /**
         * Call action based in instance controller 
         * created in controller method.
         * 
         * @return void
         */
	
	private static function action()
	{
            	$reflection = new \ReflectionClass(static::$controller);
               
		if(isset(static::$segments[1]))
		{ 

                        if( ! $reflection->hasMethod(static::$segments[1]))
                        {
                                throw new ActionException('Action ' . static::$segments[1] . ' not found');
                        }
                        
                        static::$action = static::$segments[1];
		}
			
                if( ! $reflection->hasMethod('index'))
                {
                        throw new ActionException('Action index not found');
                }
	}
Ejemplo n.º 8
0
 /**
  * GET/POST/PUT/DELETE запросы к маршруту
  *
  * @param string $path
  * @param Closure $action
  * @param string $filter
  * @return boolean
  */
 protected function any_action($path, Closure $action, $filter = null)
 {
     if (static::$found) {
         return false;
     }
     $path = $this->route_patterns($path);
     if (preg_match("#^" . $path . "\$#", static::$path, $match)) {
         if (!is_null($filter)) {
             $filters = $this->filters_result($filter);
             if (!array_all(true, $filters)) {
                 return false;
             }
         }
         $params = $this->params($action, $match);
         static::$action = $action;
         static::$match = $params;
         static::$found = true;
         return true;
     }
     return false;
 }
Ejemplo n.º 9
0
 /**
  * Parse Response of Soap Requests with parent::__doRequest()
  *
  * @param string $method
  * @param array  $args
  *
  * @throws \SoapFault $ex
  * @return string $result
  */
 public function getResponseResult($method, $args)
 {
     static::$action = static::GET_RESULT;
     try {
         $resultObj = parent::__call($method, $args);
         $id = static::$lastRequestId;
         $this->addDebugInfo($resultObj, $id);
     } catch (\SoapFault $ex) {
         $this->addDebugInfo($ex, static::$lastRequestId);
         throw $ex;
     }
     static::$action = '';
     return $resultObj;
 }
Ejemplo n.º 10
0
 /**
  * 获取控制器
  * @param null $_action
  * @param null $_method
  */
 public function setAction($_action = null, $_method = null)
 {
     if ($_action && $_method) {
         static::$action = $_action;
         static::$method = $_method;
     }
 }