   'phpDocumentor\Descriptor\FileDescriptor * hash 867166e7700f1aad0a2d945cfe674183 * pathRest/Serializer.php	 * source<?php
/**
 * Rest Serializer
 *
 * 暂未实现，后面如果在 Restful 返回值中需要有 _links 或在 header 中加入分页信息可用...
 *
 * @author camera360_server@camera360.com
 * @copyright Chengdu pinguo Technology Co.,Ltd.
 */

namespace PG\MSF\Rest;

/**
 * Class Serializer
 * @package PG\MSF\Rest
 */
class Serializer
{
    /**
     * @var 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.
     */
    public $fieldsParam = 'fields';
    /**
     * @var 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.
     */
    public $expandParam = 'expand';
    /**
     * @var 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.
     */
    public $totalCountHeader = 'X-Pagination-Total-Count';
    /**
     * @var 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.
     */
    public $pageCountHeader = 'X-Pagination-Page-Count';
    /**
     * @var 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.
     */
    public $currentPageHeader = 'X-Pagination-Current-Page';
    /**
     * @var 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.
     */
    public $perPageHeader = 'X-Pagination-Per-Page';
    /**
     * @var 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.
     */
    public $collectionEnvelope;
    /**
     * @var string the name of the envelope (e.g. `_links`) for returning the links objects.
     * It takes effect only, if `collectionEnvelope` is set.
     */
    public $linksEnvelope = '_links';
    /**
     * @var string the name of the envelope (e.g. `_meta`) for returning the pagination object.
     * It takes effect only, if `collectionEnvelope` is set.
     */
    public $metaEnvelope = '_meta';
    /**
     * @var bool 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 serializeDataProvider()
     * @since 2.0.10
     */
    public $preserveKeys = false;

    /**
     * Serializes the given data into a format that can be easily turned into other formats.
     * @param mixed $data the data to be serialized.
     * @return mixed the converted data.
     */
    public function serialize($data)
    {
        return $data;
    }

    /**
     * Requested fields
     *
     * @return 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 Model::fields()
     * @see Model::extraFields()
     */
    protected function getRequestedFields()
    {
        $fields = $this->request->get($this->fieldsParam);
        $expand = $this->request->get($this->expandParam);

        return [
            is_string($fields) ? preg_split('/\s*,\s*/', $fields, -1, PREG_SPLIT_NO_EMPTY) : [],
            is_string($expand) ? preg_split('/\s*,\s*/', $expand, -1, PREG_SPLIT_NO_EMPTY) : [],
        ];
    }

    /**
     * Serializes a pagination into an array.
     * @param Pagination $pagination
     * @return array the array representation of the pagination
     * @see addPaginationHeaders()
     */
    protected function serializePagination($pagination)
    {
        return [
            $this->linksEnvelope => Link::serialize($pagination->getLinks(true)),
            $this->metaEnvelope => [
                'totalCount' => $pagination->totalCount,
                'pageCount' => $pagination->getPageCount(),
                'currentPage' => $pagination->getPage() + 1,
                'perPage' => $pagination->getPageSize(),
            ],
        ];
    }

