1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Equip; |
4
|
|
|
|
5
|
|
|
use Equip\Action; |
6
|
|
|
use Equip\Compatibility\StructureWithDataAlias; |
7
|
|
|
use Equip\Exception\DirectoryException; |
8
|
|
|
use Equip\Structure\Dictionary; |
9
|
|
|
|
10
|
|
|
class Directory extends Dictionary |
11
|
|
|
{ |
12
|
|
|
use StructureWithDataAlias; |
13
|
|
|
|
14
|
|
|
const ANY = '*'; |
15
|
|
|
const GET = 'GET'; |
16
|
|
|
const POST = 'POST'; |
17
|
|
|
const PUT = 'PUT'; |
18
|
|
|
const PATCH = 'PATCH'; |
19
|
|
|
const HEAD = 'HEAD'; |
20
|
|
|
const DELETE = 'DELETE'; |
21
|
|
|
const OPTIONS = 'OPTIONS'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param string $path |
25
|
|
|
* @param string|Action $domainOrAction |
26
|
|
|
* |
27
|
|
|
* @return static |
28
|
|
|
*/ |
29
|
1 |
|
public function any($path, $domainOrAction) |
30
|
|
|
{ |
31
|
1 |
|
return $this->action(self::ANY, $path, $domainOrAction); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $path |
36
|
|
|
* @param string|Action $domainOrAction |
37
|
|
|
* |
38
|
|
|
* @return static |
39
|
|
|
*/ |
40
|
3 |
|
public function get($path, $domainOrAction) |
41
|
|
|
{ |
42
|
3 |
|
return $this->action(self::GET, $path, $domainOrAction); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $path |
47
|
|
|
* @param string|Action $domainOrAction |
48
|
|
|
* |
49
|
|
|
* @return static |
50
|
|
|
*/ |
51
|
1 |
|
public function post($path, $domainOrAction) |
52
|
|
|
{ |
53
|
1 |
|
return $this->action(self::POST, $path, $domainOrAction); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $path |
58
|
|
|
* @param string|Action $domainOrAction |
59
|
|
|
* |
60
|
|
|
* @return static |
61
|
|
|
*/ |
62
|
1 |
|
public function put($path, $domainOrAction) |
63
|
|
|
{ |
64
|
1 |
|
return $this->action(self::PUT, $path, $domainOrAction); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param string $path |
69
|
|
|
* @param string|Action $domainOrAction |
70
|
|
|
* |
71
|
|
|
* @return static |
72
|
|
|
*/ |
73
|
1 |
|
public function patch($path, $domainOrAction) |
74
|
|
|
{ |
75
|
1 |
|
return $this->action(self::PATCH, $path, $domainOrAction); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $path |
80
|
|
|
* @param string|Action $domainOrAction |
81
|
|
|
* |
82
|
|
|
* @return static |
83
|
|
|
*/ |
84
|
1 |
|
public function head($path, $domainOrAction) |
85
|
|
|
{ |
86
|
1 |
|
return $this->action(self::HEAD, $path, $domainOrAction); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $path |
91
|
|
|
* @param string|Action $domainOrAction |
92
|
|
|
* |
93
|
|
|
* @return static |
94
|
|
|
*/ |
95
|
1 |
|
public function delete($path, $domainOrAction) |
96
|
|
|
{ |
97
|
1 |
|
return $this->action(self::DELETE, $path, $domainOrAction); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $path |
102
|
|
|
* @param string|Action $domainOrAction |
103
|
|
|
* |
104
|
|
|
* @return static |
105
|
|
|
*/ |
106
|
1 |
|
public function options($path, $domainOrAction) |
107
|
|
|
{ |
108
|
1 |
|
return $this->action(self::OPTIONS, $path, $domainOrAction); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $method |
113
|
|
|
* @param string $path |
114
|
|
|
* @param string|Action $domainOrAction |
115
|
|
|
* |
116
|
|
|
* @return static |
117
|
|
|
*/ |
118
|
12 |
|
public function action($method, $path, $domainOrAction) |
119
|
|
|
{ |
120
|
12 |
|
if ($domainOrAction instanceof Action) { |
121
|
11 |
|
$action = $domainOrAction; |
122
|
11 |
|
} else { |
123
|
1 |
|
$action = new Action($domainOrAction); |
124
|
|
|
} |
125
|
|
|
|
126
|
12 |
|
return $this->withValue(sprintf('%s %s', $method, $path), $action); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @inheritDoc |
131
|
|
|
* |
132
|
|
|
* @throws DirectoryException If a value is not an Action instance |
133
|
|
|
*/ |
134
|
15 |
|
protected function assertValid(array $data) |
135
|
|
|
{ |
136
|
15 |
|
parent::assertValid($data); |
137
|
|
|
|
138
|
15 |
|
foreach ($data as $value) { |
139
|
13 |
|
if (!is_object($value) || !$value instanceof Action) { |
140
|
1 |
|
throw DirectoryException::invalidEntry($value); |
141
|
|
|
} |
142
|
15 |
|
} |
143
|
15 |
|
} |
144
|
|
|
} |
145
|
|
|
|