Ejemplo n.º 1
0
 /**
  * Magic call
  * 
  * @param type $method
  * @param type $args
  * @throws KantException
  */
 public function __call($method, $args)
 {
     $dispatchInfo = KantRegistry::get('dispatchInfo');
     if (0 === strcasecmp($method, strtolower($dispatchInfo[2]) . "Action")) {
         if (method_exists($this, '_empty')) {
             $this->_empty($method, $args);
         } elseif (file_exists($this->view->parseTemplate())) {
             $this->display();
         } else {
             throw new KantException(sprintf("No action exists:%s", ucfirst($dispatchInfo[2]) . 'Action'));
         }
     } else {
         throw new KantException("Method not exists");
     }
 }
Ejemplo n.º 2
0
 /**
  * Get Token
  * @return type
  */
 private function getToken()
 {
     $tokenConfig = KantRegistry::get('config')->get("token");
     $tokenName = !empty($tokenConfig['name']) ? $tokenConfig['name'] : "__hash__";
     $tokenType = !empty($tokenConfig['type']) ? $tokenConfig['type'] : "md5";
     $tokenReset = !empty($tokenConfig['reset']) ? $tokenConfig['reset'] : false;
     if (!isset($_SESSION[$tokenName])) {
         $_SESSION[$tokenName] = array();
     }
     $tokenKey = md5($_SERVER['REQUEST_URI']);
     if (isset($_SESSION[$tokenName][$tokenKey])) {
         $tokenValue = $_SESSION[$tokenName][$tokenKey];
     } else {
         $tokenValue = is_callable($tokenType) ? $tokenType(microtime(true)) : md5(microtime(true));
         $_SESSION[$tokenName][$tokenKey] = $tokenValue;
         if (IS_AJAX && $tokenReset) {
             header($tokenName . ': ' . $tokenKey . '_' . $tokenValue);
         }
     }
     return array($tokenName, $tokenKey, $tokenValue);
 }
Ejemplo n.º 3
0
 /**
  * Execution
  * 
  * @throws KantException
  * @throws ReflectionException
  */
 public function module($dispatchInfo)
 {
     KantRegistry::set('dispatchInfo', $dispatchInfo);
     $this->dispatchInfo = $dispatchInfo;
     //module name
     $moduleName = !empty($dispatchInfo[0]) ? ucfirst($dispatchInfo[0]) : ucfirst(KantFactory::getConfig()->get('route.module'));
     if (empty($moduleName)) {
         throw new KantException('No Module found');
     }
     $this->_initModuleConfig($moduleName);
     //controller name
     $controllerName = !empty($dispatchInfo[1]) ? ucfirst($dispatchInfo[1]) : ucfirst(KantFactory::getConfig()->get('route.ctrl'));
     $controller = $this->controller($controllerName, $moduleName);
     if (!$controller) {
         if (empty($controller)) {
             throw new KantException(sprintf("No controller exists:%s", ucfirst($this->dispatchInfo[1]) . 'Controller'));
         }
     }
     $action = !empty($this->dispatchInfo[2]) ? $this->dispatchInfo[2] . KantFactory::getConfig()->get('action_suffix') : 'Index' . KantFactory::getConfig()->get('action_suffix');
     try {
         if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
             throw new ReflectionException();
         }
         $method = new ReflectionMethod($controller, $action);
         if ($method->isPublic() && !$method->isStatic()) {
             $request = Request::createFromBase(Request::createFromGlobals());
             $data = $method->invoke($controller, $request);
         } else {
             throw new ReflectionException();
         }
     } catch (ReflectionException $e) {
         $method = new ReflectionMethod($controller, '__call');
         $request = Request::createFromBase(Request::createFromGlobals());
         $data = $method->invokeArgs($controller, array($action, $request));
     }
     return $data;
 }
Ejemplo n.º 4
0
 /**
  * Include template
  * 
  * @param type $template
  * @param type $module
  * @throws RuntimeException
  */
 public function layout($template, $module = '')
 {
     if (empty($template)) {
         return;
     }
     list($ctrl, $act) = explode("/", strtolower($template));
     $tpldir = $this->getTplDir($module);
     $tplfile = $tpldir . $ctrl . DIRECTORY_SEPARATOR . $act . '.php';
     if (!file_exists($tplfile)) {
         $debug = KantRegistry::get('config')->get('debug');
         if ($debug) {
             throw new KantException(sprintf("No template: %s", $tplfile));
         } else {
             $this->redirect($this->lang('system_error'), 'close');
         }
     }
     include_once $tplfile;
 }