Esempio n. 1
0
 /**
  * Save session in storage
  */
 public function write()
 {
     try {
         // Make sure we have instance of ComelySession
         if (!$this->session instanceof ComelySession) {
             throw SessionException::sessionNotExists(__METHOD__);
         }
         // Prepare it for writing
         $this->session->encodeData($this->config->hashSalt, $this->config->hashCost);
         $payload = serialize($this->session);
         // Cipher Encryption?
         if ($this->config->cipher instanceof Cipher) {
             $payload = $this->config->cipher->encrypt($payload);
         }
         // Write in storage
         $this->storage->write($this->session->getId(), $payload);
     } catch (\Throwable $t) {
         /**
          * Since this method would run at end of execution, its better to trigger an error alongside throwing
          * exception (assuming that is is being logged by error handler)
          */
         $methodString = method_exists($t, "getMethod") ? sprintf("%s: ", $t->getMethod()) : "";
         trigger_error($methodString . $t->getMessage(), E_USER_WARNING);
         // Re-throw
         throw $t;
     }
 }