FormEncodedDataFormatter::convertStringToArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace SilverStripe\RestfulServer\DataFormatter;
4
5
/**
6
 * Accepts form encoded strings and converts them
7
 * to a valid PHP array via {@link parse_str()}.
8
 *
9
 * Example when using cURL on commandline:
10
 * <code>
11
 * curl -d "Name=This is a new record" http://host/api/v1/(DataObject)
12
 * curl -X PUT -d "Name=This is an updated record" http://host/api/v1/(DataObject)/1
13
 * </code>
14
 *
15
 * @todo Format response form encoded as well - currently uses XMLDataFormatter
16
 *
17
 * @author Cam Spiers <camspiers at gmail dot com>
18
 */
19
class FormEncodedDataFormatter extends XMLDataFormatter
20
{
21
22
    public function supportedExtensions()
23
    {
24
        return array(
25
        );
26
    }
27
28
    public function supportedMimeTypes()
29
    {
30
        return array(
31
            'application/x-www-form-urlencoded'
32
        );
33
    }
34
35
    public function convertStringToArray($strData)
36
    {
37
        $postArray = array();
38
        parse_str($strData, $postArray);
39
        return $postArray;
40
        //TODO: It would be nice to implement this function in Convert.php
41
        //return Convert::querystr2array($strData);
42
    }
43
}
44