Completed
Push — master ( 6f2bb4...6400d0 )
by Anton
11s
created

ResponseTrait::__toString()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
1
<?php
2
/**
3
 * Bluz Framework Component
4
 *
5
 * @copyright Bluz PHP Team
6
 * @link      https://github.com/bluzphp/framework
7
 */
8
9
declare(strict_types=1);
10
11
namespace Bluz\Response;
12
13
/**
14
 * Response Trait
15
 *
16
 * @package  Bluz\Response
17
 * @author   Anton Shevchuk
18
 */
19
trait ResponseTrait
20
{
21
    /**
22
     * @return string
23
     */
24
    abstract public function jsonSerialize();
25
26
    /**
27
     * @return string
28
     */
29
    abstract public function __toString();
30
31
    /**
32
     * Render object as HTML or JSON
33
     *
34
     * @param  string $type
35
     *
36
     * @return string
37
     */
38 3
    public function render($type = 'HTML') : string
39
    {
40
        // switch statement by response type
41 3
        switch (strtoupper($type)) {
42
            case 'CLI':
43
            case 'JSON':
44
                return $this->jsonSerialize();
45
            case 'HTML':
46
            default:
47 3
                return $this->__toString();
48
        }
49
    }
50
}
51