Beispiel #1
0
 /**
  * Asign needed elements to internal variables
  * @param \Stupid\Registry $registry
  */
 public function __construct($registry = null)
 {
     $this->registry = $registry;
     $this->view = $this->registry['view'];
     $this->args = $this->registry['args'];
     $this->name = $this->registry['name'];
     $this->user = Stupid::getUser();
 }
Beispiel #2
0
 /**
  * This method runs the application
  * parses URL, to get controller & action to run
  * if URL is invalid, passes control to ErrorController
  */
 public function delegate()
 {
     $destination = $this->parseUrl();
     $this->registry['args'] = $destination->args;
     $this->registry['name'] = $destination->name . ':' . $destination->action;
     $file = $destination->file;
     $controller = $destination->controller;
     $action = $destination->action;
     //		$action = "action". ucfirst($destination->action);
     // File available?
     if (!file_exists($file)) {
         $controller = $this->controllersNamespace . "ErrorController";
         $controllerFile = "ErrorController";
         $file = $this->controllersDir . $controllerFile . '.php';
         $action = 'actionIndex';
     }
     if (is_readable($file) == false) {
         throw new \Exception("File '{$file}' cannot be read from filesystem");
     }
     include $file;
     $controllerObj = new $controller($this->registry);
     if (!method_exists($controllerObj, $action) and !method_exists($controllerObj, "action" . ucfirst($destination->action))) {
         unset($controllerObj);
         $this->registry->remove('args');
         // pass control to ErrorController
         $controller = $this->controllersNamespace . "ErrorController";
         $controllerFile = 'ErrorController';
         $action = 'actionIndex';
         $file = $this->controllersDir . "{$controllerFile}.php";
         include $file;
         // Initiate the class
         $controllerObj = new $controller($this->registry);
     }
     // Start session
     $s = Stupid::getSession();
     if (!$s->isStarted() && $s->exists()) {
         $s->start();
     }
     if (method_exists($controllerObj, 'startup')) {
         $controllerObj->startup();
     }
     if (method_exists($controllerObj, "action" . ucfirst($destination->action))) {
         // Run Controller::action<Action>()
         $action = "action" . ucfirst($destination->action);
         $controllerObj->{$action}();
     } else {
         $controllerObj->{$action}();
     }
 }
Beispiel #3
0
 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|DateTime  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @return Session  provides a fluent interface
  * @throws \Exception  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL)
 {
     if (headers_sent($file, $line)) {
         throw new \Exception("Cannot set cookie after HTTP headers have been sent" . ($file ? " (output started at {$file}:{$line})." : "."));
     }
     setcookie($name, $value, $time ? Stupid::createDateTime($time)->format('U') : 0, $path === NULL ? '/' : (string) $path, $domain === NULL ? '' : (string) $domain, $secure === NULL ? false : (bool) $secure, TRUE);
     return $this;
 }
Beispiel #4
0
 /**
  * Is visitor developer, or is his IP in excluding array?
  * @return bool
  */
 public static function isDeveloper($file = null)
 {
     $IPs = Stupid::getConfig('common', null, $file)->ip;
     if (in_array($_SERVER['REMOTE_ADDR'], $IPs) or !Stupid::isProduction()) {
         return true;
     } else {
         return false;
     }
 }
Beispiel #5
0
 /**
  * Sets the authenticated status of this user.
  * @param  bool  flag indicating the authenticated status of user
  * @return User  provides a fluent interface
  */
 protected function setAuthenticated($state)
 {
     $session = $this->getUserNamespace(true);
     $session->authenticated = (bool) $state;
     // Session Fixation defence
     Stupid::getSession()->regenerateId();
     if ($state) {
         $session->reason = NULL;
         $session->authTime = time();
         // informative value
     } else {
         $session->reason = self::MANUAL;
         $session->authTime = NULL;
     }
     return $this;
 }