1 | <?php |
||
10 | class MaintenanceModeExtension extends Extension |
||
|
|||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @throws SS_HTTPResponse_Exception |
||
15 | */ |
||
16 | public function onBeforeInit() |
||
17 | { |
||
18 | if($this->isDownForMaintenance() && !$this->clientIpIsAllowedInMaintenanceMode()) |
||
19 | { |
||
20 | $this->throw503(); |
||
21 | } |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @return bool |
||
26 | */ |
||
27 | public function isDownForMaintenance() |
||
31 | |||
32 | /** |
||
33 | * Somehow $this->owner->httpError keeps the website spinning. |
||
34 | * |
||
35 | * Maybe not very Silverstripe'sch, but at least this works |
||
36 | * |
||
37 | * @throws SS_HTTPResponse_Exception |
||
38 | */ |
||
39 | protected function throw503() |
||
40 | { |
||
41 | $message = 'Website is down for maintenance'; |
||
42 | $errorFile = $this->get503File(); |
||
43 | $content = is_file($errorFile) ? file_get_contents($errorFile) : '<h1>'.$message.'</h1>'; |
||
44 | |||
45 | throw new SS_HTTPResponse_Exception(new SS_HTTPResponse($content, 503, $message)); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | protected function get503File() |
||
57 | |||
58 | /** |
||
59 | * @return bool |
||
60 | */ |
||
61 | protected function clientIpIsAllowedInMaintenanceMode() |
||
68 | |||
69 | /** |
||
70 | * @return string|false |
||
71 | */ |
||
72 | protected function getClientIp() |
||
78 | |||
79 | /** |
||
80 | * @return array |
||
81 | */ |
||
82 | protected function getAllowedIpAddresses() |
||
86 | } |
||
87 |
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.