Passed
Push — master ( fdb4cc...c92fa1 )
by Radu
03:29
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
trait OutputTrait
5
{
6
    protected $outputLoader;
7
    
8
    final protected function setOutputLoader(\WebServCo\Framework\AbstractOutputLoader $outputLoader)
9
    {
10
        $this->outputLoader = $outputLoader;
11
    }
12
    
13
    final protected function output()
14
    {
15
        return $this->outputLoader;
16
    }
17
    
18
    final protected function outputCli($string, $eol = true)
19
    {
20
        return $this->output()->cli($string, $eol);
21
    }
22
    
23
    protected function outputHtml($data, $pageTemplate, $mainTemplate = null)
24
    {
25
        return new \WebServCo\Framework\Libraries\HttpResponse(
26
            $this->output()->htmlPage($data, $pageTemplate, $mainTemplate),
27
            200,
28
            ['Content-Type' => 'text/html']
29
        );
30
    }
31
    
32
    protected function outputJson($content, $result = true)
33
    {
34
        $data = [
35
            'result' => $result,
36
            'data' => $content,
37
        ];
38
        return new \WebServCo\Framework\Libraries\HttpResponse(
39
            $this->output()->json($data),
40
            200,
41
            ['Content-Type' => 'application/json']
42
        );
43
    }
44
}
45