1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Phiremock. |
4
|
|
|
* |
5
|
|
|
* Phiremock is free software: you can redistribute it and/or modify |
6
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
8
|
|
|
* (at your option) any later version. |
9
|
|
|
* |
10
|
|
|
* Phiremock is distributed in the hope that it will be useful, |
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
* GNU General Public License for more details. |
14
|
|
|
* |
15
|
|
|
* You should have received a copy of the GNU General Public License |
16
|
|
|
* along with Phiremock. If not, see <http://www.gnu.org/licenses/>. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Mcustiel\Phiremock\Domain\Http; |
20
|
|
|
|
21
|
|
|
class Method |
22
|
|
|
{ |
23
|
|
|
/** @var string * */ |
24
|
|
|
private $method; |
25
|
|
|
|
26
|
|
|
public function __construct(string $method) |
27
|
|
|
{ |
28
|
|
|
$this->ensureIsValidHttpMethod($method); |
29
|
|
|
$this->method = strtolower($method); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public static function get(): self |
33
|
|
|
{ |
34
|
|
|
return new self(MethodsEnum::GET); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function post(): self |
38
|
|
|
{ |
39
|
|
|
return new self(MethodsEnum::POST); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function put(): self |
43
|
|
|
{ |
44
|
|
|
return new self(MethodsEnum::PUT); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function delete(): self |
48
|
|
|
{ |
49
|
|
|
return new self(MethodsEnum::DELETE); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function fetch(): self |
53
|
|
|
{ |
54
|
|
|
return new self(MethodsEnum::FETCH); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function options(): self |
58
|
|
|
{ |
59
|
|
|
return new self(MethodsEnum::OPTIONS); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public static function patch(): self |
63
|
|
|
{ |
64
|
|
|
return new self(MethodsEnum::PATCH); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function head(): self |
68
|
|
|
{ |
69
|
|
|
return new self(MethodsEnum::HEAD); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function asString(): string |
73
|
|
|
{ |
74
|
|
|
return $this->method; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function equals(self $other): bool |
78
|
|
|
{ |
79
|
|
|
return $this->asString() === $other->asString(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
private function ensureIsValidHttpMethod(string $method): void |
83
|
|
|
{ |
84
|
|
|
var_export('ensurer'); |
85
|
|
|
if (!MethodsEnum::isValid($method)) { |
86
|
|
|
throw new \InvalidArgumentException(sprintf('Invalid http method: %s', var_export($method, true))); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|