abstract class DataFormatter (View source)

A DataFormatter object handles transformation of data from SilverStripe model objects to a particular output format, and vice versa. This is most commonly used in developing RESTful APIs.

Traits

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

Properties

int $relationDepth

Follow relations for the {@link DataObject} instances ($has_one, $has_many, $many_many).

Methods

static Config_ForClass
config()

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

mixed
stat(string $name) deprecated

Get inherited config value

mixed
uninherited(string $name)

Gets the uninherited value for the given config option

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

Update the config value for a given property

static DataFormatter
for_extension(string $extension)

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

static DataFormatter
for_extensions(array $extensions)

Get formatter for the first matching extension.

static DataFormatter
for_mimetype(string $mimeType)

Get a DataFormatter object suitable for handling the given mimetype.

static DataFormatter
for_mimetypes(array $mimetypes)

Get formatter for the first matching mimetype.

$this
setCustomFields(array $fields)

No description

array
getCustomFields()

No description

$this
setCustomAddFields(array $fields)

No description

$this
setCustomRelations(array $relations)

No description

array
getCustomRelations()

No description

array
getCustomAddFields()

No description

$this
setRemoveFields(array $fields)

No description

array
getRemoveFields()

No description

string
getOutputContentType()

No description

$this
setTotalSize(int $size)

No description

int
getTotalSize()

No description

supportedExtensions()

Return an array of the extensions that this data formatter supports

supportedMimeTypes()

No description

mixed
convertDataObject(DataObjectInterface $do)

Convert a single data object to this format. Return a string.

string
convertDataObjectSet(SS_List $set)

Convert a data object set to this format. Return a string.

string
convertArray($array)

Convert an array to this format. Return a string.

convertStringToArray(string $strData)

No description

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

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

string
getRealFieldName(string $className, string $field)

Get the DataObject field name from its alias

string
getFieldAlias(string $className, string $field)

Get a DataObject Field's Alias defaults to the fieldname

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

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)

Parameters

array $fields

Return Value

$this

array getCustomFields()

Return Value

array

$this setCustomAddFields(array $fields)

Parameters

array $fields

Return Value

$this

$this setCustomRelations(array $relations)

Parameters

array $relations

Return Value

$this

array getCustomRelations()

Return Value

array

array getCustomAddFields()

Return Value

array

$this setRemoveFields(array $fields)

Parameters

array $fields

Return Value

$this

array getRemoveFields()

Return Value

array

string getOutputContentType()

Return Value

string

$this setTotalSize(int $size)

Parameters

int $size

Return Value

$this

int getTotalSize()

Return Value

int

abstract supportedExtensions()

Return an array of the extensions that this data formatter supports

abstract supportedMimeTypes()

abstract mixed convertDataObject(DataObjectInterface $do)

Convert a single data object to this format. Return a string.

Parameters

DataObjectInterface $do

Return Value

mixed

abstract string convertDataObjectSet(SS_List $set)

Convert a data object set to this format. Return a string.

Parameters

SS_List $set

Return Value

string

abstract string convertArray($array)

Convert an array to this format. Return a string.

Parameters

$array

Return Value

string

convertStringToArray(string $strData)

Parameters

string $strData

HTTP Payload as string

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