1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace ZfrCors\Options; |
20
|
|
|
|
21
|
|
|
use Zend\Stdlib\AbstractOptions; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* CorsOptions |
25
|
|
|
* |
26
|
|
|
* @license MIT |
27
|
|
|
* @author Florent Blaison <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class CorsOptions extends AbstractOptions |
30
|
|
|
{ |
31
|
|
|
const ROUTE_PARAM = 'cors'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Set the list of allowed origins domain with protocol. |
35
|
|
|
* |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $allowedOrigins = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Set the list of HTTP verbs. |
42
|
|
|
* |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $allowedMethods = []; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Set the list of headers. |
49
|
|
|
* |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $allowedHeaders = []; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the max age of the authorize request in seconds. |
56
|
|
|
* |
57
|
|
|
* @var int |
58
|
|
|
*/ |
59
|
|
|
protected $maxAge = 0; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set the list of exposed headers. |
63
|
|
|
* |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
protected $exposedHeaders = []; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Allow CORS request with credential. |
70
|
|
|
* |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
protected $allowedCredentials = false; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param array $allowedOrigins |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
public function setAllowedOrigins(array $allowedOrigins) |
80
|
|
|
{ |
81
|
|
|
$this->allowedOrigins = $allowedOrigins; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return array |
86
|
|
|
*/ |
87
|
|
|
public function getAllowedOrigins() |
88
|
|
|
{ |
89
|
|
|
return $this->allowedOrigins; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param array $allowedMethods |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
public function setAllowedMethods(array $allowedMethods) |
97
|
|
|
{ |
98
|
|
|
foreach ($allowedMethods as &$allowedMethod) { |
99
|
|
|
$allowedMethod = strtoupper($allowedMethod); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$this->allowedMethods = $allowedMethods; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array |
107
|
|
|
*/ |
108
|
|
|
public function getAllowedMethods() |
109
|
|
|
{ |
110
|
|
|
return $this->allowedMethods; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param array $allowedHeaders |
115
|
|
|
* @return void |
116
|
|
|
*/ |
117
|
|
|
public function setAllowedHeaders(array $allowedHeaders) |
118
|
|
|
{ |
119
|
|
|
$this->allowedHeaders = $allowedHeaders; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
|
|
public function getAllowedHeaders() |
126
|
|
|
{ |
127
|
|
|
return $this->allowedHeaders; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param int $maxAge |
132
|
|
|
* @return void |
133
|
|
|
*/ |
134
|
|
|
public function setMaxAge($maxAge) |
135
|
|
|
{ |
136
|
|
|
$this->maxAge = (int) $maxAge; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return int |
141
|
|
|
*/ |
142
|
|
|
public function getMaxAge() |
143
|
|
|
{ |
144
|
|
|
return $this->maxAge; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param array $exposedHeaders |
149
|
|
|
* @return void |
150
|
|
|
*/ |
151
|
|
|
public function setExposedHeaders(array $exposedHeaders) |
152
|
|
|
{ |
153
|
|
|
$this->exposedHeaders = $exposedHeaders; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return array |
158
|
|
|
*/ |
159
|
|
|
public function getExposedHeaders() |
160
|
|
|
{ |
161
|
|
|
return $this->exposedHeaders; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param bool $allowedCredentials |
166
|
|
|
* @return void |
167
|
|
|
*/ |
168
|
|
|
public function setAllowedCredentials($allowedCredentials) |
169
|
|
|
{ |
170
|
|
|
$this->allowedCredentials = (bool) $allowedCredentials; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return boolean |
175
|
|
|
*/ |
176
|
|
|
public function getAllowedCredentials() |
177
|
|
|
{ |
178
|
|
|
return $this->allowedCredentials; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|