summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/TJavaScript.php
diff options
context:
space:
mode:
authorctrlaltca@gmail.com <>2012-03-19 11:19:44 +0000
committerctrlaltca@gmail.com <>2012-03-19 11:19:44 +0000
commit942bee46430fe06e17200a9f5a649768081d6eae (patch)
treeef90db9f203ead2695a8fda3c31c12a88e303e67 /framework/Web/Javascripts/TJavaScript.php
parentf99ef429874fc6ba4bc644ac8d2cf2a378f6f6f4 (diff)
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)
Diffstat (limited to 'framework/Web/Javascripts/TJavaScript.php')
-rw-r--r--framework/Web/Javascripts/TJavaScript.php96
1 files changed, 35 insertions, 61 deletions
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
@@ -24,11 +24,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
* @return string rendering result
@@ -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");
}
/**