class FormEncodedDataFormatter extends XMLDataFormatter (View source)

Accepts form encoded strings and converts them to a valid PHP array via parse_str().

Example when using cURL on commandline:

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

Format response form encoded as well - currently uses XMLDataFormatter

Traits

Provides extensions to this object to integrate it with standard config API methods.

Config options

priority int

Set priority from 0-100.

from  DataFormatter
api_base from  XMLDataFormatter

Properties

public int $relationDepth

Follow relations for the DataObject instances ($has_one, $has_many, $many_many).

from  DataFormatter
protected array $customFields

Allows overriding of the fields which are rendered for the processed dataobjects. By default, this includes all fields in DataObject::inheritedDatabaseFields().

from  DataFormatter
protected array $customAddFields

Allows addition of fields (e.g. custom getters on a DataObject)

from  DataFormatter
protected array $customRelations

Allows to limit or add relations.

from  DataFormatter
protected array $removeFields

Fields which should be expicitly excluded from the export.

from  DataFormatter
protected $outputContentType from  XMLDataFormatter
protected int $totalSize

Used to set totalSize properties on the output of convertDataObjectSet(), shows the total number of records without the "limit" and "offset" GET parameters. Useful to implement pagination.

from  DataFormatter

Methods

public static 
config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

public
mixed
stat(string $name) deprecated

Get inherited config value

public
mixed
uninherited(string $name)

Gets the uninherited value for the given config option

public
$this
set_stat(string $name, mixed $value) deprecated

Update the config value for a given property

protected
string
sanitiseClassName($className)

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 static 
for_extension(string $extension)

Get a DataFormatter object suitable for handling the given file extension.

public static 
for_extensions(array $extensions)

Get formatter for the first matching extension.

public static 
for_mimetype(string $mimeType)

Get a DataFormatter object suitable for handling the given mimetype.

public static 
for_mimetypes(array $mimetypes)

Get formatter for the first matching mimetype.

public
$this
setCustomFields(array $fields)

No description

public
array
getCustomFields()

No description

public
$this
setCustomAddFields(array $fields)

No description

public
$this
setCustomRelations(array $relations)

No description

public
array
getCustomRelations()

No description

public
array
getCustomAddFields()

No description

public
$this
setRemoveFields(array $fields)

No description

public
array
getRemoveFields()

No description

public
string
getOutputContentType()

No description

public
$this
setTotalSize(int $size)

No description

public
int
getTotalSize()

No description

protected
array
getFieldsForObj(DataObject $obj)

Returns all fields on the object which should be shown in the output. Can be customised through self::setCustomFields().

public
supportedExtensions()

No description

public
supportedMimeTypes()

No description

public
mixed
convertDataObject(DataObjectInterface $obj, $fields = null)

Generate an XML representation of the given DataObject.

public
string
convertDataObjectSet(SS_List $set, $fields = null)

Generate an XML representation of the given SS_List.

public
string
convertArray($array)

No description

public
convertStringToArray(string $strData)

No description

public
string[]
getRealFields(string $className, string[] $fields)

Convert an array of aliased field names to their Dataobject field name

public
string
getRealFieldName(string $className, string $field)

Get the DataObject field name from its alias

public
string
getFieldAlias(string $className, string $field)

Get a DataObject Field's Alias defaults to the fieldname

protected
string[]|array
getApiMapping(string $className)

Get the 'api_field_mapping' config value for a class or return an empty array

protected
string
getMappedKey(array $map, string $key)

Helper function to get mapped field names

public
string
convertArrayWithoutHeader($array)

No description

public
string
convertDataObjectWithoutHeader(DataObject $obj, null $fields = null, null $relations = null)

No description

Details

static Config_ForClass config()

Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).

Return Value

Config_ForClass

mixed stat(string $name) deprecated

deprecated 5.0 Use ->config()->get() instead

Get inherited config value

Parameters

string $name

