Neomerx\JsonApi\Document\Presenters\ElementPresenter::convertResourceToArray PHP Method

convertResourceToArray() private method

Convert resource object to array.
private convertResourceToArray ( Neomerx\JsonApi\Contracts\Schema\ResourceObjectInterface $resource, array $resourceLinks, mixed $meta, boolean $isShowAttributes ) : array
$resource Neomerx\JsonApi\Contracts\Schema\ResourceObjectInterface
$resourceLinks array
$meta mixed
$isShowAttributes boolean
return array
    private function convertResourceToArray(ResourceObjectInterface $resource, $resourceLinks, $meta, $isShowAttributes)
    {
        $representation = [Document::KEYWORD_TYPE => $resource->getType(), Document::KEYWORD_ID => $resource->getId()];
        $attributes = $resource->getAttributes();
        // "type" and "id" are reserved keywords and cannot be used as resource object attributes
        $isOk = isset($attributes[Document::KEYWORD_TYPE]) === false;
        if ($isOk === false) {
            throw new InvalidArgumentException(T::t('\'%s\' is a reserved keyword and cannot be used as attribute name in type \'%s\'', [Document::KEYWORD_TYPE, $resource->getType()]));
        }
        $isOk = isset($attributes[Document::KEYWORD_ID]) === false;
        if ($isOk === false) {
            throw new InvalidArgumentException(T::t('\'%s\' is a reserved keyword and cannot be used as attribute name in type \'%s\'', [Document::KEYWORD_ID, $resource->getType()]));
        }
        if ($isShowAttributes === true && empty($attributes) === false) {
            $representation[Document::KEYWORD_ATTRIBUTES] = $attributes;
        }
        // reserve placeholder for relationships, otherwise it would be added after
        // links and meta which is not visually beautiful
        $representation[Document::KEYWORD_RELATIONSHIPS] = null;
        if (empty($resourceLinks) === false) {
            foreach ($resourceLinks as $linkName => $link) {
                /** @var LinkInterface $link */
                $representation[Document::KEYWORD_LINKS][$linkName] = $this->getLinkRepresentation($this->document->getUrlPrefix(), $link);
            }
        }
        if ($meta !== null) {
            $representation[Document::KEYWORD_META] = $meta;
        }
        return $representation;
    }