Fr3nch13/CakePHP Utilities

JsonType extends BaseType
in package
implements BatchCastingInterface

JSON type converter.

Use to convert JSON data between PHP and the database types.

Table of Contents

Interfaces

BatchCastingInterface
Denotes type objects capable of converting many values from their original database representation to php values.

Properties

$_encodingOptions  : int
$_name  : string|null
Identifier name for this type

Methods

__construct()  : mixed
Constructor
getBaseType()  : string|null
Returns the base type name that this class is inheriting.
getName()  : string|null
Returns type identifier name for this object.
manyToPHP()  : array<string, mixed>
Returns an array of the values converted to the PHP representation of this type.
marshal()  : mixed
Marshals request data into a JSON compatible structure.
newId()  : mixed
Generate a new primary key value for a given type.
setEncodingOptions()  : $this
Set json_encode options.
toDatabase()  : string|null
Convert a value data into a JSON string
toPHP()  : array<string|int, mixed>|string|null
Casts given value from a database type to a PHP equivalent.
toStatement()  : int
Get the correct PDO binding type for string data.

Properties

$_encodingOptions

protected int $_encodingOptions = 0

$_name

Identifier name for this type

protected string|null $_name

Methods

__construct()

Constructor

public __construct([string|null $name = null ]) : mixed
Parameters
$name : string|null = null

The name identifying this type

getBaseType()

Returns the base type name that this class is inheriting.

public getBaseType() : string|null
Tags
inheritDoc
Return values
string|null

The base type name that this class is inheriting.

getName()

Returns type identifier name for this object.

public getName() : string|null
Tags
inheritDoc
Return values
string|null

The type identifier name for this object.

manyToPHP()

Returns an array of the values converted to the PHP representation of this type.

public manyToPHP(array<string|int, mixed> $values, array<string|int, mixed> $fields, DriverInterface $driver) : array<string, mixed>
Parameters
$values : array<string|int, mixed>

The original array of values containing the fields to be casted

$fields : array<string|int, mixed>

The field keys to cast

$driver : DriverInterface

Object from which database preferences and configuration will be extracted.

Tags
inheritDoc
Return values
array<string, mixed>

marshal()

Marshals request data into a JSON compatible structure.

public marshal(mixed $value) : mixed
Parameters
$value : mixed

The value to convert.

Return values
mixed

Converted value.

newId()

Generate a new primary key value for a given type.

public newId() : mixed
Tags
inheritDoc
Return values
mixed

A new primary key value.

toDatabase()

Convert a value data into a JSON string

public toDatabase(mixed $value, DriverInterface $driver) : string|null
Parameters
$value : mixed

The value to convert.

$driver : DriverInterface

The driver instance to convert with.

Tags
throws
InvalidArgumentException
Return values
string|null

toPHP()

Casts given value from a database type to a PHP equivalent.

public toPHP(mixed $value, DriverInterface $driver) : array<string|int, mixed>|string|null
Parameters
$value : mixed

The value to convert.

$driver : DriverInterface

The driver instance to convert with.

Return values
array<string|int, mixed>|string|null

toStatement()

Get the correct PDO binding type for string data.

public toStatement(mixed $value, DriverInterface $driver) : int
Parameters
$value : mixed

The value being bound.

$driver : DriverInterface

The driver.

Return values
int

        
On this page

Search results