SilverStripe\RestfulServer\DataFormatter\FormEncodedDataFormatter
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>
- Author: Cam Spiers <camspiers at gmail dot com>
Synopsis
class FormEncodedDataFormatter
extends XMLDataFormatter
{
- // Inherited members from XMLDataFormatter
- protected string $outputContentType;
- // Inherited members from DataFormatter
- public integer $relationDepth;
- protected $customFields;
- protected $customAddFields;
- protected $customRelations;
- protected $removeFields;
- protected $outputContentType;
- protected $totalSize;
- // methods
- public void supportedExtensions()
- public void supportedMimeTypes()
- public void convertStringToArray()
- // Inherited methods from XMLDataFormatter
- public array supportedExtensions()
- public array supportedMimeTypes()
- public string convertArray()
- public string convertArrayWithoutHeader()
- public String convertDataObject()
- public string convertDataObjectWithoutHeader()
- public String convertDataObjectSet()
- public array|void convertStringToArray()
- // Inherited methods from DataFormatter
- protected string sanitiseClassName()
- public static DataFormatter for_extension()
- public static DataFormatter for_extensions()
- public static DataFormatter for_mimetype()
- public static DataFormatter for_mimetypes()
- public $this setCustomFields()
- public array getCustomFields()
- public $this setCustomAddFields()
- public $this setCustomRelations()
- public array getCustomRelations()
- public array getCustomAddFields()
- public $this setRemoveFields()
- public array getRemoveFields()
- public string getOutputContentType()
- public $this setTotalSize()
- public int getTotalSize()
- protected array getFieldsForObj()
- public abstract void supportedExtensions()
- public abstract void supportedMimeTypes()
- public abstract mixed convertDataObject()
- public abstract string convertDataObjectSet()
- public abstract string convertArray()
- public void convertStringToArray()
- public array getRealFields()
- public string getRealFieldName()
- public string getFieldAlias()
- protected array getApiMapping()
- protected string getMappedKey()
Hierarchy
Tasks
Line | Task |
---|---|
19+ | Format response form encoded as well - currently uses XMLDataFormatter |
40 | It would be nice to implement this function in Convert.php |
+ | Support more than one nesting level |
299+ | Allow for custom getters on the processed object (currently filtered through inheritedDatabaseFields) |
299+ | Field level permission checks |
Members
protected
- $customAddFields
—
array
Allows addition of fields (e.g. custom getters on a DataObject) - $customFields
—
array
Allows overriding of the fields which are rendered for the processed dataobjects. By default, this includes all fields in {@link DataObject::inheritedDatabaseFields()}. - $customRelations
—
array
Allows to limit or add relations. - $outputContentType
- $outputContentType
—
string
Specifies the mimetype in which all strings returned from the convert*() methods should be used, e.g. "text/xml". - $removeFields
—
array
Fields which should be expicitly excluded from the export. - $totalSize
—
int
Used to set totalSize properties on the output of {@link convertDataObjectSet()}, shows the total number of records without the "limit" and "offset" GET parameters. Useful to implement pagination.
public
- $relationDepth
—
int
Follow relations for the {@link DataObject} instances ($has_one, $has_many, $many_many).
Methods
public
Inherited from SilverStripe\RestfulServer\DataFormatter\XMLDataFormatter
public
- convertArray()
- convertArrayWithoutHeader()
- convertDataObject() — Generate an XML representation of the given {@link DataObject}.
- convertDataObjectSet() — Generate an XML representation of the given {@link SS_List}.
- convertDataObjectWithoutHeader()
- convertStringToArray()
- supportedExtensions()
- supportedMimeTypes()
Inherited from SilverStripe\RestfulServer\DataFormatter
protected
- getApiMapping() — Get the 'api_field_mapping' config value for a class or return an empty array
- getFieldsForObj() — Returns all fields on the object which should be shown in the output. Can be customised through {@link self::setCustomFields()}.
- getMappedKey() — Helper function to get mapped field names
- sanitiseClassName() — Backslashes in fully qualified class names (e.g. NameSpaced\ClassName) kills both requests (i.e. URIs) and XML (invalid character in a tag name) So we'll replace them with a hyphen (-), as it's also unambiguious in both cases (invalid in a php class name, and safe in an xml tag name)
public
- convertArray() — Convert an array to this format. Return a string.
- convertDataObject() — Convert a single data object to this format. Return a string.
- convertDataObjectSet() — Convert a data object set to this format. Return a string.
- convertStringToArray()
- for_extension() — Get a DataFormatter object suitable for handling the given file extension.
- for_extensions() — Get formatter for the first matching extension.
- for_mimetype() — Get a DataFormatter object suitable for handling the given mimetype.
- for_mimetypes() — Get formatter for the first matching mimetype.
- getCustomAddFields()
- getCustomFields()
- getCustomRelations()
- getFieldAlias() — Get a DataObject Field's Alias defaults to the fieldname
- getOutputContentType()
- getRealFieldName() — Get the DataObject field name from its alias
- getRealFields() — Convert an array of aliased field names to their Dataobject field name
- getRemoveFields()
- getTotalSize()
- setCustomAddFields()
- setCustomFields()
- setCustomRelations()
- setRemoveFields()
- setTotalSize()
- supportedExtensions() — Return an array of the extensions that this data formatter supports
- supportedMimeTypes()