Esempio n. 1
0
 public function logAction()
 {
     Log::debug('AE1');
     Log::notice('AE2');
     Log::notice('AE3');
     echo "OK";
 }
 public function logAction()
 {
     Log::debug('TEST');
 }
Esempio n. 3
0
 /**
  * Construct the object
  * @param string $uri
  */
 public function __construct($uri, array $config = null)
 {
     if ($config === null || count($config) == 0 || !isset($config['module_param']) || !isset($config['controller_param']) || !isset($config['action_param'])) {
         throw new Exception('Route config options are missing');
     }
     parent::__construct($uri, $config);
     if (isset($_GET[$config['controller_param']])) {
         $c = trim($_GET[$config['controller_param']]);
         if ($c == '') {
             $this->controllerUrl = 'index';
             $this->controllerClass = 'IndexController';
         } else {
             $this->controllerUrl = strtolower($c);
             $this->controllerClass = str_replace(' ', '', ucwords(str_replace(array('-', '.'), ' ', $this->controllerUrl))) . 'Controller';
         }
     } else {
         $this->controllerUrl = 'index';
         $this->controllerClass = 'IndexController';
     }
     // Now we have the controller class name detected, but, should it be
     // taken from module or from default controllers?
     // TODO: Zavrsiti ovo!
     $moduleDir = Application::getApplicationPath() . 'modules' . DS . $this->controllerUrl;
     if (is_dir($moduleDir)) {
         // ok, it is a module with module/controller/action path
         $moduleUrl = $this->controllerUrl;
         $this->moduleUrl = $moduleUrl;
         $a = isset($_GET[$config['action_param']]) ? trim($_GET[$config['action_param']]) : '';
         if ($a != '') {
             $this->controllerUrl = strtolower($a);
             $this->controllerClass = str_replace(' ', '', ucwords(str_replace(array('-', '.'), ' ', $this->controllerUrl))) . 'Controller';
         } else {
             $this->controllerUrl = 'index';
             $this->controllerClass = 'IndexController';
         }
         $this->controllerPath = $moduleDir . DS . 'controllers' . DS . $this->controllerClass . '.php';
         $mainControllerExists = true;
         if (!is_file($this->controllerPath)) {
             $this->controllerPath = Application::getApplicationPath() . 'modules' . DS . $moduleUrl . DS . 'controllers' . DS . 'IndexController.php';
             if (!is_file($this->controllerPath)) {
                 // Even IndexController is missing. Can not resolve that.
                 if (Application::inDevelopment()) {
                     $controllersPath = $moduleDir . DS . 'controllers';
                     \Koldy\Log::debug("Can not find {$this->controllerClass} nor IndexController in {$controllersPath}");
                 }
                 Application::error(404, 'Page not found');
             }
             $mainControllerExists = false;
             $this->controllerClass = 'IndexController';
         }
         if ($mainControllerExists) {
             if (!isset($this->uri[3]) || $this->uri[3] == '') {
                 $this->actionUrl = 'index';
                 $this->actionMethod = 'index';
             } else {
                 $this->actionUrl = strtolower($this->uri[3]);
                 $this->actionMethod = ucwords(str_replace(array('-', '.'), ' ', $this->actionUrl));
                 $this->actionMethod = str_replace(' ', '', $this->actionMethod);
                 $this->actionMethod = strtolower(substr($this->actionMethod, 0, 1)) . substr($this->actionMethod, 1);
             }
         } else {
             if (isset($this->uri[2]) && $this->uri[2] != '') {
                 $this->actionUrl = strtolower($this->uri[2]);
                 $this->actionMethod = ucwords(str_replace(array('-', '.'), ' ', $this->actionUrl));
                 $this->actionMethod = str_replace(' ', '', $this->actionMethod);
                 $this->actionMethod = strtolower(substr($this->actionMethod, 0, 1)) . substr($this->actionMethod, 1);
             } else {
                 $this->actionUrl = 'index';
                 $this->actionMethod = 'index';
             }
         }
         // and now, configure the include paths according to the case
         Application::addIncludePath(array($moduleDir . DS . 'controllers' . DS, $moduleDir . DS . 'models' . DS, $moduleDir . DS . 'library' . DS, Application::getApplicationPath() . 'controllers' . DS, Application::getApplicationPath() . 'models' . DS, Application::getApplicationPath() . 'library' . DS));
     } else {
         // ok, it is the default controller/action
         $this->controllerPath = Application::getApplicationPath() . 'controllers' . DS . $this->controllerClass . '.php';
         $mainControllerExists = true;
         if (!is_file($this->controllerPath)) {
             $this->controllerPath = Application::getApplicationPath() . 'controllers' . DS . 'IndexController.php';
             if (!is_file($this->controllerPath)) {
                 // Even IndexController is missing. Can not resolve that.
                 if (Application::inDevelopment()) {
                     $controllersPath = Application::getApplicationPath() . 'controllers';
                     \Koldy\Log::debug("Can not find {$this->controllerClass} nor IndexController in {$controllersPath}");
                 }
                 Application::error(404, 'Page not found');
             }
             $mainControllerExists = false;
             $this->controllerClass = 'IndexController';
         }
         if ($mainControllerExists) {
             if (!isset($this->uri[2]) || $this->uri[2] == '') {
                 $this->actionUrl = 'index';
                 $this->actionMethod = 'index';
             } else {
                 $this->actionUrl = strtolower($this->uri[2]);
                 $this->actionMethod = ucwords(str_replace(array('-', '.'), ' ', $this->actionUrl));
                 $this->actionMethod = str_replace(' ', '', $this->actionMethod);
                 $this->actionMethod = strtolower(substr($this->actionMethod, 0, 1)) . substr($this->actionMethod, 1);
             }
         } else {
             $this->actionUrl = strtolower($this->uri[1]);
             $this->actionMethod = ucwords(str_replace(array('-', '.'), ' ', $this->actionUrl));
             $this->actionMethod = str_replace(' ', '', $this->actionMethod);
             $this->actionMethod = strtolower(substr($this->actionMethod, 0, 1)) . substr($this->actionMethod, 1);
         }
         // and now, configure the include paths according to the case
         Application::addIncludePath(array(Application::getApplicationPath() . 'controllers' . DS, Application::getApplicationPath() . 'models' . DS, Application::getApplicationPath() . 'library' . DS));
     }
     $this->isAjax = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false;
     if ($this->isAjax) {
         $this->actionMethod .= 'Ajax';
     } else {
         $this->actionMethod .= 'Action';
     }
 }