1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Equip; |
4
|
|
|
|
5
|
|
|
use Equip\Action; |
6
|
|
|
use Destrukt\Dictionary; |
7
|
|
|
use Equip\Exception\DirectoryException; |
8
|
|
|
|
9
|
|
|
class Directory extends Dictionary |
10
|
|
|
{ |
11
|
|
|
const GET = 'GET'; |
|
|
|
|
12
|
|
|
const POST = 'POST'; |
|
|
|
|
13
|
|
|
const PUT = 'PUT'; |
|
|
|
|
14
|
|
|
const PATCH = 'PATCH'; |
|
|
|
|
15
|
|
|
const HEAD = 'HEAD'; |
|
|
|
|
16
|
|
|
const DELETE = 'DELETE'; |
|
|
|
|
17
|
|
|
const OPTIONS = 'OPTIONS'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @inheritDoc |
21
|
|
|
* |
22
|
|
|
* @throws DirectoryException If a value is not an Action instance |
23
|
|
|
*/ |
24
|
12 |
|
public function validate(array $data) |
25
|
|
|
{ |
26
|
12 |
|
parent::validate($data); |
27
|
|
|
|
28
|
12 |
|
foreach ($data as $value) { |
29
|
12 |
|
if (!is_object($value) || !$value instanceof Action) { |
30
|
12 |
|
throw DirectoryException::invalidEntry($value); |
31
|
|
|
} |
32
|
|
|
} |
33
|
11 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $path |
37
|
|
|
* @param string|Action $domainOrAction |
38
|
|
|
* |
39
|
|
|
* @return static |
40
|
|
|
*/ |
41
|
3 |
|
public function get($path, $domainOrAction) |
42
|
|
|
{ |
43
|
3 |
|
return $this->action(self::GET, $path, $domainOrAction); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $path |
48
|
|
|
* @param string|Action $domainOrAction |
49
|
|
|
* |
50
|
|
|
* @return static |
51
|
|
|
*/ |
52
|
1 |
|
public function post($path, $domainOrAction) |
53
|
|
|
{ |
54
|
1 |
|
return $this->action(self::POST, $path, $domainOrAction); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $path |
59
|
|
|
* @param string|Action $domainOrAction |
60
|
|
|
* |
61
|
|
|
* @return static |
62
|
|
|
*/ |
63
|
1 |
|
public function put($path, $domainOrAction) |
64
|
|
|
{ |
65
|
1 |
|
return $this->action(self::PUT, $path, $domainOrAction); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $path |
70
|
|
|
* @param string|Action $domainOrAction |
71
|
|
|
* |
72
|
|
|
* @return static |
73
|
|
|
*/ |
74
|
1 |
|
public function patch($path, $domainOrAction) |
75
|
|
|
{ |
76
|
1 |
|
return $this->action(self::PATCH, $path, $domainOrAction); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $path |
81
|
|
|
* @param string|Action $domainOrAction |
82
|
|
|
* |
83
|
|
|
* @return static |
84
|
|
|
*/ |
85
|
1 |
|
public function head($path, $domainOrAction) |
86
|
|
|
{ |
87
|
1 |
|
return $this->action(self::HEAD, $path, $domainOrAction); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $path |
92
|
|
|
* @param string|Action $domainOrAction |
93
|
|
|
* |
94
|
|
|
* @return static |
95
|
|
|
*/ |
96
|
1 |
|
public function delete($path, $domainOrAction) |
97
|
|
|
{ |
98
|
1 |
|
return $this->action(self::DELETE, $path, $domainOrAction); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param string $path |
103
|
|
|
* @param string|Action $domainOrAction |
104
|
|
|
* |
105
|
|
|
* @return static |
106
|
|
|
*/ |
107
|
1 |
|
public function options($path, $domainOrAction) |
108
|
|
|
{ |
109
|
1 |
|
return $this->action(self::OPTIONS, $path, $domainOrAction); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param string $method |
114
|
|
|
* @param string $path |
115
|
|
|
* @param string|Action $domainOrAction |
116
|
|
|
* |
117
|
|
|
* @return static |
118
|
|
|
*/ |
119
|
11 |
|
public function action($method, $path, $domainOrAction) |
120
|
|
|
{ |
121
|
11 |
|
if ($domainOrAction instanceof Action) { |
122
|
10 |
|
$action = $domainOrAction; |
123
|
|
|
} else { |
124
|
1 |
|
$action = new Action($domainOrAction); |
125
|
|
|
} |
126
|
|
|
|
127
|
11 |
|
return $this->withValue("$method $path", $action); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.