From 942bee46430fe06e17200a9f5a649768081d6eae Mon Sep 17 00:00:00 2001 From: "ctrlaltca@gmail.com" <> Date: Mon, 19 Mar 2012 11:19:44 +0000 Subject: Droppped php 5.2 support, require 5.3.3 (rc1 was breaking php 5.2 support because of a broken change in TJavaScript::jsonEncode(), but nobody noticed in a month; previous php 5.3 version are broken) Droppped TJSON, not needed anymore Name this 3.2-rc2 (to distinguish problems from users caused by this change) --- framework/Web/Javascripts/TJavaScript.php | 96 +++++++++++-------------------- 1 file changed, 35 insertions(+), 61 deletions(-) (limited to 'framework/Web/Javascripts/TJavaScript.php') diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php index 6ef3b466..4f12eb94 100644 --- a/framework/Web/Javascripts/TJavaScript.php +++ b/framework/Web/Javascripts/TJavaScript.php @@ -23,11 +23,6 @@ */ class TJavaScript { - /** - * @var TJSON JSON decoder and encoder instance - */ - private static $_json; - /** * Renders a list of javascript files * @param array URLs to the javascript files @@ -200,82 +195,61 @@ class TJavaScript /** * Encodes a PHP variable into javascript string. - * This method invokes {@TJSON} utility class to perform the encoding. + * This method invokes json_encode to perform the encoding. * @param mixed variable to be encoded * @return string encoded string */ public static function jsonEncode($value, $options = 0) { - if (function_exists('json_encode')) - { - if (is_string($value) && - ($g=Prado::getApplication()->getGlobalization(false))!==null && - strtoupper($enc=$g->getCharset())!='UTF-8') - $value=iconv($enc, 'UTF-8', $value); - $s = json_encode($value,$options); - self::checkJsonError(); - return $s; - } - - if(self::$_json === null) - self::$_json = Prado::createComponent('System.Web.Javascripts.TJSON'); - return self::$_json->encode($value); + if (is_string($value) && + ($g=Prado::getApplication()->getGlobalization(false))!==null && + strtoupper($enc=$g->getCharset())!='UTF-8') + $value=iconv($enc, 'UTF-8', $value); + $s = json_encode($value,$options); + self::checkJsonError(); + return $s; } /** * Decodes a javascript string into PHP variable. - * This method invokes {@TJSON} utility class to perform the decoding. + * This method invokes json_decode to perform the decoding. * @param string string to be decoded * @return mixed decoded variable */ public static function jsonDecode($value) { - if (function_exists('json_decode')) - { - $s= json_decode($value); - self::checkJsonError(); - return $s; - } - if(self::$_json === null) - self::$_json = Prado::createComponent('System.Web.Javascripts.TJSON'); - return self::$_json->decode($value); + $s= json_decode($value); + self::checkJsonError(); + return $s; } private static function checkJsonError() { - // requires php 5.3.0 - if (function_exists('json_last_error')) + switch ($err = json_last_error()) { - // requires php 5.3.3 - if(!defined('JSON_ERROR_UTF8')) - define('JSON_ERROR_UTF8', null); - - switch ($err = json_last_error()) - { - case JSON_ERROR_NONE: - return; - break; - case JSON_ERROR_DEPTH: - $msg = 'Maximum stack depth exceeded'; - break; - case JSON_ERROR_STATE_MISMATCH: - $msg = 'Underflow or the modes mismatch'; - break; - case JSON_ERROR_CTRL_CHAR: - $msg = 'Unexpected control character found'; - break; - case JSON_ERROR_SYNTAX: - $msg = 'Syntax error, malformed JSON'; - break; - case JSON_ERROR_UTF8: - $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded'; - break; - default: - $msg = 'Unknown error'; - break; - } - throw new Exception("JSON error ($err): $msg"); + case JSON_ERROR_NONE: + return; + break; + case JSON_ERROR_DEPTH: + $msg = 'Maximum stack depth exceeded'; + break; + case JSON_ERROR_STATE_MISMATCH: + $msg = 'Underflow or the modes mismatch'; + break; + case JSON_ERROR_CTRL_CHAR: + $msg = 'Unexpected control character found'; + break; + case JSON_ERROR_SYNTAX: + $msg = 'Syntax error, malformed JSON'; + break; + case JSON_ERROR_UTF8: + $msg = 'Malformed UTF-8 characters, possibly incorrectly encoded'; + break; + default: + $msg = 'Unknown error'; + break; } + throw new Exception("JSON error ($err): $msg"); } /** -- cgit v1.2.3