Ejemplo n.º 1
0
 public function get(string $key, $default = null, string $cryptKey = null)
 {
     /*
      * The key might already be hashed
      */
     if (isset($this->mData[$key])) {
         return $cryptKey !== null ? unserialize(Crypt::decrypt($this->mData[$key], $cryptKey, true)) : $this->mData[$key];
     } else {
         $key = Crypt::hash($this->mPrefix . $key);
         if (isset($this->mData[$key])) {
             return $cryptKey !== null ? unserialize(Crypt::decrypt($this->mData[$key], $cryptKey, true)) : $this->mData[$key];
         }
     }
     return $default;
 }
Ejemplo n.º 2
0
 public function getRaw(string $key, string $default = null, string $encKey = null)
 {
     $result = $this->selectCache($key);
     if ($result !== null && $result->numRows() > 0) {
         $row = $result->fetch();
         if ($encKey !== null) {
             $data = Crypt::decrypt($row[0], $encKey, true);
         } else {
             $data = $row[0];
         }
     }
     if ($result !== null) {
         $result->destroy();
     }
     return $data ?? $default;
 }
Ejemplo n.º 3
0
 public function getRaw(string $key, string $default = null, string $encKey = null)
 {
     $data = $this->mConnection->get($key);
     $status = $this->mConnection->getResultCode();
     if ($status !== Memcached::RES_NOTFOUND) {
         if ($encKey !== null) {
             $data = Crypt::decrypt($data, $encKey, false);
         }
         return $data;
     }
     return $default;
 }
Ejemplo n.º 4
0
 /** @ignore */
 protected function read(string $key, string $encKey = null)
 {
     $fileKey = sha1($key);
     // Key could contain non-filename characters
     $cacheFile = $this->mPath . "{$fileKey}.cache";
     $data = null;
     if (is_file($cacheFile)) {
         if ($encKey !== null) {
             $data = Crypt::decrypt(file_get_contents($cacheFile), $encKey, false);
         } else {
             $data = file_get_contents($cacheFile);
         }
     }
     return $data;
 }
Ejemplo n.º 5
0
 /** @ignore */
 public function readBack()
 {
     if (!$this->mSessReady && !in_array(Runtime::$SYSTEM["REQUEST_CLIENT"], ["terminal", "crawler"])) {
         $driver = Runtime::$SETTINGS->getString("SESSION_DRIVER", "file");
         $maxlife = Runtime::$SETTINGS->getInt("SESSION_EXPIRES", 24 * 60 * 60);
         switch ($driver) {
             case "file":
                 $this->mSessHandler = new FileHandler($this->mSessId, $maxlife);
                 break;
             case "database":
                 $this->mSessHandler = new DBHandler($this->mSessId, $maxlife);
                 break;
             case "cache":
                 $this->mSessHandler = new CacheHandler($this->mSessId, $maxlife);
                 break;
             default:
                 $class = "driver\\Session\\" . $driver . "\\Handler";
                 if (Runtime::loadClassFile($class)) {
                     $this->mSessHandler = (new ReflectionClass($class))->newInstance($this->mSessId, $maxlife);
                 }
         }
         if ($this->mSessHandler === null) {
             throw new Exception("Could find the Session Driver '" . $driver . "'");
         }
         if (mt_rand(0, 100) == 1) {
             $this->mSessHandler->gc();
         }
         $data = $this->mSessHandler->read();
         $this->mData = !empty($data) ? @unserialize($data) : [];
         if (!is_array($this->mData)) {
             if (Runtime::$SETTINGS->getBoolean("SESSION_ENCRYPT_DATA")) {
                 $cryptKey = Runtime::$SETTINGS->getString("SECURITY_PASSWD");
                 if (!empty($cryptKey)) {
                     $this->mData = @unserialize(Crypt::decrypt($data, $cryptKey, true));
                     if (!is_array($this->mData)) {
                         $this->mData = [];
                     }
                 }
             } else {
                 $this->mData = [];
             }
         }
     }
     $this->mSessReady = true;
 }