| @@ 129-145 (lines=17) @@ | ||
| 126 | /** |
|
| 127 | * {@inheritdoc} |
|
| 128 | */ |
|
| 129 | public function setExpiration($ttl = null) |
|
| 130 | { |
|
| 131 | if ($ttl instanceof \DateTime) { |
|
| 132 | $this->expiration = $ttl; |
|
| 133 | } elseif (is_numeric($ttl)) { |
|
| 134 | $this->expiration = new \DateTime('now +' . $ttl . ' seconds'); |
|
| 135 | } elseif (is_null($ttl)) { |
|
| 136 | // stored permanently or for as long as the default value. |
|
| 137 | $this->expiration = new \DateTime(self::DEFAULT_EXPIRATION); |
|
| 138 | } else { |
|
| 139 | throw new InvalidArgumentException( |
|
| 140 | 'Integer or \DateTime object expected.' |
|
| 141 | ); |
|
| 142 | } |
|
| 143 | ||
| 144 | return $this; |
|
| 145 | } |
|
| 146 | ||
| 147 | /** |
|
| 148 | * {@inheritdoc} |
|
| @@ 190-209 (lines=20) @@ | ||
| 187 | /** |
|
| 188 | * {@inheritdoc} |
|
| 189 | */ |
|
| 190 | public function expiresAfter($time) |
|
| 191 | { |
|
| 192 | if ($time instanceof \DateInterval) { |
|
| 193 | $this->expiration = new \DateTime(); |
|
| 194 | $this->expiration->add($time); |
|
| 195 | ||
| 196 | } elseif (is_numeric($time)) { |
|
| 197 | $this->expiration = new \DateTime('now +' . $time . ' seconds'); |
|
| 198 | ||
| 199 | } elseif (null === $time) { |
|
| 200 | // stored permanently or for as long as the default value. |
|
| 201 | $this->expiration = new \DateTime(self::DEFAULT_EXPIRATION); |
|
| 202 | } else { |
|
| 203 | throw new InvalidArgumentException( |
|
| 204 | 'Integer or \DateInterval object expected.' |
|
| 205 | ); |
|
| 206 | } |
|
| 207 | ||
| 208 | return $this; |
|
| 209 | } |
|
| 210 | ||
| 211 | } |
|
| 212 | ||