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
47fe25d4
Commit
47fe25d4
authored
Mar 27, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new event implementation.
parent
e281b402
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
134 deletions
+91
-134
Behavior.php
framework/base/Behavior.php
+8
-8
Component.php
framework/base/Component.php
+0
-0
ModelBehavior.php
framework/base/ModelBehavior.php
+4
-15
Object.php
framework/base/Object.php
+2
-2
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+77
-109
No files found.
framework/base/Behavior.php
View file @
47fe25d4
...
@@ -19,7 +19,7 @@ namespace yii\base;
...
@@ -19,7 +19,7 @@ namespace yii\base;
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
Behavior
extends
Object
class
Behavior
extends
\yii\base\
Object
{
{
/**
/**
* @var Component the owner component
* @var Component the owner component
...
@@ -38,17 +38,17 @@ class Behavior extends Object
...
@@ -38,17 +38,17 @@ class Behavior extends Object
*
*
* The callbacks can be any of the followings:
* The callbacks can be any of the followings:
*
*
* - method in this behavior: `'handle
OnClick'`, equivalent to `array($this, 'handleOn
Click')`
* - method in this behavior: `'handle
Click'`, equivalent to `array($this, 'handle
Click')`
* - object method: `array($object, 'handle
On
Click')`
* - object method: `array($object, 'handleClick')`
* - static method: `array('Page', 'handle
On
Click')`
* - static method: `array('Page', 'handleClick')`
* - anonymous function: `function($event) { ... }`
* - anonymous function: `function($event) { ... }`
*
*
* The following is an example:
* The following is an example:
*
*
* ~~~
* ~~~
* array(
* array(
* '
onB
eforeValidate' => 'myBeforeValidate',
* '
b
eforeValidate' => 'myBeforeValidate',
* '
onA
fterValidate' => 'myAfterValidate',
* '
a
fterValidate' => 'myAfterValidate',
* )
* )
* ~~~
* ~~~
*
*
...
@@ -70,7 +70,7 @@ class Behavior extends Object
...
@@ -70,7 +70,7 @@ class Behavior extends Object
{
{
$this
->
_owner
=
$owner
;
$this
->
_owner
=
$owner
;
foreach
(
$this
->
events
()
as
$event
=>
$handler
)
{
foreach
(
$this
->
events
()
as
$event
=>
$handler
)
{
$owner
->
attachEventHandler
(
$event
,
is_string
(
$handler
)
?
array
(
$this
,
$handler
)
:
$handler
);
$owner
->
on
(
$event
,
is_string
(
$handler
)
?
array
(
$this
,
$handler
)
:
$handler
);
}
}
}
}
...
@@ -84,7 +84,7 @@ class Behavior extends Object
...
@@ -84,7 +84,7 @@ 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
,
is_string
(
$handler
)
?
array
(
$this
,
$handler
)
:
$handler
);
$owner
->
off
(
$event
,
is_string
(
$handler
)
?
array
(
$this
,
$handler
)
:
$handler
);
}
}
$this
->
_owner
=
null
;
$this
->
_owner
=
null
;
}
}
...
...
framework/base/Component.php
View file @
47fe25d4
This diff is collapsed.
Click to expand it.
framework/base/ModelBehavior.php
View file @
47fe25d4
...
@@ -24,9 +24,8 @@ class ModelBehavior extends Behavior
...
@@ -24,9 +24,8 @@ class ModelBehavior extends Behavior
* Declares event handlers for owner's events.
* Declares event handlers for owner's events.
* The default implementation returns the following event handlers:
* The default implementation returns the following event handlers:
*
*
* - `onAfterInit` event: [[afterInit]]
* - `beforeValidate` event
* - `onBeforeValidate` event: [[beforeValidate]]
* - `afterValidate` event
* - `onAfterValidate` event: [[afterValidate]]
*
*
* You may override these event handler methods to respond to the corresponding owner events.
* You may override these event handler methods to respond to the corresponding owner events.
* @return array events (array keys) and the corresponding event handler methods (array values).
* @return array events (array keys) and the corresponding event handler methods (array values).
...
@@ -34,22 +33,12 @@ class ModelBehavior extends Behavior
...
@@ -34,22 +33,12 @@ class ModelBehavior extends Behavior
public
function
events
()
public
function
events
()
{
{
return
array
(
return
array
(
'onAfterInit'
=>
'afterInit'
,
'beforeValidate'
=>
'beforeValidate'
,
'onBeforeValidate'
=>
'beforeValidate'
,
'afterValidate'
=>
'afterValidate'
,
'onAfterValidate'
=>
'afterValidate'
,
);
);
}
}
/**
/**
* Responds to [[Model::onAfterInit]] event.
* Override this method if you want to handle the corresponding event of the [[owner]].
* @param Event $event event parameter
*/
public
function
afterInit
(
$event
)
{
}
/**
* Responds to [[Model::onBeforeValidate]] event.
* Responds to [[Model::onBeforeValidate]] event.
* Override this method if you want to handle the corresponding event of the [[owner]].
* Override this method if you want to handle the corresponding event of the [[owner]].
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter
...
...
framework/base/Object.php
View file @
47fe25d4
...
@@ -294,7 +294,7 @@ class Object
...
@@ -294,7 +294,7 @@ class Object
* ~~~
* ~~~
*
*
* @param array $config the object configuration (name-value pairs that will be used to initialize the object)
* @param array $config the object configuration (name-value pairs that will be used to initialize the object)
* @return Object the created object
* @return
\yii\base\
Object the created object
* @throws Exception if the configuration is invalid.
* @throws Exception if the configuration is invalid.
*/
*/
public
static
function
newInstance
(
$config
=
array
())
public
static
function
newInstance
(
$config
=
array
())
...
@@ -326,7 +326,7 @@ class Object
...
@@ -326,7 +326,7 @@ class Object
$object
->
$name
=
$value
;
$object
->
$name
=
$value
;
}
}
if
(
$object
instanceof
\yii\base\
Initable
)
{
if
(
$object
instanceof
Initable
)
{
$object
->
init
();
$object
->
init
();
}
}
...
...
tests/unit/framework/base/ComponentTest.php
View file @
47fe25d4
This diff is collapsed.
Click to expand it.
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