    /**
     * Adds HTTP headers about the pagination to the response.
     * @param Pagination $pagination
     */
    protected function addPaginationHeaders($pagination)
    {
        $links = [];
        foreach ($pagination->getLinks(true) as $rel => $url) {
            $links[] = "<$url>; rel=$rel";
        }

        $this->response->getHeaders()
            ->set($this->totalCountHeader, $pagination->totalCount)
            ->set($this->pageCountHeader, $pagination->getPageCount())
            ->set($this->currentPageHeader, $pagination->getPage() + 1)
            ->set($this->perPageHeader, $pagination->pageSize)
            ->set('Link', implode(', ', $links));
    }
}
 * namespaceAliases#phpDocumentor\Descriptor\Collection * items  * includes	  * constants	  * functions	 
 * classes	\PG\MSF\Rest\Serializer(phpDocumentor\Descriptor\ClassDescriptor	 * parent * implements	  * abstract * final	  * properties	
fieldsParam+phpDocumentor\Descriptor\PropertyDescriptor" * types 
 * default'fields'	 * static * visibilitypublic * fqsen$\PG\MSF\Rest\Serializer::fieldsParam * name * namespace 
 * package
 * summary * description * fileDescriptor  * line * tags	var	 *phpDocumentor\Descriptor\Tag\VarDescriptor * variableName	 .phpDocumentor\Descriptor\Type\StringDescriptor '#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.	 * errors	 ,	  * inheritedElement expandParam" 'expand'$\PG\MSF\Rest\Serializer::expandParam.  !"#$ %&	'	 ()	 * '#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.,	 ,	 - totalCountHeader" 'X-Pagination-Total-Count')\PG\MSF\Rest\Serializer::totalCountHeader2  !"#$ %"&	'	 ()	 * '#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.,	 ,	 - pageCountHeader" 'X-Pagination-Page-Count'(\PG\MSF\Rest\Serializer::pageCountHeader6  !"#$ %'&	'	 ()	 * '#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.,	 ,	 - currentPageHeader" 'X-Pagination-Current-Page'*\PG\MSF\Rest\Serializer::currentPageHeader:  !"#$ %,&	'	 ()	 * '#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.,	 ,	 - perPageHeader" 'X-Pagination-Per-Page'&\PG\MSF\Rest\Serializer::perPageHeader>  !"#$ %1&	'	 ()	 * '#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.,	 ,	 - collectionEnvelope"  +\PG\MSF\Rest\Serializer::collectionEnvelopeB  !"#$ %K&	'	 ()	 * '#wthe 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.,	 ,	 - linksEnvelope" '_links'&\PG\MSF\Rest\Serializer::linksEnvelopeE  !"#$ %P&	'	 ()	 * '#the name of the envelope (e.g. `_links`) for returning the links objects.
It takes effect only, if `collectionEnvelope` is set.,	 ,	 - metaEnvelope" '_meta'%\PG\MSF\Rest\Serializer::metaEnvelopeI  !"#$ %U&	'	 ()	 * '#the name of the envelope (e.g. `_meta`) for returning the pagination object.
It takes effect only, if `collectionEnvelope` is set.,	 ,	 - preserveKeys" false%\PG\MSF\Rest\Serializer::preserveKeysM  !"#$ %^&	'	 ()	 /phpDocumentor\Descriptor\Type\BooleanDescriptor '#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	 *phpDocumentor\Descriptor\Tag\SeeDescriptor * reference!@context::serializeDataProvider()R#,	 since	 ,phpDocumentor\Descriptor\Tag\SinceDescriptor
 * version2.0.10V#,	 ,	 - 
 * methods		serialize)phpDocumentor\Descriptor\MethodDescriptor" * arguments	$data+phpDocumentor\Descriptor\ArgumentDescriptor	 * method"	 3phpDocumentor\Descriptor\Type\UnknownTypeDescriptormixed  * byReference * isVariadic^  !"#the data to be serialized.$ % &	 ,	 - $\PG\MSF\Rest\Serializer::serialize()[  !"USerializes the given data into a format that can be easily turned into other formats.#$ %e&	param	 ,phpDocumentor\Descriptor\Tag\ParamDescriptor)^"h#e,	 return	 -phpDocumentor\Descriptor\Tag\ReturnDescriptor	 abj#the converted data.,	 ,	 - getRequestedFields\"	protected]	 -\PG\MSF\Rest\Serializer::getRequestedFields()m  !"Requested fields#$ %s&	j	 k	 aarrayj#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.,	 R	 ST\PG\MSF\Rest\Model::fields()R#,	 ST!\PG\MSF\Rest\Model::extraFields()R#,	 h	 ,	 - serializePagination\"n]	$pagination_`"	 a\PG\MSF\Rest\Pagination cdv  !"#$ % &	 ,	 - .\PG\MSF\Rest\Serializer::serializePagination()u  !"&Serializes a pagination into an array.#$ %&	h	 i)v"h#,	 j	 k	 aqj#*the array representation of the pagination,	 R	 ST @context::addPaginationHeaders()R#,	 ,	 - addPaginationHeaders\"n]	v_`"	 aw cdv  !"#$ % &	 ,	 - /\PG\MSF\Rest\Serializer::addPaginationHeaders()|  !"7Adds HTTP headers about the pagination to the response.#$ %&	h	 i)v"h#,	 j	 ,	 -  * usedTraits	 
Serializer \PG\MSF\Rest!PG\MSF\Rest"Class Serializer#$" %&	package	 &phpDocumentor\Descriptor\TagDescriptor#,	 
subpackage	 ,	 -  * interfaces	 	 * traits	 
 * markers	 Serializer.php  !Default"Rest Serializer#p暂未实现，后面如果在 Restful 返回值中需要有 _links 或在 header 中加入分页信息可用...$ % &	author	 -phpDocumentor\Descriptor\Tag\AuthorDescriptor#camera360_server@camera360.com,	 	copyright	 #"Chengdu pinguo Technology Co.,Ltd.,	 	 #,	 	 ,	 - 