code/view/json.php
protected function _createResource(ModelEntityInterface $entity, array $config = array())
    {
        $config = array_merge(array(
            'links'         => true,
            'relationships' => true
        ), $config);

        $data = array(
            'type' => $this->_callCustomMethod($entity, 'type') ?: StringInflector::pluralize($entity->getIdentifier()->name),
            'id'   => $this->_callCustomMethod($entity, 'id') ?: $entity->{$entity->getIdentityKey()},
            'attributes' => $this->_callCustomMethod($entity, 'attributes') ?: $entity->toArray()
        );

        if (isset($this->_fields[$data['type']]))
        {
            $fields = array_flip($this->_fields[$data['type']]);
            $data['attributes'] = array_intersect_key($data['attributes'], $fields);
        }

        if ($config['links'])
        {
            $links = $this->_callCustomMethod($entity, 'links') ?: array('self' => (string)$this->_getEntityRoute($entity));
            if ($links) {
                $data['links'] = $links;
            }
        }

        if ($config['relationships'])
        {
            $relationships = $this->_callCustomMethod($entity, 'relationships');
            if ($relationships) {
                $data['relationships'] = $relationships;
            }
        }

        return $data;
    }
protected function _createResource(ModelEntityInterface $entity, array $config = array())
    {
        $config = array_merge(array(
            'links'         => true,
            'relationships' => true
        ), $config);

        $data = array(
            'type' => $this->_callCustomMethod($entity, 'type') ?: StringInflector::pluralize($entity->getIdentifier()->name),
            'id'   => $this->_callCustomMethod($entity, 'id') ?: $entity->{$entity->getIdentityKey()},
            'attributes' => $this->_callCustomMethod($entity, 'attributes') ?: $entity->toArray()
        );

        if (isset($this->_fields[$data['type']]))
        {
            $fields = array_flip($this->_fields[$data['type']]);
            $data['attributes'] = array_intersect_key($data['attributes'], $fields);
        }

        if ($config['links'])
        {
            $links = $this->_callCustomMethod($entity, 'links') ?: array('self' => (string)$this->_getEntityRoute($entity));
            if ($links) {
                $data['links'] = $links;
            }
        }

        if ($config['relationships'])
        {
            $relationships = $this->_callCustomMethod($entity, 'relationships');
            if ($relationships) {
                $data['relationships'] = $relationships;
            }
        }

        return $data;
    }
protected function _createResource ( ModelEntityInterface $ entity , array $ config = array ( ) ) { $ config = array_merge ( array ( 'links' => true , 'relationships' => true ) , $ config ) ; $ data = array ( 'type' => $ this -> _callCustomMethod ( $ entity , 'type' ) ? : StringInflector :: pluralize ( $ entity -> getIdentifier ( ) -> name ) , 'id' => $ this -> _callCustomMethod ( $ entity , 'id' ) ? : $ entity -> { $ entity -> getIdentityKey ( ) } , 'attributes' => $ this -> _callCustomMethod ( $ entity , 'attributes' ) ? : $ entity -> toArray ( ) ) ; if ( isset ( $ this -> _fields [ $ data [ 'type' ] ] ) ) { $ fields = array_flip ( $ this -> _fields [ $ data [ 'type' ] ] ) ; $ data [ 'attributes' ] = array_intersect_key ( $ data [ 'attributes' ] , $ fields ) ; } if ( $ config [ 'links' ] ) { $ links = $ this -> _callCustomMethod ( $ entity , 'links' ) ? : array ( 'self' => ( string ) $ this -> _getEntityRoute ( $ entity ) ) ; if ( $ links ) { $ data [ 'links' ] = $ links ; } } if ( $ config [ 'relationships' ] ) { $ relationships = $ this -> _callCustomMethod ( $ entity , 'relationships' ) ; if ( $ relationships ) { $ data [ 'relationships' ] = $ relationships ; } } return $ data ; }
Creates a resource object specified by JSON API

@see   http://jsonapi.org/format/#document-resource-objects

@param ModelEntityInterface  $entity   Document row
@param array $config Resource configuration.
@return array The array with data to be encoded to json
Creates a resource object specified by JSON API