KMP PHP API Reference

JsonableBehavior extends Behavior
in package

A behavior that will json_encode (and json_decode) fields if they contain an array or specific pattern.

Tags
author

Mark Scherer

license

MIT

Table of Contents

Properties

$_defaultConfig  : array<string, mixed>

Methods

_decode()  : string|null
Fields are absolutely necessary to function properly!
_encode()  : string|null
beforeFind()  : void
Decode the fields on after find
beforeSave()  : void
Saves all fields that do not belong to the current Model into 'with' helper model.
decodeItems()  : void
Decodes the fields of an array/entity (if the value itself was encoded)
initialize()  : void
_fromJson()  : array<string|int, mixed>
_getMappedFields()  : array<string|int, mixed>

Properties

$_defaultConfig

protected array<string, mixed> $_defaultConfig = [ 'fields' => [], // Fields to convert 'input' => 'array', // json, array, param, list (param/list only works with specific fields) 'output' => 'array', // json, array, param, list (param/list only works with specific fields) 'separator' => '|', // only for param or list 'keyValueSeparator' => ':', // only for param 'leftBound' => '{', // only for list 'rightBound' => '}', // only for list 'map' => [], // map on a different DB field 'encodeParams' => [ // params for json_encode 'options' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR, 'depth' => 512, ], 'decodeParams' => [ // params for json_decode 'assoc' => true, // useful when working with multidimensional arrays 'depth' => 512, 'options' => JSON_THROW_ON_ERROR, ], ]

Methods

_decode()

Fields are absolutely necessary to function properly!

public _decode(array<string|int, mixed>|null $val) : string|null
Parameters
$val : array<string|int, mixed>|null
Return values
string|null

_encode()

public _encode(array<string|int, mixed>|string $val) : string|null
Parameters
$val : array<string|int, mixed>|string
Return values
string|null

beforeFind()

Decode the fields on after find

public beforeFind(EventInterface $event, SelectQuery $query, ArrayObject $options, bool $primary) : void
Parameters
$event : EventInterface
$query : SelectQuery
$options : ArrayObject
$primary : bool

beforeSave()

Saves all fields that do not belong to the current Model into 'with' helper model.

public beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options) : void
Parameters
$event : EventInterface
$entity : EntityInterface
$options : ArrayObject

decodeItems()

Decodes the fields of an array/entity (if the value itself was encoded)

public decodeItems(EntityInterface $entity) : void
Parameters
$entity : EntityInterface

initialize()

public initialize(array<string|int, mixed> $config) : void
Parameters
$config : array<string|int, mixed>
Tags
throws
RuntimeException

_fromJson()

protected _fromJson(string $val) : array<string|int, mixed>
Parameters
$val : string
Return values
array<string|int, mixed>

_getMappedFields()

protected _getMappedFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results