diff --git a/framework/helpers/JsonExpression.php b/framework/helpers/JsExpression.php similarity index 91% rename from framework/helpers/JsonExpression.php rename to framework/helpers/JsExpression.php index eee57a1..0054b64 100644 --- a/framework/helpers/JsonExpression.php +++ b/framework/helpers/JsExpression.php @@ -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 * @since 2.0 */ -class JsonExpression extends Object +class JsExpression extends Object { /** * @var string the JavaScript expression represented by this object diff --git a/framework/helpers/base/Json.php b/framework/helpers/base/Json.php index d39b2b3..1deb5c2 100644 --- a/framework/helpers/base/Json.php +++ b/framework/helpers/base/Json.php @@ -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; diff --git a/tests/unit/framework/helpers/JsonTest.php b/tests/unit/framework/helpers/JsonTest.php index 3459a54..0e06eb3 100644 --- a/tests/unit/framework/helpers/JsonTest.php +++ b/tests/unit/framework/helpers/JsonTest.php @@ -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)); }