-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathResponse.php
More file actions
138 lines (109 loc) · 2.72 KB
/
Response.php
File metadata and controls
138 lines (109 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php declare(strict_types = 1);
namespace Contributte\Codeception\Http;
use DateTimeInterface;
use Nette\Http\Helpers;
use Nette\Http\IResponse;
use Nette\Utils\DateTime;
/**
* HttpResponse class for tests.
*/
class Response implements IResponse
{
/** @var string The domain in which the cookie will be available */
public string $cookieDomain = '';
/** @var string The path in which the cookie will be available */
public string $cookiePath = '/';
/** @var bool Whether the cookie is available only through HTTPS */
public bool $cookieSecure = false;
private int $code = self::S200_OK;
/** @var string[] */
private array $headers = [];
public function reset(): void
{
$this->code = self::S200_OK;
$this->headers = [];
}
public function getCode(): int
{
return $this->code;
}
/**
* @return static
*/
public function setCode(int $code, ?string $reason = null): static
{
$this->code = $code;
return $this;
}
/**
* @return static
*/
public function setHeader(string $name, string $value): static
{
$this->headers[$name] = $value;
return $this;
}
/**
* @return static
*/
public function addHeader(string $name, string $value): static
{
$this->headers[$name] = $value;
return $this;
}
/**
* @return static
*/
public function setContentType(string $type, ?string $charset = null): static
{
$this->setHeader('Content-Type', $type . ($charset !== null ? '; charset=' . $charset : ''));
return $this;
}
public function redirect(string $url, int $code = self::S302_Found): void
{
$this->setCode($code);
$this->setHeader('Location', $url);
}
/**
* @return static
*/
public function setExpiration(?string $time): static
{
if (!$time) {
$this->setHeader('Cache-Control', 's-maxage=0, max-age=0, must-revalidate');
$this->setHeader('Expires', 'Mon, 23 Jan 1978 10:00:00 GMT');
return $this;
}
$time = DateTime::from($time);
$this->setHeader('Cache-Control', 'max-age=' . ((int) $time->format('U') - time()));
$this->setHeader('Expires', Helpers::formatDate($time));
return $this;
}
public function isSent(): bool
{
return false;
}
public function getHeader(string $name): ?string
{
return $this->headers[$name] ?? null;
}
/**
* @return string[]
*/
public function getHeaders(): array
{
return $this->headers;
}
/**
* @param string|int|DateTimeInterface $time
* @return static
*/
public function setCookie(string $name, string $value, mixed $time, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null, ?string $sameSite = null): static
{
return $this;
}
public function deleteCookie(string $name, ?string $path = null, ?string $domain = null, ?bool $secure = null): void
{
// No-op
}
}