1 | <?php |
||
41 | class JsonBehavior extends Behavior |
||
42 | { |
||
43 | public $attributes = []; |
||
44 | |||
45 | /** |
||
46 | * @var boolean If enabled, the data will be encoded before validating, this means the validation rule should be `array` otherwise the validation must be `string`. |
||
47 | * This might also differ based on how the data is passed to the model. Data passed to the model will be encoded from string to array (if not already). |
||
48 | * @since 1.2.0 |
||
49 | */ |
||
50 | public $encodeBeforeValidate = true; |
||
51 | |||
52 | /** |
||
53 | * @var boolean If enabled the data will be encoded from json to array after populating the active record data. |
||
54 | * @since 1.2.0 |
||
55 | */ |
||
56 | public $decodeAfterFind = false; |
||
57 | |||
58 | /** |
||
59 | * @inheritdoc |
||
60 | */ |
||
61 | public function events() |
||
76 | |||
77 | /** |
||
78 | * Encode all attributes from json to php. |
||
79 | */ |
||
80 | public function encodeAttributes() |
||
91 | |||
92 | /** |
||
93 | * Decode all attributes from php to json. |
||
94 | */ |
||
95 | public function decodeAttributes() |
||
103 | /** |
||
104 | * Encodes the given value into a JSON string. |
||
105 | * |
||
106 | * @param mixed $value This is commonly an array. |
||
107 | * @return string |
||
108 | */ |
||
109 | public function jsonEncode($value) |
||
119 | |||
120 | /** |
||
121 | * Decodes the given JSON string into a PHP data structure. |
||
122 | * |
||
123 | * @param string $value |
||
124 | * @return array |
||
125 | */ |
||
126 | public function jsonDecode($value) |
||
135 | } |
||
136 |