PHP Interface Neomerx\JsonApi\Contracts\Encoder\EncoderInterface

显示文件 Open project: neomerx/json-api Interface Usage Examples

Public Methods

Method Description
encodeData ( object | array | Iterato\Iterator | null $data, Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface $parameters = null ) : string Encode input as JSON API string.
encodeError ( Neomerx\JsonApi\Contracts\Document\ErrorInterface $error ) : string Encode error as JSON API string.
encodeErrors ( Neomerx\JsonApi\Contracts\Document\ErrorInterface[] | ErrorCollection $errors ) : string Encode errors as JSON API string.
encodeIdentifiers ( object | array | Iterato\Iterator | null $data, Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface $parameters = null ) : string Encode input as JSON API string with a list of resource identifiers.
encodeMeta ( array | object $meta ) : string Encode input meta as JSON API string.
withJsonApiVersion ( mixed | null $meta = null ) : Neomerx\JsonApi\Contracts\Encoder\EncoderInterface If called JSON API version information with optional meta will be added to a document.
withLinks ( array $links ) : Neomerx\JsonApi\Contracts\Encoder\EncoderInterface Add links that will be encoded with data. Links must be in array format.
withMeta ( mixed | null $meta ) : Neomerx\JsonApi\Contracts\Encoder\EncoderInterface Add meta information that will be encoded with data. If 'null' meta will not appear in a document.
withRelationshipRelatedLink ( object $resource, string $relationshipName, null | mixed $meta = null, boolean $treatAsHref = false ) : Neomerx\JsonApi\Contracts\Encoder\EncoderInterface Add 'related' Link to top-level document's 'links' section for relationship specified.
withRelationshipSelfLink ( object $resource, string $relationshipName, null | mixed $meta = null, boolean $treatAsHref = false ) : Neomerx\JsonApi\Contracts\Encoder\EncoderInterface Add 'self' Link to top-level document's 'links' section for relationship specified.

Method Details

encodeData() public method

Encode input as JSON API string.
public encodeData ( object | array | Iterato\Iterator | null $data, Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface $parameters = null ) : string
$data object | array | Iterato\Iterator | null Data to encode.
$parameters Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface Encoding parameters.
return string

encodeError() public method

Encode error as JSON API string.
public encodeError ( Neomerx\JsonApi\Contracts\Document\ErrorInterface $error ) : string
$error Neomerx\JsonApi\Contracts\Document\ErrorInterface
return string

encodeErrors() public method

Encode errors as JSON API string.
public encodeErrors ( Neomerx\JsonApi\Contracts\Document\ErrorInterface[] | ErrorCollection $errors ) : string
$errors Neomerx\JsonApi\Contracts\Document\ErrorInterface[] | Neomerx\JsonApi\Exceptions\ErrorCollection
return string

encodeIdentifiers() public method

Encode input as JSON API string with a list of resource identifiers.
public encodeIdentifiers ( object | array | Iterato\Iterator | null $data, Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface $parameters = null ) : string
$data object | array | Iterato\Iterator | null Data to encode.
$parameters Neomerx\JsonApi\Contracts\Encoder\Parameters\EncodingParametersInterface Encoding parameters.
return string

encodeMeta() public method

Encode input meta as JSON API string.
public encodeMeta ( array | object $meta ) : string
$meta array | object Meta information.
return string

withJsonApiVersion() public method

If called JSON API version information with optional meta will be added to a document.
See also: http://jsonapi.org/format/#document-jsonapi-object
public withJsonApiVersion ( mixed | null $meta = null ) : Neomerx\JsonApi\Contracts\Encoder\EncoderInterface
$meta mixed | null
return Neomerx\JsonApi\Contracts\Encoder\EncoderInterface

withMeta() public method

Add meta information that will be encoded with data. If 'null' meta will not appear in a document.
public withMeta ( mixed | null $meta ) : Neomerx\JsonApi\Contracts\Encoder\EncoderInterface
$meta mixed | null
return Neomerx\JsonApi\Contracts\Encoder\EncoderInterface