예제 #1
0
 /**
  * Clears the cookie collection.
  * 
  * @method  clear
  */
 public function clear()
 {
     $this->readOnlyCheck();
     foreach ($this->collection as $httpCookie) {
         $httpCookie->setExpires(\System\Std\Date::now()->sub(new \DateInterval('P1Y')));
     }
 }
예제 #2
0
 /**
  * Writes all logs to a file.
  * 
  * @method  write
  * @param   array $logs
  * @param   array $extra
  * @return  void
  */
 public function write(array $logs, array $extra = array())
 {
     $formatted = (new \System\Std\String())->appendLine('');
     foreach ($extra as $key => $value) {
         $formatted = $formatted->appendLine(strtoupper($key) . ': ' . $value);
     }
     $save = false;
     foreach ($logs as $log) {
         if (count($this->filters) == 0 || in_array(strtoupper($log['level_name']), array_map('strtoupper', $this->filters))) {
             $log = $this->executeProcessor($log);
             if ($log) {
                 $formatted = $formatted->appendLine('LEVEL: ' . $log['level_name'])->appendLine('DATE: ' . $log['time'])->appendLine('PARAMS: ' . json_encode($log['params']))->appendLine('MESSAGE:')->appendLine($log['message'])->appendLine('');
                 $save = true;
             }
         }
     }
     if (!$save) {
         return;
     }
     $logFile = $this->singleLog ? \System\Std\Date::now()->toString('dd-mm-yyyy') : \System\Std\Date::now()->getTimestamp();
     $fp = fopen($this->path . '/' . $logFile . '.log', 'a');
     if ($this->useLock) {
         flock($fp, LOCK_EX);
     }
     fwrite($fp, (string) $formatted);
     if ($this->useLock) {
         flock($fp, LOCK_UN);
     }
 }
예제 #3
0
 public function write()
 {
     if ($this->sessionStarted) {
         if (!$this->sessionFile) {
             $this->sessionId = sha1(uniqid(mt_rand()));
             $this->sessionFile = session_save_path() . '/sess_' . $this->sessionId;
         }
         if ($this->expires > 0) {
             $this->expires = \System\Std\Date::now()->addSeconds($this->expires)->getTimestamp();
         }
         $httpCookie = new \System\Web\HttpCookie($this->sessionName, $this->sessionId, $this->expires, $this->path, $this->domain, $this->isSecure, $this->isHttpOnly);
         $this->httpResponse->getCookies()->add($httpCookie);
         file_put_contents($this->sessionFile, serialize($this->collection));
     }
 }
예제 #4
0
 public function getDefaultValue()
 {
     if (strtolower($this->defaultValue) == '@now') {
         $this->defaultValue = \System\Std\Date::now()->toString('yyyy-MM-dd HH:mm:ss');
     } else {
         if (strtolower($this->defaultValue) == '@time') {
             $this->defaultValue = \System\Std\Date::now()->toString('HH:mm:ss');
         } else {
             if (strtolower($this->defaultValue) == '@timestamp') {
                 $this->defaultValue = \System\Std\Date::now()->getTimestamp();
             }
         }
     }
     return $this->defaultValue;
 }
예제 #5
0
 protected function addLog($level, $message, $params)
 {
     $this->logs[] = array('message' => $message, 'time' => \System\Std\Date::now()->toString(), 'level' => $level, 'level_name' => static::$levels[$level], 'params' => $params);
 }
예제 #6
0
 /**
  * Authenticates a HTTP request using Authentication and establishes the 
  * identity of the user.
  * 
  * @method  authenticateRequest
  * @param   System.Web.Mvc.Controller $controller
  * @return  void
  */
 public function authenticateRequest(\System\Web\Mvc\Controller $controller)
 {
     $httpAuthCookie = $this->httpContext->getRequest()->getCookies()->get(Authentication::getCookieName());
     $identity = new UserIdentity('Anonymous');
     if ($httpAuthCookie) {
         $ticket = Authentication::decrypt($httpAuthCookie->getValue());
         if (\System\Std\Date::now()->getTimestamp() < $ticket->getExpire() || $ticket->getExpire() == 0) {
             $identity = new UserIdentity($ticket->getName(), $ticket->getUserData(), true);
         }
     }
     $this->httpContext->getRequest()->setUser($identity);
 }