Documentation

Codec extends Decoder, Encoder

The Codec interface allows decoding BSON data to native PHP types and back to BSON.

Tags
psalm-template

BSONType

psalm-template

NativeType

template-extends
template-extends

Table of Contents

Methods

canDecode()  : bool
Checks if the decoder supports a given value.
canEncode()  : bool
Checks if the encoder supports a given value.
decode()  : mixed
Decodes a given value. If the decoder does not support the value, it should throw an exception.
decodeIfSupported()  : mixed
Decodes a given value if supported, otherwise returns the value as-is.
encode()  : mixed
Encodes a given value. If the encoder does not support the value, it should throw an exception.
encodeIfSupported()  : mixed
Encodes a given value if supported, otherwise returns the value as-is.

Methods

canDecode()

Checks if the decoder supports a given value.

public canDecode(mixed $value) : bool
Parameters
$value : mixed
Tags
psalm-assert-if-true

BSONType $value

Return values
bool

canEncode()

Checks if the encoder supports a given value.

public canEncode(mixed $value) : bool
Parameters
$value : mixed
Tags
psalm-assert-if-true

NativeType $value

Return values
bool

decode()

Decodes a given value. If the decoder does not support the value, it should throw an exception.

public decode(mixed $value) : mixed
Parameters
$value : mixed
Tags
psalm-param

BSONType $value

psalm-return

NativeType

throws
UnsupportedValueException

if the decoder does not support the value

decodeIfSupported()

Decodes a given value if supported, otherwise returns the value as-is.

public decodeIfSupported(mixed $value) : mixed

The DecodeIfSupported trait provides a default implementation of this method.

Parameters
$value : mixed
Tags
psalm-return

($value is BSONType ? NativeType : $value)

encode()

Encodes a given value. If the encoder does not support the value, it should throw an exception.

public encode(mixed $value) : mixed
Parameters
$value : mixed
Tags
psalm-param

NativeType $value

psalm-return

BSONType

throws
UnsupportedValueException

if the encoder does not support the value

encodeIfSupported()

Encodes a given value if supported, otherwise returns the value as-is.

public encodeIfSupported(mixed $value) : mixed

The EncodeIfSupported trait provides a default implementation of this method.

Parameters
$value : mixed
Tags
psalm-return

($value is NativeType ? BSONType : $value)


        
On this page

Search results