1 | <?php |
||
6 | class Controller |
||
7 | { |
||
8 | /** |
||
9 | * The controller has to know the model to access the data stored there. |
||
10 | * @var Model $model contains the Model object. |
||
11 | */ |
||
12 | public $model; |
||
13 | |||
14 | protected $negotiator; |
||
15 | |||
16 | protected $languages; |
||
17 | |||
18 | /** |
||
19 | * Initializes the Model object. |
||
20 | */ |
||
21 | public function __construct($model) |
||
42 | |||
43 | /** |
||
44 | * Sets the locale language properties from the parameter (used by gettext and some Model classes). |
||
45 | * @param string $lang language parameter eg. 'fi' for Finnish. |
||
46 | */ |
||
47 | public function setLanguageProperties($lang) |
||
58 | |||
59 | /** |
||
60 | * Negotiate a MIME type according to the proposed format, the list of valid |
||
61 | * formats, and an optional proposed format. |
||
62 | * As a side effect, set the HTTP Vary header if a choice was made based on |
||
63 | * the Accept header. |
||
64 | * @param array $choices possible MIME types as strings |
||
65 | * @param string $accept HTTP Accept header value |
||
66 | * @param string $format proposed format |
||
67 | * @return string selected format, or null if negotiation failed |
||
68 | */ |
||
69 | protected function negotiateFormat($choices, $accept, $format) |
||
84 | |||
85 | private function isSecure() |
||
86 | { |
||
87 | if ($protocol = filter_input(INPUT_SERVER, 'HTTP_X_FORWARDED_PROTO', FILTER_SANITIZE_STRING)) { |
||
88 | return \in_array(strtolower($protocol), ['https', 'on', 'ssl', '1'], true); |
||
89 | } |
||
90 | |||
91 | return filter_input(INPUT_SERVER, 'HTTPS', FILTER_SANITIZE_STRING) !== null; |
||
92 | } |
||
93 | |||
94 | private function guessBaseHref() |
||
112 | |||
113 | public function getBaseHref() |
||
117 | |||
118 | /** |
||
119 | * Creates Skosmos links from uris. |
||
120 | * @param string $uri |
||
121 | * @param Vocabulary $vocab |
||
122 | * @param string $lang |
||
123 | * @param string $type |
||
124 | * @param string $clang content |
||
125 | * @param string $term |
||
126 | * @throws Exception if the vocabulary ID is not found in configuration |
||
127 | * @return string containing the Skosmos link |
||
128 | */ |
||
129 | public function linkUrlFilter($uri, $vocab, $lang, $type = 'page', $clang = null, $term = null) { |
||
167 | |||
168 | /** |
||
169 | * Echos an error message when the request can't be fulfilled. |
||
170 | * @param string $code |
||
171 | * @param string $status |
||
172 | * @param string $message |
||
173 | */ |
||
174 | protected function returnError($code, $status, $message) |
||
180 | |||
181 | /** |
||
182 | * If the $modifiedDate is a valid DateTime, and if the $_SERVER variable contains the right info, and |
||
183 | * if the $modifiedDate is not more recent than the latest value in $_SERVER, then this function sets the |
||
184 | * HTTP 304 not modified and returns true.. |
||
185 | * |
||
186 | * If the $modifiedDate is still valid, then it sets the Last-Modified header, to be used by the browser for |
||
187 | * subsequent requests, and returns false. |
||
188 | * |
||
189 | * Otherwise, it returns false. |
||
190 | * |
||
191 | * @param DateTime $modifiedDate the last modified date to be compared against server's modified since information |
||
192 | * @return bool whether it sent the HTTP 304 not modified headers or not (useful for sending the response without |
||
193 | * further actions) |
||
194 | */ |
||
195 | protected function sendNotModifiedHeader($modifiedDate): bool |
||
207 | |||
208 | /** |
||
209 | * @return DateTime|null a DateTime object if the value exists in the $_SERVER variable, null otherwise |
||
210 | */ |
||
211 | protected function getIfModifiedSince() |
||
220 | |||
221 | /** |
||
222 | * Sends HTTP headers. Simply calls PHP built-in header function. But being |
||
223 | * a function here, it can easily be tested/mocked. |
||
224 | * |
||
225 | * @param $header string header to be sent |
||
226 | */ |
||
227 | protected function sendHeader($header) |
||
231 | } |
||
232 |