silverstripe-framework/api/FormEncodedDataFormatter.php

41 lines
1004 B
PHP
Raw Permalink Normal View History

<?php
/**
* Accepts form encoded strings and converts them
* to a valid PHP array via {@link parse_str()}.
*
* Example when using cURL on commandline:
* <code>
* curl -d "Name=This is a new record" http://host/api/v1/(DataObject)
* curl -X PUT -d "Name=This is an updated record" http://host/api/v1/(DataObject)/1
* </code>
2014-08-15 08:53:05 +02:00
*
* @todo Format response form encoded as well - currently uses XMLDataFormatter
2014-08-15 08:53:05 +02:00
*
* @author Cam Spiers <camspiers at gmail dot com>
2014-08-15 08:53:05 +02:00
*
* @package framework
* @subpackage formatters
*/
class FormEncodedDataFormatter extends XMLDataFormatter {
2014-08-15 08:53:05 +02:00
public function supportedExtensions() {
return array(
);
}
public function supportedMimeTypes() {
return array(
'application/x-www-form-urlencoded'
);
}
2014-08-15 08:53:05 +02:00
public function convertStringToArray($strData) {
$postArray = array();
parse_str($strData, $postArray);
return $postArray;
//TODO: It would be nice to implement this function in Convert.php
//return Convert::querystr2array($strData);
}
2014-08-15 08:53:05 +02:00
}