1
|
|
|
<?php namespace Comodojo\Dispatcher\Output; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Dispatcher\Components\Model as DispatcherClassModel; |
4
|
|
|
use \Comodojo\Dispatcher\Request\Model as Request; |
5
|
|
|
use \Comodojo\Dispatcher\Response\Model as Response; |
6
|
|
|
use \Comodojo\Dispatcher\Components\Configuration; |
7
|
|
|
use \Comodojo\Dispatcher\Components\HttpStatusCodes; |
8
|
|
|
use \Psr\Log\LoggerInterface; |
9
|
|
|
use \Exception; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @package Comodojo Dispatcher |
13
|
|
|
* @author Marco Giovinazzi <[email protected]> |
14
|
|
|
* @author Marco Castiello <[email protected]> |
15
|
|
|
* @license GPL-3.0+ |
16
|
|
|
* |
17
|
|
|
* LICENSE: |
18
|
|
|
* |
19
|
|
|
* This program is free software: you can redistribute it and/or modify |
20
|
|
|
* it under the terms of the GNU Affero General Public License as |
21
|
|
|
* published by the Free Software Foundation, either version 3 of the |
22
|
|
|
* License, or (at your option) any later version. |
23
|
|
|
* |
24
|
|
|
* This program is distributed in the hope that it will be useful, |
25
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
26
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27
|
|
|
* GNU Affero General Public License for more details. |
28
|
|
|
* |
29
|
|
|
* You should have received a copy of the GNU Affero General Public License |
30
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
// |
|
|
|
|
34
|
|
|
// @WARNING: some method's preprocessor missing |
35
|
|
|
// |
36
|
|
|
// _______ |
37
|
|
|
// j_______j |
38
|
|
|
// /_______/_\ |
39
|
|
|
// |Missing| | |
40
|
|
|
// | ___ | | |
41
|
|
|
// | !418! | | |
42
|
|
|
// | !___! | | |
43
|
|
|
// |_______|,' |
44
|
|
|
// |
45
|
|
|
|
46
|
|
|
class Processor extends DispatcherClassModel { |
47
|
|
|
|
48
|
4 |
View Code Duplication |
public function __construct(Configuration $configuration, LoggerInterface $logger, Request $request, Response $response) { |
|
|
|
|
49
|
|
|
|
50
|
4 |
|
parent::__construct($configuration, $logger); |
51
|
|
|
|
52
|
4 |
|
$this->response = $response; |
|
|
|
|
53
|
|
|
|
54
|
4 |
|
$this->request = $request; |
|
|
|
|
55
|
|
|
|
56
|
4 |
|
$this->codes = new HttpStatusCodes(); |
|
|
|
|
57
|
|
|
|
58
|
4 |
|
} |
59
|
|
|
|
60
|
4 |
|
public function send() { |
61
|
|
|
|
62
|
4 |
|
$status = $this->response->status->get(); |
|
|
|
|
63
|
|
|
|
64
|
4 |
|
if ( !$this->codes->exists($status) ) throw new Exception("Invalid HTTP status code in response"); |
|
|
|
|
65
|
|
|
|
66
|
4 |
|
$message = $this->codes->getMessage($status); |
|
|
|
|
67
|
|
|
|
68
|
4 |
|
$this->response->headers->send(); |
|
|
|
|
69
|
|
|
|
70
|
4 |
|
header(sprintf('HTTP/%s %s %s', $this->request->version->get(), $status, $message), true, $status); |
|
|
|
|
71
|
|
|
|
72
|
4 |
|
$this->response->cookies->save(); |
|
|
|
|
73
|
|
|
|
74
|
4 |
|
return $this->response->content->get(); |
|
|
|
|
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
4 |
|
public static function parse(Configuration $configuration, LoggerInterface $logger, Request $request, Response $response) { |
79
|
|
|
|
80
|
4 |
|
$processor = new Processor($configuration, $logger, $request, $response); |
81
|
|
|
|
82
|
4 |
|
return $processor->send(); |
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.