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() |
||
98 | |||
99 | /** |
||
100 | * Decode all attributes from php to json. |
||
101 | */ |
||
102 | public function decodeAttributes() |
||
110 | /** |
||
111 | * Encodes the given value into a JSON string. |
||
112 | * |
||
113 | * @param mixed $value This is commonly an array. |
||
114 | * @return string |
||
115 | */ |
||
116 | public function jsonEncode($value) |
||
120 | |||
121 | /** |
||
122 | * Decodes the given JSON string into a PHP data structure. |
||
123 | * |
||
124 | * @param string $value |
||
125 | * @return array |
||
126 | */ |
||
127 | public function jsonDecode($value) |
||
136 | } |
||
137 |