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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
f3b057c4
Commit
f3b057c4
authored
Nov 11, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code refactoring.
parent
f9aa9a18
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
9 deletions
+19
-9
Behavior.php
framework/base/Behavior.php
+19
-9
No files found.
framework/base/Behavior.php
View file @
f3b057c4
...
@@ -21,19 +21,29 @@ namespace yii\base;
...
@@ -21,19 +21,29 @@ namespace yii\base;
*/
*/
class
Behavior
extends
Object
class
Behavior
extends
Object
{
{
/**
* @var Component the owner component
*/
private
$_owner
;
private
$_owner
;
/**
/**
* Declares event handlers for the [[owner]]'s events.
* Declares event handlers for the [[owner]]'s events.
*
*
* Child classes may override this method to declare which methods in this behavior
* Child classes may override this method to declare what PHP callbacks should
* should be attached to which events of the [[owner]] component.
* be attached to the events of the [[owner]] component.
* The methods will be attached to the [[owner]]'s events when the behavior is
*
* The callbacks will be attached to the [[owner]]'s events when the behavior is
* attached to the owner; and they will be detached from the events when
* attached to the owner; and they will be detached from the events when
* the behavior is detached from the component.
* the behavior is detached from the component.
*
*
* The method should return an array whose keys are the names of the owner's events
* The callbacks can be any of the followings:
* and values are the names of the behavior methods. For example,
*
* - method in this behavior: `'handleOnClick'`, equivalent to `array($this, 'handleOnClick')`
* - object method: `array($object, 'handleOnClick')`
* - static method: `array('Page', 'handleOnClick')`
* - anonymous function: `function($event) { ... }`
*
* The following is an example:
*
*
* ~~~
* ~~~
* array(
* array(
...
@@ -59,8 +69,8 @@ class Behavior extends Object
...
@@ -59,8 +69,8 @@ class Behavior extends Object
public
function
attach
(
$owner
)
public
function
attach
(
$owner
)
{
{
$this
->
_owner
=
$owner
;
$this
->
_owner
=
$owner
;
foreach
(
$this
->
events
()
as
$event
=>
$handler
)
{
foreach
(
$this
->
events
()
as
$event
=>
$handler
)
{
$owner
->
attachEventHandler
(
$event
,
array
(
$this
,
$handler
)
);
$owner
->
attachEventHandler
(
$event
,
is_string
(
$handler
)
?
array
(
$this
,
$handler
)
:
$handler
);
}
}
}
}
...
@@ -73,8 +83,8 @@ class Behavior extends Object
...
@@ -73,8 +83,8 @@ class Behavior extends Object
*/
*/
public
function
detach
(
$owner
)
public
function
detach
(
$owner
)
{
{
foreach
(
$this
->
events
()
as
$event
=>
$handler
)
{
foreach
(
$this
->
events
()
as
$event
=>
$handler
)
{
$owner
->
detachEventHandler
(
$event
,
array
(
$this
,
$handler
)
);
$owner
->
detachEventHandler
(
$event
,
is_string
(
$handler
)
?
array
(
$this
,
$handler
)
:
$handler
);
}
}
$this
->
_owner
=
null
;
$this
->
_owner
=
null
;
}
}
...
...
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