Completed
Push — master ( d99d38...fc2b8b )
by Sebastian
02:26
created

ContentResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Kartenmacherei\RestFramework\Response;
3
4
use Kartenmacherei\RestFramework\Response\Content\Content;
5
6
class ContentResponse implements Response
7
{
8
    /**
9
     * @var Content
10
     */
11
    private $content;
12
13
    /**
14
     * @param Content $content
15
     */
16
    public function __construct(Content $content)
17
    {
18
        $this->content = $content;
19
    }
20
21
    public function flush()
22
    {
23
        http_response_code($this->getResponseCode());
24
        header((new HttpHeader('Content-Type', $this->content->getContentType()->asString()))->asString());
25
26
        print($this->content->asString());
27
    }
28
29
    /**
30
     * @return int
31
     */
32
    protected function getResponseCode(): int
33
    {
34
        return 200;
35
    }
36
37
}
38