Passed
Push — master ( 65060b...2b54a2 )
by Julito
10:15
created

ImsLtiServiceResponse::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 21
rs 9.7998
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class ImsLtiServiceResponse.
6
 */
7
abstract class ImsLtiServiceResponse
8
{
9
    const TYPE_REPLACE = 'replace';
10
    const TYPE_READ = 'read';
11
    const TYPE_DELETE = 'delete';
12
13
    /**
14
     * @var mixed
15
     */
16
    protected $bodyParams;
17
    /**
18
     * @var ImsLtiServiceResponseStatus
19
     */
20
    private $statusInfo;
21
22
    /**
23
     * ImsLtiServiceResponse constructor.
24
     *
25
     * @param ImsLtiServiceResponseStatus $statusInfo
26
     * @param mixed|null                  $bodyParam
27
     */
28
    public function __construct(ImsLtiServiceResponseStatus $statusInfo, $bodyParam = null)
29
    {
30
        $this->statusInfo = $statusInfo;
31
        $this->bodyParams = $bodyParam;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function __toString()
38
    {
39
        $xml = new SimpleXMLElement('<imsx_POXEnvelopeResponse></imsx_POXEnvelopeResponse>');
40
        $xml->addAttribute('xmlns', 'http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0');
41
42
        $headerInfo = $xml->addChild('imsx_POXHeader')->addChild('imsx_POXResponseHeaderInfo');
43
        $headerInfo->addChild('imsx_version', 'V1.0');
44
        $headerInfo->addChild('imsx_messageIdentifier', time());
45
46
        $statusInfo = $headerInfo->addChild('imsx_statusInfo');
47
        $statusInfo->addChild('imsx_codeMajor', $this->statusInfo->getCodeMajor());
48
        $statusInfo->addChild('imsx_severity', $this->statusInfo->getSeverity());
49
        $statusInfo->addChild('imsx_description', $this->statusInfo->getDescription());
50
        $statusInfo->addChild('imsx_messageRefIdentifier', $this->statusInfo->getMessageRefIdentifier());
51
        $statusInfo->addChild('imsx_operationRefIdentifier', $this->statusInfo->getOperationRefIdentifier());
52
53
        $body = $xml->addChild('imsx_POXBody');
54
55
        $this->generateBody($body);
56
57
        return $xml->asXML();
58
    }
59
60
    /**
61
     * @param SimpleXMLElement $xmlBody
62
     */
63
    abstract protected function generateBody(SimpleXMLElement $xmlBody);
64
}
65