-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBodyParam.php
More file actions
46 lines (39 loc) · 1.03 KB
/
BodyParam.php
File metadata and controls
46 lines (39 loc) · 1.03 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
<?php
declare(strict_types=1);
namespace Core\Request\Parameters;
use CoreInterfaces\Core\Request\RequestSetterInterface;
class BodyParam extends Parameter
{
/**
* Initializes a body parameter with the value specified.
*/
public static function init($value): self
{
return new self('', $value);
}
/**
* Initializes a body parameter with the value and key provided.
*
* @param string $key
* @param mixed $value
*/
public static function initWrapped(string $key, $value): self
{
return new self($key, $value);
}
private function __construct(string $key, $value)
{
parent::__construct($key, $value, 'body');
}
/**
* Adds the parameter to the request provided.
*
* @param RequestSetterInterface $request The request to add the parameter to.
*/
public function apply(RequestSetterInterface $request): void
{
if ($this->validated) {
$request->addBodyParam($this->value, $this->key);
}
}
}