示例#1
0
 protected static function _gen_response($_array)
 {
     echo SurStudioPluginTranslatorRevolutionLiteFastJSON::encode($_array);
 }
示例#2
0
 /**
  * public method
  *
  *	SurStudioPluginTranslatorRevolutionLiteFastJSON::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
  *		SurStudioPluginTranslatorRevolutionLiteFastJSON::encode(array(1,"two")); // '[1,"two"]'
  *
  *		$obj = new MyClass();
  *		obj->param = "value";
  *		obj->param2 = "value2";
  *		SurStudioPluginTranslatorRevolutionLiteFastJSON::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 = SurStudioPluginTranslatorRevolutionLiteFastJSON::encode($value)) !== '') {
                             array_push($keys, $value);
                         }
                     }
                     $result = '[' . implode(',', $keys) . ']';
                 } else {
                     $result = SurStudioPluginTranslatorRevolutionLiteFastJSON::convert($decode);
                 }
             }
             break;
         case 'string':
             $replacement = SurStudioPluginTranslatorRevolutionLiteFastJSON::__getStaticReplacement();
             $result = '"' . str_replace($replacement['find'], $replacement['replace'], $decode) . '"';
             break;
         default:
             if (!is_callable($decode)) {
                 $result = SurStudioPluginTranslatorRevolutionLiteFastJSON::convert($decode);
             }
             break;
     }
     return $result;
 }