Example #1
0
 public function load($id, $context = null, $returnNewBucket = true)
 {
     if (!Bucket::isValidId($id)) {
         return false;
     }
     $this->_checkDatabase();
     $data = $this->database->query('SELECT expires, data, context FROM ' . $this->table . ' WHERE id = %t% LIMIT 0, 1', array($id), Database::FILTER_ROW);
     if (!$data) {
         return false;
     }
     $expires = DateTime::$utc->setBySqlString($data['expires'])->getTimestamp();
     if ($expires < time()) {
         $this->database->exec('DELETE FROM ' . $this->table . ' WHERE id = %t%', array($id));
         return false;
     }
     if ($context !== false && $data['context'] != $context) {
         return false;
     }
     if ($returnNewBucket) {
         $b = new DatabaseBucket();
         $b->_mergeSettings($this);
     } else {
         $b = $this;
     }
     $b->database = $this->database;
     $b->table = $this->table;
     $b->id = $id;
     $b->expires = $expires;
     $b->data = unserialize(base64_decode($data['data']));
     $b->context = $data['context'];
     return $b;
 }
Example #2
0
 public function load($id, $context = null, $returnNewBucket = true)
 {
     if (!Bucket::isValidId($id)) {
         return false;
     }
     $file = $this->directory . $id . '.bck';
     if (!file_exists($file)) {
         return false;
     }
     $mod = filemtime($file);
     if ($mod < time()) {
         unlink($file);
         return false;
     }
     $data = unserialize(file_get_contents($file));
     if ($context !== false && $data[0] != $context) {
         return false;
     }
     if ($returnNewBucket) {
         $b = new FileBucket();
         $b->_mergeSettings($this);
     } else {
         $b = $this;
     }
     $b->directory = $this->directory;
     $b->id = $id;
     $b->data = $data[1];
     $b->context = $data[0];
     $b->expires = $mod;
     return $b;
 }
Example #3
0
 protected function _endProcessing()
 {
     if ($this->_bucket) {
         $this->formData->lastAction = microtime(true);
         $this->_bucket->data = $this->formData;
         $this->_bucket->save();
     }
     $this->_deInit();
 }
Example #4
0
 public function delete($keepBucket = false)
 {
     $this->data = null;
     if ($this->bucket && !$keepBucket) {
         $this->bucket->delete();
     }
     if ($this->useCookie && !headers_sent()) {
         unset($_COOKIE[$this->name]);
         setcookie($this->name, '', time() - 100, $this->cookiePath, $this->cookieDomain, $this->cookieSecure, $this->cookieHttpOnly);
     }
     $this->isNew = true;
     $this->bucket = null;
     $this->id = null;
 }
Example #5
0
 public function load($id, $context = null, $returnNewBucket = true)
 {
     if (!Bucket::isValidId($id)) {
         return false;
     }
     if (!isset($_SESSION[$this->containerName]) || !isset($_SESSION[$this->containerName][$id])) {
         return false;
     }
     /** @var $b \Cyantree\Grout\Bucket\PhpSessionBucket */
     $b = $_SESSION[$this->containerName][$id];
     if ($context !== false && $b->context != $context) {
         return false;
     }
     if (!$returnNewBucket) {
         $this->_mergeSettings($b);
         $this->id = $b->id;
         $this->data = $b->data;
         $this->expires = $b->expires;
         $this->context = $b->context;
         $b = $this;
     }
     return $b;
 }
Example #6
0
 public function load($id, $context = null, $returnNewBucket = true)
 {
     if (!Bucket::isValidId($id)) {
         return false;
     }
     $data = DoctrineTools::prepareQuery($this->connection, 'SELECT expiresOn, data, context FROM ' . $this->table . ' WHERE id = %t%', array($id), Database::FILTER_ROW);
     $data->execute();
     $data = $data->fetch();
     if (!$data) {
         return false;
     }
     // >> Lower columns to circumvent database inconsistencies
     $d = $data;
     $data = array();
     foreach ($d as $k => $v) {
         $data[strtolower($k)] = $v;
     }
     $expires = DateTime::$utc->setBySqlString($data['expireson'])->getTimestamp();
     if ($expires < time()) {
         DoctrineTools::prepareQuery($this->connection, 'DELETE FROM ' . $this->table . ' WHERE id = %t%', $id)->execute();
         return false;
     }
     if ($context !== false && $data['context'] != $context) {
         return false;
     }
     if ($returnNewBucket) {
         $b = new DoctrineBucket($this->connection);
         $b->_mergeSettings($this);
     } else {
         $b = $this;
     }
     $b->connection = $this->connection;
     $b->table = $this->table;
     $b->id = $id;
     $b->expires = $expires;
     $b->data = unserialize(base64_decode($data['data']));
     $b->context = $data['context'];
     return $b;
 }