# \PG\MSF\RestSerializer

Class Serializer

## Summary

Methods
Properties
Constants
serialize()
$fieldsParam
$expandParam
$totalCountHeader
$pageCountHeader
$currentPageHeader
$perPageHeader
$collectionEnvelope
$linksEnvelope
$metaEnvelope
$preserveKeys
No constants found
getRequestedFields()
serializePagination()
addPaginationHeaders()
No protected properties found
N/A
No private methods found
No private properties found
N/A

File
  Rest/Serializer.php
Package
  MSF\Rest
Class hierarchy
  \PG\MSF\Rest\Serializer

## Tags

None found

## Properties

### $fieldsParam

    $fieldsParam : string

#### Type

string — the name of the query parameter containing the information about which fields should be returned for a [[Model]] object. If the parameter is not provided or empty, the default set of fields as defined by [[Model::fields()]] will be returned.

#

## Tags

None found

### $expandParam

    $expandParam : string

#### Type

string — the name of the query parameter containing the information about which fields should be returned in addition to those listed in [[fieldsParam]] for a resource object.

#

## Tags

None found

### $totalCountHeader

    $totalCountHeader : string

#### Type

string — the name of the HTTP header containing the information about total number of data items. This is used when serving a resource collection with pagination.

#

## Tags

None found

### $pageCountHeader

    $pageCountHeader : string

#### Type

string — the name of the HTTP header containing the information about total number of pages of data. This is used when serving a resource collection with pagination.

#

## Tags

None found

### $currentPageHeader

    $currentPageHeader : string

#### Type

string — the name of the HTTP header containing the information about the current page number (1-based). This is used when serving a resource collection with pagination.

#

## Tags

None found

### $perPageHeader

    $perPageHeader : string

#### Type

string — the name of the HTTP header containing the information about the number of data items in each page. This is used when serving a resource collection with pagination.

#

## Tags

None found

### $collectionEnvelope

    $collectionEnvelope : string

#### Type

string — the name of the envelope (e.g. `items`) for returning the resource objects in a collection. This is used when serving a resource collection. When this is set and pagination is enabled, the serializer will return a collection in the following format: ```php [ 'items' => [...], // assuming collectionEnvelope is "items" '_links' => { // pagination links as returned by Pagination::getLinks() 'self' => '...', 'next' => '...', 'last' => '...', }, '_meta' => { // meta information as returned by Pagination::toArray() 'totalCount' => 100, 'pageCount' => 5, 'currentPage' => 1, 'perPage' => 20, }, ] ``` If this property is not set, the resource arrays will be directly returned without using envelope. The pagination information as shown in `_links` and `_meta` can be accessed from the response HTTP headers.

#

## Tags

None found

### $linksEnvelope

    $linksEnvelope : string

#### Type

string — the name of the envelope (e.g. `_links`) for returning the links objects. It takes effect only, if `collectionEnvelope` is set.

#

## Tags

None found

### $metaEnvelope

    $metaEnvelope : string

#### Type

string — the name of the envelope (e.g. `_meta`) for returning the pagination object. It takes effect only, if `collectionEnvelope` is set.

#

## Tags

None found

### $preserveKeys

    $preserveKeys : boolean

#### Type

boolean — whether to preserve array keys when serializing collection data. Set this to `true` to allow serialization of a collection as a JSON object where array keys are used to index the model objects. The default is to serialize all collections as array, regardless of how the array is indexed.

#

See also
  \PG\MSF\Rest\serializeDataProvider()

## Tags

since |

## Methods

### serialize()

    serialize(mixed  $data) : mixed

Serializes the given data into a format that can be easily turned into other formats.

#### Parameters

mixed | $data | the data to be serialized.

#### Returns

mixed —

the converted data.

#

## Tags

None found

### getRequestedFields()

    getRequestedFields() : array

Requested fields

#### Returns

array —

the names of the requested fields. The first element is an array representing the list of default fields requested, while the second element is an array of the extra fields requested in addition to the default fields.

#

See also
  \PG\MSF\Rest\Model::fields()
  \PG\MSF\Rest\Model::extraFields()

## Tags

None found

### serializePagination()

    serializePagination(\PG\MSF\Rest\Pagination  $pagination) : array

Serializes a pagination into an array.

#### Parameters

\PG\MSF\Rest\Pagination | $pagination |

#### Returns

array —

the array representation of the pagination

#

See also
  \PG\MSF\Rest\Serializer::addPaginationHeaders()

## Tags

None found

### addPaginationHeaders()

    addPaginationHeaders(\PG\MSF\Rest\Pagination  $pagination)

Adds HTTP headers about the pagination to the response.

#### Parameters

\PG\MSF\Rest\Pagination | $pagination |

#

## Tags

None found

### Serializer.php