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
9d8c0968
Commit
9d8c0968
authored
Aug 03, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #714 from crtlib/patch-3
Another try for Component::hasProperty() optimization
parents
a1d1b2fb
80f1fda7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
30 deletions
+30
-30
Component.php
framework/yii/base/Component.php
+18
-18
Object.php
framework/yii/base/Object.php
+12
-12
No files found.
framework/yii/base/Component.php
View file @
9d8c0968
...
...
@@ -220,19 +220,19 @@ class Component extends Object
*
* - the class has a getter or setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - an attached behavior has a property of the given name (when `$checkBehavior` is true).
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
* - an attached behavior has a property of the given name (when `$checkBehavior
s
` is true).
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkBehavior whether to treat behaviors' properties as properties of this component
* @param boolean $checkVar
s
whether to treat member variables as properties
* @param boolean $checkBehavior
s
whether to treat behaviors' properties as properties of this component
* @return boolean whether the property is defined
* @see canGetProperty
* @see canSetProperty
*/
public
function
hasProperty
(
$name
,
$checkVar
=
true
,
$checkBehavior
=
true
)
public
function
hasProperty
(
$name
,
$checkVar
s
=
true
,
$checkBehaviors
=
true
)
{
return
$this
->
canGetProperty
(
$name
,
$checkVar
,
$checkBehavior
)
||
$this
->
canSetProperty
(
$name
,
$checkVar
,
$checkBehavior
);
return
$this
->
canGetProperty
(
$name
,
$checkVar
s
,
$checkBehaviors
)
||
$this
->
canSetProperty
(
$name
,
false
,
$checkBehaviors
);
}
/**
...
...
@@ -241,23 +241,23 @@ class Component extends Object
*
* - the class has a getter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - an attached behavior has a readable property of the given name (when `$checkBehavior` is true).
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
* - an attached behavior has a readable property of the given name (when `$checkBehavior
s
` is true).
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @param boolean $checkBehaviors whether to treat behaviors' properties as properties of this component
* @return boolean whether the property can be read
* @see canSetProperty
*/
public
function
canGetProperty
(
$name
,
$checkVar
=
true
,
$checkBehaviors
=
true
)
public
function
canGetProperty
(
$name
,
$checkVar
s
=
true
,
$checkBehaviors
=
true
)
{
if
(
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
))
{
if
(
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
))
{
return
true
;
}
elseif
(
$checkBehaviors
)
{
$this
->
ensureBehaviors
();
foreach
(
$this
->
_behaviors
as
$behavior
)
{
if
(
$behavior
->
canGetProperty
(
$name
,
$checkVar
))
{
if
(
$behavior
->
canGetProperty
(
$name
,
$checkVar
s
))
{
return
true
;
}
}
...
...
@@ -271,23 +271,23 @@ class Component extends Object
*
* - the class has a setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - an attached behavior has a writable property of the given name (when `$checkBehavior` is true).
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
* - an attached behavior has a writable property of the given name (when `$checkBehavior
s
` is true).
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @param boolean $checkBehaviors whether to treat behaviors' properties as properties of this component
* @return boolean whether the property can be written
* @see canGetProperty
*/
public
function
canSetProperty
(
$name
,
$checkVar
=
true
,
$checkBehaviors
=
true
)
public
function
canSetProperty
(
$name
,
$checkVar
s
=
true
,
$checkBehaviors
=
true
)
{
if
(
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
))
{
if
(
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
))
{
return
true
;
}
elseif
(
$checkBehaviors
)
{
$this
->
ensureBehaviors
();
foreach
(
$this
->
_behaviors
as
$behavior
)
{
if
(
$behavior
->
canSetProperty
(
$name
,
$checkVar
))
{
if
(
$behavior
->
canSetProperty
(
$name
,
$checkVar
s
))
{
return
true
;
}
}
...
...
framework/yii/base/Object.php
View file @
9d8c0968
...
...
@@ -170,17 +170,17 @@ class Object implements Arrayable
*
* - the class has a getter or setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @return boolean whether the property is defined
* @see canGetProperty
* @see canSetProperty
*/
public
function
hasProperty
(
$name
,
$checkVar
=
true
)
public
function
hasProperty
(
$name
,
$checkVar
s
=
true
)
{
return
$this
->
canGetProperty
(
$name
,
$checkVar
)
||
$this
->
canSetProperty
(
$name
,
false
);
return
$this
->
canGetProperty
(
$name
,
$checkVar
s
)
||
$this
->
canSetProperty
(
$name
,
false
);
}
/**
...
...
@@ -189,16 +189,16 @@ class Object implements Arrayable
*
* - the class has a getter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @return boolean whether the property can be read
* @see canSetProperty
*/
public
function
canGetProperty
(
$name
,
$checkVar
=
true
)
public
function
canGetProperty
(
$name
,
$checkVar
s
=
true
)
{
return
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
);
return
method_exists
(
$this
,
'get'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
);
}
/**
...
...
@@ -207,16 +207,16 @@ class Object implements Arrayable
*
* - the class has a setter method associated with the specified name
* (in this case, property name is case-insensitive);
* - the class has a member variable with the specified name (when `$checkVar` is true);
* - the class has a member variable with the specified name (when `$checkVar
s
` is true);
*
* @param string $name the property name
* @param boolean $checkVar whether to treat member variables as properties
* @param boolean $checkVar
s
whether to treat member variables as properties
* @return boolean whether the property can be written
* @see canGetProperty
*/
public
function
canSetProperty
(
$name
,
$checkVar
=
true
)
public
function
canSetProperty
(
$name
,
$checkVar
s
=
true
)
{
return
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
&&
property_exists
(
$this
,
$name
);
return
method_exists
(
$this
,
'set'
.
$name
)
||
$checkVar
s
&&
property_exists
(
$this
,
$name
);
}
/**
...
...
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