Esempio n. 1
0
 public function __construct($config = NULL)
 {
     if (is_null($config)) {
         $this->config =& DI::get("config")->framework;
     }
     $this->request = Request::create($this->config);
 }
Esempio n. 2
0
 public function format($format = NULL)
 {
     if (is_null($format)) {
         $cfg = DI::get("config")->framework;
         if (isset($cfg->date_format)) {
             $format = $cfg->date_format;
         }
     }
     return parent::format($format);
 }
Esempio n. 3
0
 public function setAction($action)
 {
     $cfg =& DI::get("config")->framework;
     if (empty($this->controller)) {
         throw new \Exception("Can not set action without a controller being set");
     }
     $action = preg_replace("/[^a-zA-Z0-9_-]/", '', $action);
     $actionWithSuffix = sprintf('%sAction', $action);
     $appName = $this->config->appName;
     $controllerClass = $this->getController();
     if (!class_exists($controllerClass)) {
         throw new \RuntimeException("No such class {$controllerClass}");
     }
     $classMethods = get_class_methods($controllerClass);
     foreach ($classMethods as $k => $v) {
         $classMethods[$k] = strtolower($v);
     }
     $hasAction = in_array(strtolower($actionWithSuffix), $classMethods);
     $hasCall = in_array('__call', $classMethods);
     if ($hasAction) {
         $this->action = $action;
         return $this;
     }
     //To enable slugs
     if (empty($action) && $hasCall) {
         $this->action = strtolower($this->request);
         return $this;
     }
     if (!$hasCall) {
         if (empty($cfg->default_action)) {
             throw new \Exception("Invalid action {$action}");
         }
         $action = $cfg->default_action;
         $hasAction = in_array(sprintf('%saction', $cfg->default_action), $classMethods);
         if (!$hasAction) {
             throw new \Exception("Requested action doesn't exists. Additionally the default action specified in config doesn't exists");
         }
     }
     $this->action = $action;
     return $this;
 }
Esempio n. 4
0
 private function assignConfigVars()
 {
     foreach (DI::get("config") as $k => $cfg) {
         if ($k == "database") {
             continue;
         }
         $this->{$k} = $cfg;
     }
 }