Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
53a7b826
Commit
53a7b826
authored
May 01, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed JsonExpression to JsExpression.
parent
3bed48ec
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
9 deletions
+9
-9
JsExpression.php
framework/helpers/JsExpression.php
+2
-2
Json.php
framework/helpers/base/Json.php
+3
-3
JsonTest.php
tests/unit/framework/helpers/JsonTest.php
+4
-4
No files found.
framework/helpers/Js
on
Expression.php
→
framework/helpers/JsExpression.php
View file @
53a7b826
...
@@ -10,13 +10,13 @@ namespace yii\helpers;
...
@@ -10,13 +10,13 @@ namespace yii\helpers;
use
yii\base\Object
;
use
yii\base\Object
;
/**
/**
* Js
on
Expression 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
* When using [[Json::encode()]] to encode a value, JsonExpression objects
* will be specially handled and encoded as a JavaScript expression instead of a string.
* will be specially handled and encoded as a JavaScript expression instead of a string.
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
Js
on
Expression
extends
Object
class
JsExpression
extends
Object
{
{
/**
/**
* @var string the JavaScript expression represented by this object
* @var string the JavaScript expression represented by this object
...
...
framework/helpers/base/Json.php
View file @
53a7b826
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
namespace
yii\helpers\base
;
namespace
yii\helpers\base
;
use
yii\base\InvalidParamException
;
use
yii\base\InvalidParamException
;
use
yii\helpers\Js
on
Expression
;
use
yii\helpers\JsExpression
;
/**
/**
* Json is a helper class providing JSON data encoding and decoding.
* Json is a helper class providing JSON data encoding and decoding.
...
@@ -23,7 +23,7 @@ class Json
...
@@ -23,7 +23,7 @@ class Json
* Encodes the given value into a JSON string.
* Encodes the given value into a JSON string.
* The method enhances `json_encode()` by supporting JavaScript expressions.
* The method enhances `json_encode()` by supporting JavaScript expressions.
* In particular, the method will not encode a JavaScript expression that is
* In particular, the method will not encode a JavaScript expression that is
* represented in terms of a [[Js
on
Expression]] object.
* represented in terms of a [[JsExpression]] object.
* @param mixed $value the data to be encoded
* @param mixed $value the data to be encoded
* @param integer $options the encoding options. For more details please refer to
* @param integer $options the encoding options. For more details please refer to
* [[http://www.php.net/manual/en/function.json-encode.php]]
* [[http://www.php.net/manual/en/function.json-encode.php]]
...
@@ -86,7 +86,7 @@ class Json
...
@@ -86,7 +86,7 @@ class Json
}
}
return
$data
;
return
$data
;
}
elseif
(
is_object
(
$data
))
{
}
elseif
(
is_object
(
$data
))
{
if
(
$data
instanceof
Js
on
Expression
)
{
if
(
$data
instanceof
JsExpression
)
{
$token
=
'!{['
.
count
(
$expressions
)
.
']}!'
;
$token
=
'!{['
.
count
(
$expressions
)
.
']}!'
;
$expressions
[
'"'
.
$token
.
'"'
]
=
$data
->
expression
;
$expressions
[
'"'
.
$token
.
'"'
]
=
$data
->
expression
;
return
$token
;
return
$token
;
...
...
tests/unit/framework/helpers/JsonTest.php
View file @
53a7b826
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
namespace
yiiunit\framework\helpers
;
namespace
yiiunit\framework\helpers
;
use
yii\helpers\Json
;
use
yii\helpers\Json
;
use
yii\helpers\Js
on
Expression
;
use
yii\helpers\JsExpression
;
class
JsonTest
extends
\yii\test\TestCase
class
JsonTest
extends
\yii\test\TestCase
{
{
...
@@ -27,7 +27,7 @@ class JsonTest extends \yii\test\TestCase
...
@@ -27,7 +27,7 @@ class JsonTest extends \yii\test\TestCase
// expression encoding
// expression encoding
$expression
=
'function () {}'
;
$expression
=
'function () {}'
;
$data
=
new
Js
on
Expression
(
$expression
);
$data
=
new
JsExpression
(
$expression
);
$this
->
assertSame
(
$expression
,
Json
::
encode
(
$data
));
$this
->
assertSame
(
$expression
,
Json
::
encode
(
$data
));
// complex data
// complex data
...
@@ -35,9 +35,9 @@ class JsonTest extends \yii\test\TestCase
...
@@ -35,9 +35,9 @@ class JsonTest extends \yii\test\TestCase
$expression2
=
'function (b) {}'
;
$expression2
=
'function (b) {}'
;
$data
=
array
(
$data
=
array
(
'a'
=>
array
(
'a'
=>
array
(
1
,
new
Js
on
Expression
(
$expression1
)
1
,
new
JsExpression
(
$expression1
)
),
),
'b'
=>
new
Js
on
Expression
(
$expression2
),
'b'
=>
new
JsExpression
(
$expression2
),
);
);
$this
->
assertSame
(
"
{
\"a\":[1,$expression1],\"b\":$expression2
}
"
,
Json
::
encode
(
$data
));
$this
->
assertSame
(
"
{
\"a\":[1,$expression1],\"b\":$expression2
}
"
,
Json
::
encode
(
$data
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment