Passed
Push — master ( fdb4cc...c92fa1 )
by Radu
03:29
created

OutputTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A outputCli() 0 3 1
A setOutputLoader() 0 3 1
A output() 0 3 1
A outputHtml() 0 6 1
A outputJson() 0 10 1
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