Completed
Push — 4.0 ( 7855d8...1b9fbe )
by Marco
11:07
created

Processor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 4
c 5
b 0
f 0
lcom 1
cbo 7
dl 0
loc 48
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B compose() 0 25 2
A parse() 0 7 1
1
<?php namespace Comodojo\Dispatcher\Output;
2
3
use \Comodojo\Dispatcher\Output\HttpStatus\StatusGeneric;
4
use \Comodojo\Dispatcher\Components\Model as DispatcherClassModel;
5
use \Comodojo\Dispatcher\Response\Model as Response;
6
use \Comodojo\Dispatcher\Components\Configuration;
7
use \Monolog\Logger;
8
9
/**
10
 * @package     Comodojo Dispatcher
11
 * @author      Marco Giovinazzi <[email protected]>
12
 * @author      Marco Castiello <[email protected]>
13
 * @license     GPL-3.0+
14
 *
15
 * LICENSE:
16
 *
17
 * This program is free software: you can redistribute it and/or modify
18
 * it under the terms of the GNU Affero General Public License as
19
 * published by the Free Software Foundation, either version 3 of the
20
 * License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU Affero General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU Affero General Public License
28
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29
 */
30
31
// Missing status codes
32
//         _______
33
//        j_______j
34
//       /_______/_\
35
//       |Missing| |
36
//       |  ___  | |
37
//       | !100! | |
38
//       | !___! | |
39
//       |_______|,'
40
//
41
//      // Informational 1xx
42
//      100 => "Continue",
43
//      101 => "Switching Protocols",
44
//      // Successful 2xx
45
//      203 => "Non-Authoritative Information",
46
//      205 => "Reset Content",
47
//      206 => "Partial Content",
48
//      // Redirection 3xx
49
//      300 => "Multiple Choices",
50
//      305 => "Use Proxy",
51
//      // Client Error 4xx
52
//      401 => "Unauthorized",
53
//      402 => "Payment Required",
54
//      406 => "Not Acceptable",
55
//      407 => "Proxy Authentication Required",
56
//      408 => "Request Timeout",
57
//      409 => "Conflict",
58
//      410 => "Gone",
59
//      411 => "Length Required",
60
//      412 => "Precondition Failed",
61
//      413 => "Request Entity Too Large",
62
//      414 => "Request-URI Too Long",
63
//      415 => "Unsupported Media Type",
64
//      416 => "Requested Range Not Satisfiable",
65
//      417 => "Expectation Failed",
66
//      // Server Error 5xx
67
//      502 => "Bad Gateway",
68
//      504 => "Gateway Timeout",
69
//      505 => "HTTP Version Not Supported"
70
71
class Processor extends DispatcherClassModel {
72
73
    private $response;
74
75
    public function __construct(Configuration $configuration, Logger $logger, Response $response) {
76
77
        parent::__construct($configuration, $logger);
78
79
        $this->response = $response;
80
81
    }
82
83
    public function compose() {
84
85
        $status = $this->response->status()->get();
86
87
        $output_class_name = "\\Comodojo\\Dispatcher\\Output\\HttpStatus\\Status".$status;
88
89
        if ( class_exists($output_class_name) ) {
90
91
            $output = new $output_class_name($this->response);
92
93
        } else {
94
95
            $output = new StatusGeneric($this->response);
96
97
        }
98
99
        $output->consolidate();
100
101
        $this->response->headers()->send();
102
103
        $this->response->cookies()->save();
104
105
        return $this->response->content()->get();
106
107
    }
108
109
    public static function parse(Configuration $configuration, Logger $logger, Response $response) {
110
111
        $processor = new Processor($configuration, $logger, $response);
112
113
        return $processor->compose();
114
115
    }
116
117
118
}
119