1 | <?php |
||
47 | class Vhost implements VhostInterface |
||
48 | { |
||
49 | /** |
||
50 | * Primary domain |
||
51 | * |
||
52 | * @var DomainInterface |
||
53 | */ |
||
54 | protected $primaryDomain; |
||
55 | /** |
||
56 | * Secondary domains |
||
57 | * |
||
58 | * @var DomainInterface[] |
||
59 | */ |
||
60 | protected $secondaryDomains = []; |
||
61 | /** |
||
62 | * Document root |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $docroot; |
||
67 | /** |
||
68 | * Virtual host type |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $type = self::TYPE_APACHE; |
||
73 | /** |
||
74 | * Ports |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | protected $ports = []; |
||
79 | /** |
||
80 | * Active PHP version |
||
81 | * |
||
82 | * @var null|string |
||
83 | */ |
||
84 | protected $php = null; |
||
85 | /** |
||
86 | * Absolute URL to redirect to |
||
87 | * |
||
88 | * @var null|string |
||
89 | */ |
||
90 | protected $redirectUrl = null; |
||
91 | /** |
||
92 | * Redirect status code |
||
93 | * |
||
94 | * @var int |
||
95 | */ |
||
96 | protected $redirectStatus = 301; |
||
97 | /** |
||
98 | * Default port for HTTP virtual hosts |
||
99 | * |
||
100 | * @var int |
||
101 | */ |
||
102 | const PORT_HTTP_DEFAULT = 80; |
||
103 | /** |
||
104 | * Default port for HTTPS virtual hosts |
||
105 | * |
||
106 | * @var int |
||
107 | */ |
||
108 | const PORT_HTTPS_DEFAULT = 443; |
||
109 | /** |
||
110 | * HTTP protocol |
||
111 | * |
||
112 | * @var int |
||
113 | */ |
||
114 | const PROTOCOL_HTTP = 1; |
||
115 | /** |
||
116 | * HTTPS protocol |
||
117 | * |
||
118 | * @var int |
||
119 | */ |
||
120 | const PROTOCOL_HTTPS = 2; |
||
121 | /** |
||
122 | * Apache virtual host |
||
123 | * |
||
124 | * @var string |
||
125 | */ |
||
126 | const TYPE_APACHE = 'apache'; |
||
127 | /** |
||
128 | * Supported protocols |
||
129 | * |
||
130 | * @var array |
||
131 | */ |
||
132 | protected static $supportedProtocols = [ |
||
133 | self::PROTOCOL_HTTP => 'http', |
||
134 | self::PROTOCOL_HTTPS => 'https', |
||
135 | ]; |
||
136 | /** |
||
137 | * Default protocol ports |
||
138 | * |
||
139 | * @var array |
||
140 | */ |
||
141 | protected static $defaultProtocolPorts = [ |
||
142 | self::PROTOCOL_HTTP => 80, |
||
143 | self::PROTOCOL_HTTPS => 443, |
||
144 | ]; |
||
145 | |||
146 | /** |
||
147 | * Virtual host constructor |
||
148 | * |
||
149 | * @param DomainInterface $primaryDomain Primary domain |
||
150 | * @param string $docroot Document root |
||
151 | * @param string $type Virtual host type |
||
152 | * @internal param int $port Port |
||
153 | */ |
||
154 | 10 | public function __construct(DomainInterface $primaryDomain, $docroot, $type = self::TYPE_APACHE) |
|
160 | |||
161 | /** |
||
162 | * Return the primary domain |
||
163 | * |
||
164 | * @return DomainInterface Primary domain |
||
165 | */ |
||
166 | 2 | public function getPrimaryDomain() |
|
170 | |||
171 | /** |
||
172 | * Return the document root |
||
173 | * |
||
174 | * @return string Document root |
||
175 | */ |
||
176 | 1 | public function getDocroot() |
|
180 | |||
181 | /** |
||
182 | * Return the virtual host type |
||
183 | * |
||
184 | * @return string Virtual host type |
||
185 | */ |
||
186 | public function getType() |
||
190 | |||
191 | /** |
||
192 | * Return the port |
||
193 | * |
||
194 | * @param int $protocol Protocol |
||
195 | * @return int|null Port |
||
196 | * @throws \RuntimeException If the protocol is unsupported |
||
197 | */ |
||
198 | 3 | public function getPort($protocol) |
|
209 | |||
210 | /** |
||
211 | * Return all supported protocols and corresponding ports |
||
212 | * |
||
213 | * @return array Protocols and ports |
||
214 | */ |
||
215 | 1 | public function getPorts() |
|
219 | |||
220 | /** |
||
221 | * Return the secondary domains |
||
222 | * |
||
223 | * @return DomainInterface[] |
||
224 | */ |
||
225 | 1 | public function getSecondaryDomains() |
|
229 | |||
230 | /** |
||
231 | * Set the secondary domains |
||
232 | * |
||
233 | * @param DomainInterface[] $secondaryDomains |
||
234 | * @return Vhost Self reference |
||
235 | * @throws \RuntimeException If the domain is invalid |
||
236 | */ |
||
237 | 1 | public function setSecondaryDomains(array $secondaryDomains) |
|
253 | |||
254 | /** |
||
255 | * Add a secondary domain |
||
256 | * |
||
257 | * @param DomainInterface $secondaryDomain Secondary domain |
||
258 | * @return Vhost Self reference |
||
259 | */ |
||
260 | 1 | public function addSecondaryDomain(DomainInterface $secondaryDomain) |
|
267 | |||
268 | /** |
||
269 | * Remove a secondary domain |
||
270 | * |
||
271 | * @param DomainInterface $secondaryDomain Secondary domain |
||
272 | * @return Vhost Self reference |
||
273 | */ |
||
274 | 1 | public function removeSecondaryDomain(DomainInterface $secondaryDomain) |
|
279 | |||
280 | /** |
||
281 | * Return the active PHP version |
||
282 | * |
||
283 | * @return null|string Active PHP version |
||
284 | */ |
||
285 | 1 | public function getPhp() |
|
289 | |||
290 | /** |
||
291 | * Set the active PHP version |
||
292 | * |
||
293 | * @param null|string $php Active PHP version |
||
294 | * @return Vhost Self reference |
||
295 | * @throws \RuntimeException If the PHP version is invalid |
||
296 | */ |
||
297 | 1 | public function setPhp($php) |
|
307 | |||
308 | /** |
||
309 | * Enable a supported protocol |
||
310 | * |
||
311 | * @param int $protocol Protocol |
||
312 | * @param int $port Port |
||
313 | * @return Vhost Self reference |
||
314 | * @throws \RuntimeException If the protocol is unsupported |
||
315 | */ |
||
316 | 3 | public function enableProtocol($protocol, $port = null) |
|
333 | |||
334 | /** |
||
335 | * Disable a supported protocol |
||
336 | * |
||
337 | * @param int $protocol Protocol |
||
338 | * @return Vhost Self reference |
||
339 | * @throws \RuntimeException If the protocol is unsupported |
||
340 | */ |
||
341 | 2 | public function disableProtocol($protocol) |
|
353 | |||
354 | /** |
||
355 | * Return the redirect URL |
||
356 | * |
||
357 | * @return null|string Redirect URL |
||
358 | */ |
||
359 | 1 | public function getRedirectUrl() |
|
363 | |||
364 | /** |
||
365 | * Set the redirect URL |
||
366 | * |
||
367 | * @param null|string $redirectUrl Redirect URL |
||
368 | * @return Vhost Self reference |
||
369 | * @throws \RuntimeException If the redirect URL is invalid |
||
370 | */ |
||
371 | 1 | public function setRedirectUrl($redirectUrl) |
|
386 | |||
387 | /** |
||
388 | * Return the redirect HTTP status code |
||
389 | * |
||
390 | * @return int Redirect HTTP status code |
||
391 | */ |
||
392 | 1 | public function getRedirectStatus() |
|
396 | |||
397 | /** |
||
398 | * Set the redirect HTTP status code |
||
399 | * |
||
400 | * @param int $redirectStatus Redirect HTTP status code |
||
401 | * @return Vhost Self reference |
||
402 | */ |
||
403 | 1 | public function setRedirectStatus($redirectStatus) |
|
411 | } |
||
412 |