From 53a7b826720f921ab836cc2a5b94b56ac25ffd7d Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 1 May 2013 14:46:24 -0400 Subject: [PATCH] Renamed JsonExpression to JsExpression. --- framework/helpers/JsExpression.php | 45 +++++++++++++++++++++++++++++++ framework/helpers/JsonExpression.php | 45 ------------------------------- framework/helpers/base/Json.php | 6 ++--- tests/unit/framework/helpers/JsonTest.php | 8 +++--- 4 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 framework/helpers/JsExpression.php delete mode 100644 framework/helpers/JsonExpression.php diff --git a/framework/helpers/JsExpression.php b/framework/helpers/JsExpression.php new file mode 100644 index 0000000..0054b64 --- /dev/null +++ b/framework/helpers/JsExpression.php @@ -0,0 +1,45 @@ + + * @since 2.0 + */ +class JsExpression extends Object +{ + /** + * @var string the JavaScript expression represented by this object + */ + public $expression; + + /** + * Constructor. + * @param string $expression the JavaScript expression represented by this object + * @param array $config additional configurations for this object + */ + public function __construct($expression, $config = array()) + { + $this->expression = $expression; + parent::__construct($config); + } + + /** + * The PHP magic function converting an object into a string. + * @return string the JavaScript expression. + */ + public function __toString() + { + return $this->expression; + } +} \ No newline at end of file diff --git a/framework/helpers/JsonExpression.php b/framework/helpers/JsonExpression.php deleted file mode 100644 index eee57a1..0000000 --- a/framework/helpers/JsonExpression.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @since 2.0 - */ -class JsonExpression extends Object -{ - /** - * @var string the JavaScript expression represented by this object - */ - public $expression; - - /** - * Constructor. - * @param string $expression the JavaScript expression represented by this object - * @param array $config additional configurations for this object - */ - public function __construct($expression, $config = array()) - { - $this->expression = $expression; - parent::__construct($config); - } - - /** - * The PHP magic function converting an object into a string. - * @return string the JavaScript expression. - */ - public function __toString() - { - return $this->expression; - } -} \ No newline at end of file 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)); }