| @@ 186-207 (lines=22) @@ | ||
| 183 | /** |
|
| 184 | * {@inheritdoc} |
|
| 185 | */ |
|
| 186 | public function expiresAt($expiration = null) |
|
| 187 | { |
|
| 188 | if ($expiration instanceof \DateTime) { |
|
| 189 | $this->expiration = $expiration; |
|
| 190 | ||
| 191 | } elseif (is_int($expiration)) { |
|
| 192 | $this->expiration = new \DateTime( |
|
| 193 | 'now +' . $expiration . ' seconds' |
|
| 194 | ); |
|
| 195 | ||
| 196 | } elseif (null === $expiration) { |
|
| 197 | $this->expiration = new \DateTime(self::DEFAULT_EXPIRATION); |
|
| 198 | ||
| 199 | } else { |
|
| 200 | ||
| 201 | throw new InvalidArgumentException( |
|
| 202 | 'Integer or \DateTime object expected.' |
|
| 203 | ); |
|
| 204 | } |
|
| 205 | ||
| 206 | return $this; |
|
| 207 | } |
|
| 208 | ||
| 209 | /** |
|
| 210 | * {@inheritdoc} |
|
| @@ 212-232 (lines=21) @@ | ||
| 209 | /** |
|
| 210 | * {@inheritdoc} |
|
| 211 | */ |
|
| 212 | public function expiresAfter($time) |
|
| 213 | { |
|
| 214 | if ($time instanceof \DateInterval) { |
|
| 215 | $this->expiration = new \DateTime(); |
|
| 216 | $this->expiration->add($time); |
|
| 217 | ||
| 218 | } elseif (is_int($time)) { |
|
| 219 | $this->expiration = new \DateTime('now +' . $time . ' seconds'); |
|
| 220 | ||
| 221 | } elseif (null === $time) { |
|
| 222 | $this->expiration = new \DateTime(self::DEFAULT_EXPIRATION); |
|
| 223 | ||
| 224 | } else { |
|
| 225 | ||
| 226 | throw new InvalidArgumentException( |
|
| 227 | 'Integer or \DateInterval object expected.' |
|
| 228 | ); |
|
| 229 | } |
|
| 230 | ||
| 231 | return $this; |
|
| 232 | } |
|
| 233 | ||
| 234 | /** |
|
| 235 | * Returns the item value. |
|