Passed
Branch master (257598)
by refat
11:21
created

Response   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 88
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A sendOutput() 0 3 1
A send() 0 5 1
A sendHeaders() 0 4 2
A setOutput() 0 3 1
A __construct() 0 3 1
A setHeader() 0 3 1
1
<?php
2
3
namespace System\Http;
4
5
use System\Application;
6
7
class Response
8
{
9
  /**
10
   * Application Object
11
   *
12
   * @var \System\Application
13
   */
14
  private $app;
15
16
  /**
17
   * Headers container will be sent to the browser
18
   *
19
   * @var array
20
   */
21
  private $headers = [];
22
23
  /**
24
   * The content will be sent to the browser
25
   *
26
   * @var string
27
   */
28
  private $content = '';
29
30
  /**
31
   * Constructor
32
   *
33
   * @param \System\Application $app
34
   */
35
  public function __construct(Application $app)
36
  {
37
    $this->app = $app;
38
  }
39
40
  /**
41
   * Set the response output content
42
   *
43
   * @param string $content
44
   * @return void
45
   */
46
  public function setOutput($content)
47
  {
48
    $this->content = $content;
49
  }
50
51
  /**
52
   * Set the response Headers
53
   *
54
   * @param string $header
55
   * @param mixed $value
56
   * @return void
57
   */
58
  public function setHeader($header, $value)
59
  {
60
    $this->headers[$header] = $value;
61
  }
62
63
  /**
64
   * Send the response headers and content
65
   *
66
   * @return void
67
   */
68
  public function send()
69
  {
70
    $this->sendHeaders();
71
72
    $this->sendOutput();
73
  }
74
75
  /**
76
   * Send the response headers
77
   *
78
   * @return void
79
   */
80
  private function sendHeaders()
81
  {
82
    foreach ($this->headers as $header => $value) {
83
      header($header . ':' . $value);
84
    }
85
  }
86
87
  /**
88
   * Send the response output
89
   *
90
   * @return void
91
   */
92
  private function sendOutput()
93
  {
94
    echo $this->content;
95
  }
96
}
97