1 | <?php |
||
10 | class MaintenanceModeExtension extends Extension |
||
|
|||
11 | { |
||
12 | /** |
||
13 | * @throws SS_HTTPResponse_Exception |
||
14 | */ |
||
15 | public function onBeforeInit() |
||
16 | { |
||
17 | if ($this->isDownForMaintenance() && !$this->clientIpIsAllowedInMaintenanceMode()) { |
||
18 | $this->throw503(); |
||
19 | } |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @return bool |
||
24 | */ |
||
25 | public function isDownForMaintenance() |
||
29 | |||
30 | /** |
||
31 | * Somehow $this->owner->httpError keeps the website spinning. |
||
32 | * |
||
33 | * Maybe not very Silverstripe'sch, but at least this works |
||
34 | * |
||
35 | * @throws SS_HTTPResponse_Exception |
||
36 | */ |
||
37 | protected function throw503() |
||
38 | { |
||
39 | $message = 'Website is down for maintenance'; |
||
40 | $errorFile = $this->get503File(); |
||
41 | $content = is_file($errorFile) ? file_get_contents($errorFile) : '<h1>'.$message.'</h1>'; |
||
42 | |||
43 | throw new SS_HTTPResponse_Exception(new SS_HTTPResponse($content, 503, $message)); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return string |
||
48 | */ |
||
49 | protected function get503File() |
||
55 | |||
56 | /** |
||
57 | * @return bool |
||
58 | */ |
||
59 | protected function clientIpIsAllowedInMaintenanceMode() |
||
66 | |||
67 | /** |
||
68 | * @return string|false |
||
69 | */ |
||
70 | protected function getClientIp() |
||
76 | |||
77 | /** |
||
78 | * @return array |
||
79 | */ |
||
80 | protected function getAllowedIpAddresses() |
||
84 | } |
||
85 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.