Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
SessionObject.php
Go to the documentation of this file.
1<?php
2
4
6 protected $value;
7 protected $duration;
8 protected int $creationTime;
9
10 public function __construct($value, $duration) {
11 $this->value = $value;
12 $this->duration = $duration;
13 $this->creationTime = time ();
14 }
15
20 public function getValue() {
21 if (! $this->isExpired ()) {
22 return $this->value;
23 }
24 return;
25 }
26
31 public function getDuration() {
32 return $this->duration;
33 }
34
39 public function getCreationTime(): int {
40 return $this->creationTime;
41 }
42
48 public function setValue($value) {
49 if ($value !== $this->value) {
50 $this->creationTime = time();
51 }
52 return $this->value = $value;
53 }
54
59 public function setDuration($duration) {
60 $this->duration = $duration;
61 }
62
67 public function isExpired(): bool {
68 return \time () - $this->creationTime > $this->duration;
69 }
70
75 public function getTimeout(): int {
76 $timeout = $this->duration - (\time () - $this->creationTime);
77 if ($timeout > 0) {
78 return $timeout;
79 }
80 return 0;
81 }
82}
83