We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 24 | class Frontpage |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var Response |
||
| 28 | */ |
||
| 29 | private $response; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var Webpage |
||
| 33 | */ |
||
| 34 | private $webpage; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var Page |
||
| 38 | */ |
||
| 39 | private $model; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Frontpage constructor. |
||
| 43 | * @param Page $model |
||
| 44 | * @param Collection $navigationRepository |
||
| 45 | */ |
||
| 46 | public function __construct(Page $model, Collection $navigationRepository) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param string|null $template |
||
| 55 | * @param bool $override |
||
| 56 | * @param int $status |
||
| 57 | * @param bool $errorResponse |
||
| 58 | * @return Response |
||
| 59 | */ |
||
| 60 | public function publish(string $template = null, bool $override = true, int $status = 200, bool $errorResponse = false) |
||
|
|
|||
| 61 | { |
||
| 62 | if (!$errorResponse) { |
||
| 63 | if ($this->isMaintenanceMode() && ! $this->canBypassMaintenance()) { |
||
| 64 | return ErrorController::maintenance(); |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($this->isDisabledPage($this->model)) { |
||
| 68 | return ErrorController::disabled(); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | return $this->response->view($this->makeBlade($template, $override), ['webpage' => $this->webpage], $status); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * A user can disable a webpage from being viewed. |
||
| 77 | * |
||
| 78 | * @param Page $page |
||
| 79 | * @return bool |
||
| 80 | */ |
||
| 81 | private function isDisabledPage(Page $page) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Check if the website is in maintenance mode |
||
| 88 | * which is set by the user on the dashboard. |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | public function isMaintenanceMode() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Check if the current logged in user if exists, |
||
| 99 | * can bypass the maintenance and view it offline. |
||
| 100 | * |
||
| 101 | * @return bool |
||
| 102 | */ |
||
| 103 | public function canBypassMaintenance() |
||
| 104 | { |
||
| 105 | return auth()->check() == true; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param string|null $template |
||
| 110 | * @param bool $override |
||
| 111 | * @return string |
||
| 112 | */ |
||
| 113 | private function makeBlade(string $template = null, bool $override = true) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $title |
||
| 128 | * @param string $description |
||
| 129 | * @param string $template |
||
| 130 | * @param int $response |
||
| 131 | * @return Response |
||
| 132 | */ |
||
| 133 | public static function build(string $title, string $description, string $template, int $response) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Return a drafted page without response headers. |
||
| 144 | * |
||
| 145 | * @return Webpage |
||
| 146 | */ |
||
| 147 | public function draft() |
||
| 151 | } |
||
| 152 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.