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
1599a2cf
Commit
1599a2cf
authored
Jun 01, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed Object::evaluateExpression().
Finished ExpressionDependency.
parent
37c874f1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
4 additions
and
55 deletions
+4
-55
Object.md
docs/api/framework/base/Object.md
+0
-4
Component.php
framework/base/Component.php
+1
-1
Object.php
framework/base/Object.php
+0
-35
ExpressionDependency.php
framework/caching/ExpressionDependency.php
+3
-8
ObjectTest.php
tests/unit/framework/base/ObjectTest.php
+0
-7
No files found.
docs/api/framework/base/Object.md
View file @
1599a2cf
...
...
@@ -34,6 +34,3 @@ One can call [[hasProperty]], [[canGetProperty]] and/or [[canSetProperty]] to ch
Besides the property feature, the Object class defines a static method
[
[create
]
] which provides a convenient
alternative way of creating a new object instance.
The Object class also defines the
[
[evaluateExpression
]
] method so that a PHP expression or callback can be dynamically
evaluated within the context of an object.
\ No newline at end of file
framework/base/Component.php
View file @
1599a2cf
...
...
@@ -92,7 +92,7 @@ class Component extends \yii\base\Object
}
elseif
(
strncmp
(
$name
,
'as '
,
3
)
===
0
)
{
// as behavior: attach behavior
$name
=
trim
(
substr
(
$name
,
3
));
$this
->
attachBehavior
(
$name
,
\Yii
::
createObject
(
$value
));
$this
->
attachBehavior
(
$name
,
$value
instanceof
Behavior
?
$value
:
\Yii
::
createObject
(
$value
));
}
else
{
// behavior property
$this
->
ensureBehaviors
();
...
...
framework/base/Object.php
View file @
1599a2cf
...
...
@@ -180,41 +180,6 @@ class Object
}
/**
* Evaluates a PHP expression or callback under the context of this object.
*
* Valid PHP callback can be class method name in the form of
* array(ClassName/Object, MethodName), or anonymous function.
*
* If a PHP callback is used, the corresponding function/method signature should be
*
* ~~~
* function foo($param1, $param2, ..., $object) { ... }
* ~~~
*
* where the array elements in the second parameter to this method will be passed
* to the callback as `$param1`, `$param2`, ...; and the last parameter will be the object itself.
*
* If a PHP expression is used, the second parameter will be "extracted" into PHP variables
* that can be directly accessed in the expression.
* See [PHP extract](http://us.php.net/manual/en/function.extract.php)
* for more details. In the expression, the object can be accessed using `$this`.
*
* @param mixed $_expression_ a PHP expression or PHP callback to be evaluated.
* @param array $_data_ additional parameters to be passed to the above expression/callback.
* @return mixed the expression result
*/
public
function
evaluateExpression
(
$_expression_
,
$_data_
=
array
())
{
if
(
is_string
(
$_expression_
))
{
extract
(
$_data_
);
return
eval
(
'return '
.
$_expression_
.
';'
);
}
else
{
$_data_
[]
=
$this
;
return
call_user_func_array
(
$_expression_
,
$_data_
);
}
}
/**
* Creates a new instance of the calling class.
*
* The newly created object will be initialized with the specified configuration.
...
...
framework/caching/ExpressionDependency.php
View file @
1599a2cf
...
...
@@ -12,9 +12,8 @@ namespace yii\caching;
/**
* ExpressionDependency represents a dependency based on the result of a PHP expression.
*
* ExpressionDependency performs dependency checking based on the
* result of a PHP {@link expression}.
* The dependency is reported as unchanged if and only if the result is
* ExpressionDependency will use `eval()` to evaluate the PHP expression.
* The dependency is reported as unchanged if and only if the result of the expression is
* the same as the one evaluated when storing the data to cache.
*
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -24,10 +23,6 @@ class ExpressionDependency extends Dependency
{
/**
* @var string the PHP expression whose result is used to determine the dependency.
* The expression can also be a valid PHP callback,
* including class method name (array(ClassName/Object, MethodName)),
* or anonymous function (PHP 5.3.0+). The function/method will be passed with a
* parameter which is the dependency object itself.
*/
public
$expression
;
...
...
@@ -47,6 +42,6 @@ class ExpressionDependency extends Dependency
*/
protected
function
generateDependencyData
()
{
return
$this
->
evaluateExpression
(
$this
->
expression
);
return
eval
(
"return
{
$this
->
expression
}
;"
);
}
}
tests/unit/framework/base/ObjectTest.php
View file @
1599a2cf
...
...
@@ -116,13 +116,6 @@ class ObjectTest extends \yiiunit\TestCase
$this
->
assertTrue
(
isset
(
$this
->
object
->
Text
));
$this
->
assertTrue
(
empty
(
$this
->
object
->
Text
));
}
public
function
testEvaluateExpression
()
{
$object
=
new
NewObject
;
$this
->
assertEquals
(
'Hello world'
,
$object
->
evaluateExpression
(
'"Hello $who"'
,
array
(
'who'
=>
'world'
)));
$this
->
assertEquals
(
'Hello world'
,
$object
->
evaluateExpression
(
array
(
$object
,
'exprEvaluator'
),
array
(
'who'
=>
'world'
)));
}
}
...
...
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