-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathRequest.php
More file actions
190 lines (149 loc) · 2.98 KB
/
Request.php
File metadata and controls
190 lines (149 loc) · 2.98 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
declare(strict_types=1);
namespace Nette\Application;
use Nette;
/**
* Presenter request.
*
* @property-deprecated string $presenterName
* @property-deprecated array $parameters
* @property-deprecated array $post
* @property-deprecated array $files
* @property-deprecated string|null $method
*/
final class Request
{
use Nette\SmartObject;
/** method */
public const FORWARD = 'FORWARD';
/** flag */
public const RESTORED = 'restored';
/** flag */
public const VARYING = 'varying';
public function __construct(
private string $name,
private ?string $method = null,
private array $params = [],
private array $post = [],
private array $files = [],
private array $flags = [],
) {
}
/**
* Sets the presenter name.
*/
public function setPresenterName(string $name): static
{
$this->name = $name;
return $this;
}
/**
* Retrieve the presenter name.
*/
public function getPresenterName(): string
{
return $this->name;
}
/**
* Sets variables provided to the presenter.
*/
public function setParameters(array $params): static
{
$this->params = $params;
return $this;
}
/**
* Returns all variables provided to the presenter (usually via URL).
*/
public function getParameters(): array
{
return $this->params;
}
/**
* Returns a parameter provided to the presenter.
*/
public function getParameter(string $key): mixed
{
return $this->params[$key] ?? null;
}
/**
* Sets variables provided to the presenter via POST.
*/
public function setPost(array $params): static
{
$this->post = $params;
return $this;
}
/**
* Returns a variable provided to the presenter via POST.
* If no key is passed, returns the entire array.
*/
public function getPost(?string $key = null): mixed
{
return func_num_args() === 0
? $this->post
: ($this->post[$key] ?? null);
}
/**
* Sets all uploaded files.
*/
public function setFiles(array $files): static
{
$this->files = $files;
return $this;
}
/**
* Returns all uploaded files.
*/
public function getFiles(): array
{
return $this->files;
}
/**
* Sets the method.
*/
public function setMethod(?string $method): static
{
$this->method = $method;
return $this;
}
/**
* Returns the method.
*/
public function getMethod(): ?string
{
return $this->method;
}
/**
* Checks if the method is the given one.
*/
public function isMethod(string $method): bool
{
return strcasecmp($this->method, $method) === 0;
}
/**
* Sets the flag.
*/
public function setFlag(string $flag, bool $value = true): static
{
$this->flags[$flag] = $value;
return $this;
}
/**
* Checks the flag.
*/
public function hasFlag(string $flag): bool
{
return !empty($this->flags[$flag]);
}
public function toArray(): array
{
$params = $this->params;
$params['presenter'] = $this->name;
return $params;
}
}