Passed
Pull Request — master (#255)
by Christopher
03:45
created

IncomingChangeSetRequest::getContentId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
4
namespace POData\BatchProcessor;
5
6
7
use POData\OperationContext\HTTPRequestMethod;
8
use POData\OperationContext\Web\IncomingRequest;
9
10
class IncomingChangeSetRequest extends IncomingRequest
11
{
12
13
    protected $contentID = null;
14
15
    public function __construct(string $requestChunk)
16
    {
17
        list($RequestParams, $requestHeaders, $RequestBody) = explode("\n\n", $requestChunk);
18
19
        $headerLine = strtok($requestHeaders, "\n");
20
        $RequestBody                                        = trim($RequestBody);
21
        list($RequesetType, $RequestPath, $RequestProticol) = explode(' ', $headerLine, 3);
22
        $inboundRequestHeaders                              = [];
23
        $headerLine = strtok("\n");
24
25
        while ($headerLine !== false) {
26
            list($key, $value)            = explode(':', $headerLine);
27
            $name                         = strtr(strtoupper(trim($key)), '-', '_');
28
            $value                        = trim($value);
29
            $name                         = substr($name, 0, 5) === 'HTTP_' || $name == 'CONTENT_TYPE' ? $name : 'HTTP_' . $name;
30
            if('HTTP_CONTENT_ID' === $name){
31
                $this->contentID = $value;
32
            }else {
33
                $inboundRequestHeaders[$name] = $value;
34
            }
35
            $headerLine = strtok("\n");
36
        }
37
        $host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? $_SERVER['SERVER_ADDR'] ?? 'localhost';
38
        $protocol=$_SERVER['PROTOCOL'] = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
39
40
        parent::__construct(
41
            new HTTPRequestMethod($RequesetType),
42
            [],
43
            [],
44
            $inboundRequestHeaders,
45
            null,
46
            $RequestBody,
47
            $protocol . '://' . $host . $RequestPath);
48
    }
49
50
    public function getContentId(): ?string {
51
        return $this->contentID;
52
    }
53
54
}