Ubiquity  2.0.3
php rapid development framework
SessionObject.php
Go to the documentation of this file.
1 <?php
2 
4 
5 class SessionObject {
6  protected $value;
7  protected $duration;
8  protected $creationTime;
9 
10  public function __construct($value,$duration){
11  $this->value=$value;
12  $this->duration=$duration;
13  $this->creationTime=time();
14  }
18  public function getValue() {
19  if(!$this->isExpired())
20  return $this->value;
21  return;
22  }
23 
27  public function getDuration() {
28  return $this->duration;
29  }
30 
34  public function getCreationTime() {
35  return $this->creationTime;
36  }
37 
41  public function setValue($value) {
42  if($value!==$this->value)
43  $this->creationTime=time();
44  return $this->value = $value;
45  }
46 
50  public function setDuration($duration) {
51  $this->duration = $duration;
52  }
53 
57  public function isExpired(){
58  return time()-$this->creationTime>$this->duration;
59  }
60 
64  public function getTimeout(){
65  $timeout= $this->duration-(time()-$this->creationTime);
66  if($timeout>0)
67  return $timeout;
68  return 0;
69  }
70 
71 }
72