PHP Class RESTfulAPI_EmberDataSerializer

. JSON serialization and de-serialization
Author: Thierry Francois @colymba [email protected]
Inheritance: extends RESTfulAPI_BasicSerializer
显示文件 Open project: colymba/silverstripe-restfulapi

Protected Properties

Property Type Description
$sideloadedRecords array Stores the current $sideloaded_records config

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
serialize ( DataObject | DataList $data ) : string Convert raw data (DataObject or DataList) to JSON ready to be consumed by the client API

Protected Methods

Method Description
getSideloadData ( DataObject | DataList $dataSource ) : array Fetches and return all the data that need to be sideloaded for a specific source DataObject or DataList.
hasSideloadedRecords ( string $classname ) : boolean Check if a specific class requires data to be sideloaded.
insertSideloadData ( stdClass $root, DataObject | DataList $dataSource ) : stdClass Take a root object ready to be converted into JSON and an original data source (DataObject OR DataList) and insorts into the root object all relation records that should be sideloaded.
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 ( )

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

getSideloadData() protected method

Fetches and return all the data that need to be sideloaded for a specific source DataObject or DataList.
protected getSideloadData ( DataObject | DataList $dataSource ) : array
$dataSource DataObject | DataList The source data to fetch sideloaded records for
return array A map of relation names with their data

hasSideloadedRecords() protected method

Check if a specific class requires data to be sideloaded.
protected hasSideloadedRecords ( string $classname ) : boolean
$classname string Requested data classname
return boolean True if some relations should be sideloaded

insertSideloadData() protected method

Take a root object ready to be converted into JSON and an original data source (DataObject OR DataList) and insorts into the root object all relation records that should be sideloaded.
protected insertSideloadData ( stdClass $root, DataObject | DataList $dataSource ) : stdClass
$root stdClass Root object ready to become JSON
$dataSource DataObject | DataList The original data set from the root object
return stdClass The updated root object sith the sideloaded data attached

serialize() public method

Convert raw data (DataObject or DataList) to JSON ready to be consumed by the client API
public serialize ( DataObject | DataList $data ) : string
$data DataObject | DataList 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

$sideloadedRecords protected_oe property

Stores the current $sideloaded_records config
protected array $sideloadedRecords
return array