Browse Source

Renamed JsonExpression to JsExpression.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
53a7b82672
  1. 4
      framework/helpers/JsExpression.php
  2. 6
      framework/helpers/base/Json.php
  3. 8
      tests/unit/framework/helpers/JsonTest.php

4
framework/helpers/JsonExpression.php → 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 <qiang.xue@gmail.com>
* @since 2.0
*/
class JsonExpression extends Object
class JsExpression extends Object
{
/**
* @var string the JavaScript expression represented by this object

6
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;

8
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));
}

Loading…
Cancel
Save