This repository has been archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequest.php
120 lines (105 loc) · 2.38 KB
/
Request.php
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
<?php
/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
*/
namespace Ulrack\Transaction\Component;
use Ulrack\Transaction\Common\RequestInterface;
use Ulrack\Transaction\Common\MethodEnum;
use Ulrack\Transaction\Exception\HeaderNotFoundException;
class Request implements RequestInterface
{
/** @var MethodEnum */
private $method;
/** @var array */
private $headers;
/** @var string */
private $target;
/** @var mixed */
private $payload;
/** @var array */
private $parameters;
/**
* Constructor
*
* @param MethodEnum $method
* @param string $target
* @param array $parameters
* @param mixed $payload
* @param array $headers
*/
public function __construct(
MethodEnum $method,
string $target,
array $parameters = [],
$payload = null,
array $headers = []
) {
$this->method = $method;
$this->target = $target;
$this->payload = $payload;
$this->headers = $headers;
$this->parameters = $parameters;
}
/**
* Retrieves the method of the request.
*
* @return MethodEnum
*/
public function getMethod(): MethodEnum
{
return $this->method;
}
/**
* Retrieves the request headers.
*
* @return string[]
*/
public function getHeaders(): array
{
return $this->headers;
}
/**
* Retrieves a header by its' name.
*
* @param string $name
*
* @return string
*
* @throws HeaderNotFoundException If the header is not set.
*/
public function getHeader(string $name): string
{
if (isset($this->headers[$name])) {
return $this->headers[$name];
}
throw new HeaderNotFoundException($name);
}
/**
* Retrieves the target of the request.
*
* @return string
*/
public function getTarget(): string
{
return $this->target;
}
/**
* Retrieves the payload of the request.
*
* @return mixed
*/
public function getPayload()
{
return $this->payload;
}
/**
* Retrieves a associative array of parameters of the request.
*
* @return array
*/
public function getParameters(): array
{
return $this->parameters;
}
}