public function _prepare_option_value($_id, $_value) { $value = $_value; if (PrisnaGWTValidator::isBool($value)) { $value = $value == 'true' || $value === true; } if ($_id == 'layout') { $value = array('type' => 'literal', 'value' => $value); } return PrisnaGWTFastJSON::encode($value); }
/** * public method * * PrisnaGWTFastJSON::encode(params:*):String * * @param * Array, Boolean, Float, Int, Object, String or NULL variable. * @return String JSON genric object rappresentation * or empty string if param is not compatible. * * @example * PrisnaGWTFastJSON::encode(array(1,"two")); // '[1,"two"]' * * $obj = new MyClass(); * obj->param = "value"; * obj->param2 = "value2"; * PrisnaGWTFastJSON::encode(obj); // '{"param":"value","param2":"value2"}' */ public static function encode($decode) { $result = ''; switch (gettype($decode)) { case 'array': if (count(array_keys($decode)) == 2 && array_key_exists('value', $decode) && array_key_exists('type', $decode) && $decode['type'] == 'literal') { $result = $decode['value']; } else { if (!count($decode) || array_keys($decode) === range(0, count($decode) - 1)) { $keys = array(); foreach ($decode as $value) { if (($value = PrisnaGWTFastJSON::encode($value)) !== '') { array_push($keys, $value); } } $result = '[' . implode(',', $keys) . ']'; } else { $result = PrisnaGWTFastJSON::convert($decode); } } break; case 'string': $replacement = PrisnaGWTFastJSON::__getStaticReplacement(); $result = '"' . str_replace($replacement['find'], $replacement['replace'], $decode) . '"'; break; default: if (!is_callable($decode)) { $result = PrisnaGWTFastJSON::convert($decode); } break; } return $result; }