Completed
Branch master (73f336)
by John
01:59
created

URLEncodedQueryStringRequestData::getRawData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace LunixREST\Request\RequestData;
3
4
class URLEncodedQueryStringRequestData implements RequestData {
5
6
    protected $queryString;
7
8
    protected $parsedData = [];
9
10
    public function __construct($queryString) {
11
        $this->queryString = $queryString;
12
        parse_str($queryString, $this->parsedData);
13
    }
14
15
    /**
16
     * Returns the raw data that the requestData tried to parse
17
     * @return string
18
     */
19
    public function getRawData(): string {
20
        return $this->queryString;
21
    }
22
23
    /**
24
     * Attempts to get a specific key from the parsed data. Returns NULL if non-existant key (use has($key) if
25
     * there is a difference between a null value and a missing value)
26
     * WARNING: Parsed data is not sanitized, and should be treated as regular user data
27
     * @param string $key
28
     * @return mixed
29
     */
30
    public function get(string $key) {
31
        return $this->parsedData[$key] ?? null;
32
    }
33
34
    /**
35
     * Attempts to find a specific key in the parsed data. Returns true if found else false
36
     * @param string $key
37
     * @return mixed
38
     */
39
    public function has(string $key): bool {
40
        return isset($this->parsedData[$key]);
41
    }
42
43
    /**
44
     * Gets all parsed data as an associative array
45
     * WARNING: Parsed data is not sanitized, and should be treated as regular user data
46
     * @return array
47
     */
48
    public function getAllAsAssociativeArray(): array {
49
        return $this->parsedData;
50
    }
51
}
52