1
|
|
|
<?php namespace Comodojo\Dispatcher\Output\HttpStatus; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Status: Not Modified |
5
|
|
|
* |
6
|
|
|
* @package Comodojo Dispatcher |
7
|
|
|
* @author Marco Giovinazzi <[email protected]> |
8
|
|
|
* @author Marco Castiello <[email protected]> |
9
|
|
|
* @license GPL-3.0+ |
10
|
|
|
* |
11
|
|
|
* LICENSE: |
12
|
|
|
* |
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
16
|
|
|
* License, or (at your option) any later version. |
17
|
|
|
* |
18
|
|
|
* This program is distributed in the hope that it will be useful, |
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21
|
|
|
* GNU Affero General Public License for more details. |
22
|
|
|
* |
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
class Status304 extends AbstractHttpStatus { |
28
|
|
|
|
29
|
|
|
public function consolidate() { |
|
|
|
|
30
|
|
|
|
31
|
|
|
$last_modified = $this->response()->headers()->get('Last-Modified'); |
32
|
|
|
|
33
|
|
|
if ( is_null($last_modified) ) { |
34
|
|
|
|
35
|
|
|
header($_SERVER["SERVER_PROTOCOL"].' 304 Not Modified'); |
36
|
|
|
|
37
|
|
|
} else if ( is_int($last_modified) ) { |
38
|
|
|
|
39
|
|
|
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT', true, 304); |
40
|
|
|
|
41
|
|
|
} else { |
42
|
|
|
|
43
|
|
|
header('Last-Modified: '.$last_modified, true, 304); |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
header('Content-Length: '.$this->response()->content()->length()); |
48
|
|
|
|
49
|
|
|
$this->response()->headers()->remove('Last-Modified'); |
|
|
|
|
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: