Completed
Push — master ( 8b5726...2416e6 )
by Tomas
06:18
created

XmlApiResponse::send()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Tomaj\NetteApi\Response;
4
5
use Nette\Application\IResponse as ApplicationIResponse;
6
use Nette\Http\IRequest;
7
use Nette\Http\IResponse;
8
9
class XmlApiResponse implements ApplicationIResponse
10
{
11
    /**
12
     * @var integer
13
     */
14
    private $code;
15
16
    /**
17
     * @var string
18
     */
19
    private $response = null;
20
21
    /**
22
     * Create XmlApiResponse
23
     * This class only wrap JsonResponse from Nette and add possibility
24
     * to setup response code and automaticaly set content type
25
     *
26
     * @param integer $code
27
     * @param string $data
28
     */
29 3
    public function __construct($code, $data)
30
    {
31 3
        $this->code = $code;
32 3
        $this->response = $data;
33 3
    }
34
35
    /**
36
     * Return api response http code
37
     *
38
     * @return integer
39
     */
40 3
    public function getCode()
41
    {
42 3
        return $this->code;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 3
    public function send(IRequest $httpRequest, IResponse $httpResponse)
49
    {
50 3
        $httpResponse->setContentType('text/xml');
51 3
        $httpResponse->setExpiration(false);
52 3
        $httpResponse->setCode($this->getCode());
53
54 3
        echo $this->response;
55 3
    }
56
}
57