Return Value

mixed

mixed uninherited(string $name)

Gets the uninherited value for the given config option

Parameters

string $name

Return Value

mixed

$this set_stat(string $name, mixed $value) deprecated

deprecated 5.0 Use ->config()->set() instead

Update the config value for a given property

Parameters

string $name
mixed $value

Return Value

$this

protected string sanitiseClassName($className)

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)

Parameters

$className

Return Value

string

'escaped' class name

static DataFormatter for_extension(string $extension)

Get a DataFormatter object suitable for handling the given file extension.

Parameters

string $extension

Return Value

DataFormatter

static DataFormatter for_extensions(array $extensions)

Get formatter for the first matching extension.

Parameters

array $extensions

Return Value

DataFormatter

static DataFormatter for_mimetype(string $mimeType)

Get a DataFormatter object suitable for handling the given mimetype.

Parameters

string $mimeType

Return Value

DataFormatter

static DataFormatter for_mimetypes(array $mimetypes)

Get formatter for the first matching mimetype.

Useful for HTTP Accept headers which can contain multiple comma-separated mimetypes.

Parameters

array $mimetypes

Return Value

DataFormatter

$this setCustomFields(array $fields)

No description

Parameters

array $fields

Return Value

$this

array getCustomFields()

No description

Return Value

array

$this setCustomAddFields(array $fields)

No description

Parameters

array $fields

Return Value

$this

$this setCustomRelations(array $relations)

No description

Parameters

array $relations

Return Value

$this

array getCustomRelations()

No description

Return Value

array

array getCustomAddFields()

No description

Return Value

array

$this setRemoveFields(array $fields)

No description

Parameters

array $fields

Return Value

$this

array getRemoveFields()

No description

Return Value

array

string getOutputContentType()

No description

Return Value

string

$this setTotalSize(int $size)

No description

Parameters

int $size

Return Value

$this

int getTotalSize()

No description

Return Value

int

protected array getFieldsForObj(DataObject $obj)

Returns all fields on the object which should be shown in the output. Can be customised through self::setCustomFields().

Allow for custom getters on the processed object (currently filtered through inheritedDatabaseFields) Field level permission checks

Parameters

DataObject $obj

Return Value

array

supportedExtensions()

No description

supportedMimeTypes()

No description

mixed convertDataObject(DataObjectInterface $obj, $fields = null)

Generate an XML representation of the given DataObject.

Parameters

DataObjectInterface $obj
$fields

Return Value

mixed

string convertDataObjectSet(SS_List $set, $fields = null)

Generate an XML representation of the given SS_List.

Parameters

SS_List $set
$fields

Return Value

string

string convertArray($array)

No description

Parameters

$array

Return Value

string

Exceptions

Exception

convertStringToArray(string $strData)

No description

Parameters

string $strData

HTTP Payload as string

Exceptions

Exception

string[] getRealFields(string $className, string[] $fields)

Convert an array of aliased field names to their Dataobject field name

Parameters

string $className
string[] $fields

Return Value

string[]

string getRealFieldName(string $className, string $field)

Get the DataObject field name from its alias

Parameters

string $className
string $field

Return Value

string

string getFieldAlias(string $className, string $field)

Get a DataObject Field's Alias defaults to the fieldname

Parameters

string $className
string $field

Return Value

string

protected string[]|array getApiMapping(string $className)

Get the 'api_field_mapping' config value for a class or return an empty array

Parameters

string $className

Return Value

string[]|array

protected string getMappedKey(array $map, string $key)

Helper function to get mapped field names

Parameters

array $map
string $key

Return Value

string

string convertArrayWithoutHeader($array)

No description

Parameters

$array

Return Value

string

Exceptions

Exception

string convertDataObjectWithoutHeader(DataObject $obj, null $fields = null, null $relations = null)

No description

Parameters

DataObject $obj
null $fields
null $relations

Return Value

string