PHP Class Tools\Model\Behavior\JsonableBehavior

This is a port of the Serializeable behavior by Matsimitsu (http://www.matsimitsu.nl) Modified by Mark Scherer (http://www.dereuromark.de) Supports different input/output formats: - "list" is useful as some kind of pseudo enums or simple lists - "params" is useful for multiple key/value pairs - can be used to create dynamic forms (and tables) Also automatically cleans lists and works with custom separators etc Tip: If you have other behaviors that might modify the array data prior to saving, better use a higher priority: $this->addBehavior('Tools.Jsonable', ['priority' => 11, ...]); So that it is run last. Usage: See docs
Author: PJ Hile (http://www.pjhile.com)
Author: Mark Scherer
Inheritance: extends Cake\ORM\Behavior
Exibir arquivo Open project: dereuromark/cakephp-tools

Public Properties

Property Type Description
$decoded string | false | null

Protected Properties

Property Type Description
$_defaultConfig array TODO: json input/ouput directly, clean

Public Methods

Method Description
_decode ( array | null $val ) : array | null | false Fields are absolutely necessary to function properly!
_encode ( array | string $val ) : string | null
_fromList ( string $val ) : array
_fromParam ( string $val ) : array
_toList ( array $val ) : string array() => value1|value2|value3|.
_toParam ( array $val ) : string array() => param1:value1|param2:value2|.
beforeFind ( Cake\Event\Event $event, Query $query ) : void Decode the fields on after find
beforeSave ( Cake\Event\Event $event, Cake\ORM\Entity $entity, ArrayObject $options ) : void Saves all fields that do not belong to the current Model into 'with' helper model.
decodeItems ( Cake\ORM\Entity $entity ) : void Decodes the fields of an array/entity (if the value itself was encoded)
initialize ( array $config = [] ) : void
isEncoded ( string $str ) : boolean Checks if string is encoded array/object

Protected Methods

Method Description
_getMappedFields ( ) : array

Method Details

_decode() public method

Fields are absolutely necessary to function properly!
public _decode ( array | null $val ) : array | null | false
$val array | null
return array | null | false

_encode() public method

public _encode ( array | string $val ) : string | null
$val array | string
return string | null

_fromList() public method

public _fromList ( string $val ) : array
$val string
return array

_fromParam() public method

public _fromParam ( string $val ) : array
$val string
return array

_getMappedFields() protected method

protected _getMappedFields ( ) : array
return array

_toList() public method

..
public _toList ( array $val ) : string
$val array
return string

_toParam() public method

..
public _toParam ( array $val ) : string
$val array
return string

beforeFind() public method

Decode the fields on after find
public beforeFind ( Cake\Event\Event $event, Query $query ) : void
$event Cake\Event\Event
$query Cake\ORM\Query
return void

beforeSave() public method

Saves all fields that do not belong to the current Model into 'with' helper model.
public beforeSave ( Cake\Event\Event $event, Cake\ORM\Entity $entity, ArrayObject $options ) : void
$event Cake\Event\Event
$entity Cake\ORM\Entity
$options ArrayObject
return void

decodeItems() public method

Decodes the fields of an array/entity (if the value itself was encoded)
public decodeItems ( Cake\ORM\Entity $entity ) : void
$entity Cake\ORM\Entity
return void

initialize() public method

public initialize ( array $config = [] ) : void
$config array
return void

isEncoded() public method

Checks if string is encoded array/object
public isEncoded ( string $str ) : boolean
$str string String to check
return boolean

Property Details

$_defaultConfig protected_oe property

TODO: json input/ouput directly, clean
protected array $_defaultConfig
return array

$decoded public_oe property

public string|false|null $decoded
return string | false | null