PHP Class RESTfulAPI_BasicSerializer

. JSON serialization and de-serialization
Author: Thierry Francois @colymba [email protected]
Inheritance: implements RESTfulAPI_Serializer
Show file Open project: colymba/silverstripe-restfulapi Class Usage Examples

Protected Properties

Property Type Description
$embeddedRecords array Stores the current $embedded_records @config Config set on {@link RESTfulAPI}

Public Methods

Method Description
__construct ( ) Construct and set current config
formatName ( string $name ) : string Format a SilverStripe ClassName or Field name to be used by the client API
getcontentType ( ) : string Return Content-type header definition to be used in the API response
serialize ( mixed $data ) : string Convert raw data (DataObject or DataList) to JSON ready to be consumed by the client API

Protected Methods

Method Description
formatDataList ( DataList $dataList ) : array Format a DataList into a formatted array ready to be turned into JSON
formatDataObject ( DataObject $dataObject ) : array | null Format a DataObject keys and values ready to be turned into JSON
getEmbedData ( DataObject $record, string $relationName ) : array | null Returns a DataObject relation's data formatted and ready to embed.
isEmbeddable ( string $model, string $relation ) : boolean Checks if a speicific model's relation should have its records embedded.
jsonify ( mixed $data ) : string Convert data into a JSON string
serializeColumnName ( string $name ) : string Format a DB Column name or Field name to be used by the client API

Method Details

__construct() public method

Construct and set current config
public __construct ( )

formatDataList() protected method

Format a DataList into a formatted array ready to be turned into JSON
protected formatDataList ( DataList $dataList ) : array
$dataList DataList The DataList to format
return array The formatted array representation of the DataList

formatDataObject() protected method

Format a DataObject keys and values ready to be turned into JSON
protected formatDataObject ( DataObject $dataObject ) : array | null
$dataObject DataObject The data object to format
return array | null The formatted array map representation of the DataObject or null is permission denied

formatName() public method

Format a SilverStripe ClassName or Field name to be used by the client API
public formatName ( string $name ) : string
$name string ClassName of DBField name
return string Formatted name

getEmbedData() protected method

Returns a DataObject relation's data formatted and ready to embed.
protected getEmbedData ( DataObject $record, string $relationName ) : array | null
$record DataObject The DataObject to get the data from
$relationName string The name of the relation
return array | null Formatted DataObject or RelationList ready to embed or null if nothing to embed

getcontentType() public method

Return Content-type header definition to be used in the API response
public getcontentType ( ) : string
return string Content-type

isEmbeddable() protected method

Checks if a speicific model's relation should have its records embedded.
protected isEmbeddable ( string $model, string $relation ) : boolean
$model string Model's classname
$relation string Relation name
return boolean Trus if the relation should be embedded

jsonify() protected method

Convert data into a JSON string
protected jsonify ( mixed $data ) : string
$data mixed Data to convert
return string JSON data

serialize() public method

Convert raw data (DataObject or DataList) to JSON ready to be consumed by the client API
public serialize ( mixed $data ) : string
$data mixed Data to serialize
return string JSON representation of data

serializeColumnName() protected method

Format a DB Column name or Field name to be used by the client API
protected serializeColumnName ( string $name ) : string
$name string Field name
return string Formatted name

Property Details

$embeddedRecords protected property

Stores the current $embedded_records @config Config set on {@link RESTfulAPI}
protected array $embeddedRecords
return array