Conditions | 8 |
Paths | 6 |
Total Lines | 26 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
25 | private function setExpires(bool|int|string|\DateTimeInterface $ttl): void |
||
26 | { |
||
27 | if ($ttl instanceof \DateTimeInterface) { |
||
28 | $this->expires = $ttl->getTimestamp(); |
||
29 | return; |
||
30 | } |
||
31 | |||
32 | //Срок действия cookie истечет с окончанием сессии (при закрытии браузера). |
||
33 | if ($ttl === 0 || $ttl === true || strtolower((string)$ttl) === 'session') { |
||
34 | $this->expires = 0; |
||
35 | return; |
||
36 | } |
||
37 | |||
38 | // Если число, то прибавляем значение к метке времени timestamp |
||
39 | // Для установки сессионной куки надо использовать FALSE |
||
40 | if (is_numeric($ttl)) { |
||
41 | $this->expires = $this->currentTimestamp + (int)$ttl; |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | if (is_string($ttl)) { |
||
46 | if (false !== $returnTtl = strtotime($ttl, $this->currentTimestamp)) { |
||
47 | $this->expires = $returnTtl; |
||
48 | return; |
||
49 | } |
||
50 | throw new NotCorrectTtlString($ttl); |
||
51 | } |
||
60 |