Passed
Push — master ( 9ddd07...b0cded )
by Radu
01:55
created

OutputTrait::setOutputLoader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebServCo\Framework\Traits;
3
4
use WebServCo\Framework\Http\Response;
5
6
trait OutputTrait
7
{
8
    protected $outputLoader;
9
10
    final protected function setOutputLoader(\WebServCo\Framework\AbstractOutputLoader $outputLoader)
11
    {
12
        $this->outputLoader = $outputLoader;
13
    }
14
15
    final protected function output()
16
    {
17
        return $this->outputLoader;
18
    }
19
20
    final protected function outputCli($string = '', $eol = true)
21
    {
22
        return $this->output()->cli($string, $eol);
23
    }
24
25
    protected function outputHtmlPartial($data, $template)
26
    {
27
        return new Response(
28
            $this->output()->html($data, $template),
29
            200,
30
            ['Content-Type' => 'text/html']
31
        );
32
    }
33
34
    protected function outputHtml($data, $pageTemplate, $mainTemplate = null)
35
    {
36
        return new Response(
37
            $this->output()->htmlPage($data, $pageTemplate, $mainTemplate),
38
            200,
39
            ['Content-Type' => 'text/html']
40
        );
41
    }
42
43
    protected function outputJson($content, $result = true)
44
    {
45
        $data = [
46
            'result' => $result,
47
            'data' => $content,
48
        ];
49
        return new Response(
50
            $this->output()->json($data),
51
            200,
52
            ['Content-Type' => 'application/json']
53
        );
54
    }
55
}
56