| @@ 176-197 (lines=22) @@ | ||
| 173 | /** |
|
| 174 | * {@inheritdoc} |
|
| 175 | */ |
|
| 176 | public function expiresAt($expiration = null) |
|
| 177 | { |
|
| 178 | if ($expiration instanceof \DateTime) { |
|
| 179 | $this->expiration = $expiration; |
|
| 180 | ||
| 181 | } elseif (is_int($expiration)) { |
|
| 182 | $this->expiration = new \DateTime( |
|
| 183 | 'now +' . $expiration . ' seconds' |
|
| 184 | ); |
|
| 185 | ||
| 186 | } elseif (null === $expiration) { |
|
| 187 | $this->expiration = new \DateTime(self::DEFAULT_EXPIRATION); |
|
| 188 | ||
| 189 | } else { |
|
| 190 | ||
| 191 | throw new InvalidArgumentException( |
|
| 192 | 'Integer or \DateTime object expected.' |
|
| 193 | ); |
|
| 194 | } |
|
| 195 | ||
| 196 | return $this; |
|
| 197 | } |
|
| 198 | ||
| 199 | /** |
|
| 200 | * {@inheritdoc} |
|
| @@ 202-222 (lines=21) @@ | ||
| 199 | /** |
|
| 200 | * {@inheritdoc} |
|
| 201 | */ |
|
| 202 | public function expiresAfter($time) |
|
| 203 | { |
|
| 204 | if ($time instanceof \DateInterval) { |
|
| 205 | $this->expiration = new \DateTime(); |
|
| 206 | $this->expiration->add($time); |
|
| 207 | ||
| 208 | } elseif (is_int($time)) { |
|
| 209 | $this->expiration = new \DateTime('now +' . $time . ' seconds'); |
|
| 210 | ||
| 211 | } elseif (null === $time) { |
|
| 212 | $this->expiration = new \DateTime(self::DEFAULT_EXPIRATION); |
|
| 213 | ||
| 214 | } else { |
|
| 215 | ||
| 216 | throw new InvalidArgumentException( |
|
| 217 | 'Integer or \DateInterval object expected.' |
|
| 218 | ); |
|
| 219 | } |
|
| 220 | ||
| 221 | return $this; |
|
| 222 | } |
|
| 223 | ||
| 224 | } |
|
| 225 | ||