Commit 53a7b826 by Qiang Xue

Renamed JsonExpression to JsExpression.

parent 3bed48ec
......@@ -10,13 +10,13 @@ namespace yii\helpers;
use yii\base\Object;
/**
* JsonExpression marks a string as a JavaScript expression.
* JsExpression marks a string as a JavaScript expression.
* When using [[Json::encode()]] to encode a value, JsonExpression objects
* will be specially handled and encoded as a JavaScript expression instead of a string.
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class JsonExpression extends Object
class JsExpression extends Object
{
/**
* @var string the JavaScript expression represented by this object
......
......@@ -8,7 +8,7 @@
namespace yii\helpers\base;
use yii\base\InvalidParamException;
use yii\helpers\JsonExpression;
use yii\helpers\JsExpression;
/**
* Json is a helper class providing JSON data encoding and decoding.
......@@ -23,7 +23,7 @@ class Json
* Encodes the given value into a JSON string.
* The method enhances `json_encode()` by supporting JavaScript expressions.
* In particular, the method will not encode a JavaScript expression that is
* represented in terms of a [[JsonExpression]] object.
* represented in terms of a [[JsExpression]] object.
* @param mixed $value the data to be encoded
* @param integer $options the encoding options. For more details please refer to
* [[http://www.php.net/manual/en/function.json-encode.php]]
......@@ -86,7 +86,7 @@ class Json
}
return $data;
} elseif (is_object($data)) {
if ($data instanceof JsonExpression) {
if ($data instanceof JsExpression) {
$token = '!{[' . count($expressions) . ']}!';
$expressions['"' . $token . '"'] = $data->expression;
return $token;
......
......@@ -4,7 +4,7 @@
namespace yiiunit\framework\helpers;
use yii\helpers\Json;
use yii\helpers\JsonExpression;
use yii\helpers\JsExpression;
class JsonTest extends \yii\test\TestCase
{
......@@ -27,7 +27,7 @@ class JsonTest extends \yii\test\TestCase
// expression encoding
$expression = 'function () {}';
$data = new JsonExpression($expression);
$data = new JsExpression($expression);
$this->assertSame($expression, Json::encode($data));
// complex data
......@@ -35,9 +35,9 @@ class JsonTest extends \yii\test\TestCase
$expression2 = 'function (b) {}';
$data = array(
'a' => array(
1, new JsonExpression($expression1)
1, new JsExpression($expression1)
),
'b' => new JsonExpression($expression2),
'b' => new JsExpression($expression2),
);
$this->assertSame("{\"a\":[1,$expression1],\"b\":$expression2}", Json::encode($data));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment