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
7a234327
Commit
7a234327
authored
Mar 30, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
7ff5f127
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
210 additions
and
189 deletions
+210
-189
Component.md
docs/api/framework/base/Component.md
+80
-0
Object.md
docs/api/framework/base/Object.md
+40
-0
Behavior.php
framework/base/Behavior.php
+2
-2
Component.php
framework/base/Component.php
+14
-61
Dictionary.php
framework/base/Dictionary.php
+4
-2
Event.php
framework/base/Event.php
+8
-9
Initable.php
framework/base/Initable.php
+3
-3
Model.php
framework/base/Model.php
+1
-0
ModelBehavior.php
framework/base/ModelBehavior.php
+5
-5
ModelEvent.php
framework/base/ModelEvent.php
+1
-1
Object.php
framework/base/Object.php
+2
-45
Vector.php
framework/base/Vector.php
+6
-4
ActiveRecordBehavior.php
framework/db/ar/ActiveRecordBehavior.php
+42
-55
Command.php
framework/db/dao/Command.php
+2
-2
No files found.
docs/api/framework/base/Component.md
0 → 100644
View file @
7a234327
Component provides the
*event*
and
*behavior*
features, in addition to the
*property*
feature which is implemented in
its parent class
[
[Object
]
].
Event is a way to "inject" custom code into existing code at certain places. For example, a comment object can trigger
an "add" event when the user adds a comment. We can write custom code and attach it to this event so that when the event
is triggered, our custom code will be executed.
An event is identified by a name (unique within the class it is defined). Event names are
*case-sensitive*
.
An event can be attached with one or multiple PHP callbacks, called
*event handlers*
. One can call
[
[trigger()
]
] to
raise an event. When an event is raised, the attached event handlers will be invoked automatically in the order they are
attached to the event.
To attach an event handler to an event, call
[
[on()
]
]. For example,
~~~
$comment->on('add', function($event) {
// send email notification
});
~~~
In the above, we attach an anonymous function to the "add" event of the comment. Valid event handlers include:
-
anonymous function:
`function($event) { ... }`
-
object method:
`array($object, 'handleAdd')`
-
static method:
`array('Page', 'handleAdd')`
-
global function:
`'handleAdd'`
The signature of an event handler should be like the following:
~~~
function foo($event)
~~~
where
`$event`
is an
[
[Event
]
] object which includes parameters associated with the event.
One can also attach an event handler to an event when configuring a component with a configuration array. The syntax is
like the following:
~~~
array(
'on add' => function($event) { ... }
)
~~~
where
`on add`
stands for attaching an event to the
`add`
event.
One can call
[
[getEventHandlers()
]
] to retrieve all event handlers that are attached to a specified event. Because this
method returns a
[
[Vector
]
] object, we can manipulate this object to attach/detach event handlers, or adjust their
relative orders.
~~~
$handlers = $comment->getEventHandlers('add');
$handlers->insertAt(0, $callback); // attach a handler as the first one
$handlers[] = $callback; // attach a handler as the last one
unset($handlers[0]); // detach the first handler
~~~
A behavior is an instance of
[
[Behavior
]
] or its child class. A component can be attached with one or multiple
behaviors. When a behavior is attached to a component, its public properties and methods can be accessed via the
component directly, as if the component owns those properties and methods.
To attach a behavior to a component, declare it in
[
[behaviors()
]
], or explicitly call
[
[attachBehavior
]
]. Behaviors
declared in
[
[behaviors()
]
] are automatically attached to the corresponding component.
One can also attach a behavior to a component when configuring it with a configuration array. The syntax is like the
following:
~~~
array(
'as tree' => array(
'class' => 'Tree',
),
)
~~~
where
`as tree`
stands for attaching a behavior named
`tree`
, and the array will be passed to
[
[\Yii::createObject()
]
]
to create the behavior object.
\ No newline at end of file
docs/api/framework/base/Object.md
0 → 100644
View file @
7a234327
A property is defined by a getter method (e.g.
`getLabel`
), and/or a setter method (e.g.
`setLabel`
). For example,
the following getter and setter methods define a property named
`label`
:
~~~
private $_label;
public function getLabel()
{
return $this->_label;
}
public function setLabel($value)
{
$this->_label = $value;
}
~~~
Property names are
*case-insensitive*
.
A property can be accessed like a member variable of an object. Reading or writing a property will cause the invocation
of the corresponding getter or setter method. For example,
~~~
// equivalent to $label = $object->getLabel();
$label = $object->label;
// equivalent to $object->setLabel('abc');
$object->label = 'abc';
~~~
If a property has only a getter method and has no setter method, it is considered as
*read-only*
. In this case, trying
to modify the property value will cause an exception.
One can call
[
[hasProperty
]
],
[
[canGetProperty
]
] and/or
[
[canSetProperty
]
] to check the existence of a property.
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/Behavior.php
View file @
7a234327
...
@@ -12,7 +12,7 @@ namespace yii\base;
...
@@ -12,7 +12,7 @@ namespace yii\base;
/**
/**
* Behavior is the base class for all behavior classes.
* Behavior is the base class for all behavior classes.
*
*
* A behavior can be used to enhance the functionality of an existing component.
* A behavior can be used to enhance the functionality of an existing component
without modifying its code
.
* In particular, it can "inject" its own methods and properties into the component
* In particular, it can "inject" its own methods and properties into the component
* and make them directly accessible via the component.
* and make them directly accessible via the component.
*
*
...
@@ -52,7 +52,7 @@ class Behavior extends \yii\base\Object
...
@@ -52,7 +52,7 @@ class Behavior extends \yii\base\Object
* )
* )
* ~~~
* ~~~
*
*
* @return array events (
keys) and the corresponding behavior method names (
values).
* @return array events (
array keys) and the corresponding event handler methods (array
values).
*/
*/
public
function
events
()
public
function
events
()
{
{
...
...
framework/base/Component.php
View file @
7a234327
...
@@ -10,65 +10,9 @@
...
@@ -10,65 +10,9 @@
namespace
yii\base
;
namespace
yii\base
;
/**
/**
* Component is the base class
for all component classes in Yii
.
* Component is the base class
that provides the *property*, *event* and *behavior* features
.
*
*
* Component provides the *event* and *behavior* features, in addition to
* @include @yii/base/Component.md
* the *property* feature which is implemented in its parent class [[Object]].
*
* Event is a way to "inject" custom code into existing code at certain places.
* For example, a comment object can trigger an "add" event when the user adds
* a comment. We can write custom code and attach it to this event so that
* when the event is triggered, our custom code will be executed.
*
* An event is identified by a name (unique within the class it is defined).
* Event names are *case-sensitive*.
*
* An event can be attached with one or multiple PHP callbacks, called *event handlers*.
* One can call [[trigger()]] to raise an event. When an event is raised, the attached
* event handlers will be invoked automatically in the order they are attached to the event.
*
* To attach an event handler to an event, call [[on()]]. For example,
*
* ~~~
* $comment->on('add', function($event) {
* // send email notification
* });
* ~~~
*
* In the above, we attach an anonymous function to the "add" event of the comment.
* Valid event handlers include:
*
* - anonymous function: `function($event) { ... }`
* - object method: `array($object, 'handleAdd')`
* - static method: `array('Page', 'handleAdd')`
* - global function: `'handleAdd'`
*
* The signature of an event handler should be like the following:
* ~~~
* function foo($event)
* ~~~
*
* where `$event` is an [[Event]] object which includes parameters associated with the event.
*
* One can call [[getEventHandlers()]] to retrieve all event handlers that are attached
* to a specified event. Because this method returns a [[Vector]] object, we can manipulate
* this object to attach/detach event handlers, or adjust their relative orders.
*
* ~~~
* $handlers = $comment->getEventHandlers('add');
* $handlers->insertAt(0, $callback); // attach a handler as the first one
* $handlers[] = $callback; // attach a handler as the last one
* unset($handlers[0]); // detach the first handler
* ~~~
*
*
* A behavior is an instance of [[Behavior]] or its child class. A component can be attached
* with one or multiple behaviors. When a behavior is attached to a component, its public
* properties and methods can be accessed via the component directly, as if the component owns
* those properties and methods.
*
* To attach a behavior to a component, declare it in [[behaviors()]], or explicitly call [[attachBehavior]].
* Behaviors declared in [[behaviors()]] are automatically attached to the corresponding component.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
...
@@ -134,13 +78,19 @@ class Component extends \yii\base\Object
...
@@ -134,13 +78,19 @@ class Component extends \yii\base\Object
public
function
__set
(
$name
,
$value
)
public
function
__set
(
$name
,
$value
)
{
{
$setter
=
'set'
.
$name
;
$setter
=
'set'
.
$name
;
if
(
method_exists
(
$this
,
$setter
))
{
// write property
if
(
method_exists
(
$this
,
$setter
))
{
// set property
$this
->
$setter
(
$value
);
$this
->
$setter
(
$value
);
return
;
return
;
}
elseif
(
strncmp
(
$name
,
'on '
,
3
)
===
0
)
{
// on event
}
elseif
(
strncmp
(
$name
,
'on '
,
3
)
===
0
)
{
// on event: attach event handler
$name
=
trim
(
substr
(
$name
,
3
));
$name
=
trim
(
substr
(
$name
,
3
));
$this
->
getEventHandlers
(
$name
)
->
add
(
$value
);
$this
->
getEventHandlers
(
$name
)
->
add
(
$value
);
return
;
return
;
}
elseif
(
strncmp
(
$name
,
'as '
,
3
)
===
0
)
{
// as behavior: attach behavior
$name
=
trim
(
substr
(
$name
,
3
));
$this
->
attachBehavior
(
$name
,
\Yii
::
createObject
(
$value
));
}
else
{
// behavior property
}
else
{
// behavior property
$this
->
ensureBehaviors
();
$this
->
ensureBehaviors
();
foreach
(
$this
->
_b
as
$behavior
)
{
foreach
(
$this
->
_b
as
$behavior
)
{
...
@@ -394,7 +344,7 @@ class Component extends \yii\base\Object
...
@@ -394,7 +344,7 @@ class Component extends \yii\base\Object
* @param string $behavior the behavior name
* @param string $behavior the behavior name
* @return Behavior the behavior object, or null if the behavior does not exist
* @return Behavior the behavior object, or null if the behavior does not exist
*/
*/
public
function
asa
(
$behavior
)
public
function
getBehavior
(
$behavior
)
{
{
$this
->
ensureBehaviors
();
$this
->
ensureBehaviors
();
return
isset
(
$this
->
_b
[
$behavior
])
?
$this
->
_b
[
$behavior
]
:
null
;
return
isset
(
$this
->
_b
[
$behavior
])
?
$this
->
_b
[
$behavior
]
:
null
;
...
@@ -493,6 +443,9 @@ class Component extends \yii\base\Object
...
@@ -493,6 +443,9 @@ class Component extends \yii\base\Object
if
(
!
(
$behavior
instanceof
Behavior
))
{
if
(
!
(
$behavior
instanceof
Behavior
))
{
$behavior
=
\Yii
::
createObject
(
$behavior
);
$behavior
=
\Yii
::
createObject
(
$behavior
);
}
}
if
(
isset
(
$this
->
_b
[
$name
]))
{
$this
->
_b
[
$name
]
->
detach
(
$this
);
}
$behavior
->
attach
(
$this
);
$behavior
->
attach
(
$this
);
return
$this
->
_b
[
$name
]
=
$behavior
;
return
$this
->
_b
[
$name
]
=
$behavior
;
}
}
...
...
framework/base/Dictionary.php
View file @
7a234327
...
@@ -13,9 +13,9 @@ namespace yii\base;
...
@@ -13,9 +13,9 @@ namespace yii\base;
* Dictionary implements a collection that stores key-value pairs.
* Dictionary implements a collection that stores key-value pairs.
*
*
* You can access, add or remove an item with a key by using
* You can access, add or remove an item with a key by using
* [[itemAt
]], [[add]], and [[remove
]].
* [[itemAt
()]], [[add()]], and [[remove()
]].
*
*
* To get the number of the items in the dictionary, use [[getCount]].
* To get the number of the items in the dictionary, use [[getCount
()
]].
*
*
* Because Dictionary implements a set of SPL interfaces, it can be used
* Because Dictionary implements a set of SPL interfaces, it can be used
* like a regular PHP array as follows,
* like a regular PHP array as follows,
...
@@ -28,6 +28,8 @@ namespace yii\base;
...
@@ -28,6 +28,8 @@ namespace yii\base;
* $n = count($dictionary); // returns the number of items in the dictionary
* $n = count($dictionary); // returns the number of items in the dictionary
* ~~~
* ~~~
*
*
* @property integer $count the number of items in the dictionary
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
...
...
framework/base/Event.php
View file @
7a234327
...
@@ -17,17 +17,16 @@ namespace yii\base;
...
@@ -17,17 +17,16 @@ namespace yii\base;
* And the [[handled]] property indicates if the event is handled.
* And the [[handled]] property indicates if the event is handled.
* If an event handler sets [[handled]] to be true, the rest of the
* If an event handler sets [[handled]] to be true, the rest of the
* uninvoked handlers will no longer be called to handle the event.
* uninvoked handlers will no longer be called to handle the event.
* Additionally, an event may specify extra parameters via the [[
params
]] property.
* Additionally, an event may specify extra parameters via the [[
data
]] property.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
Event
extends
Object
class
Event
extends
\yii\base\
Object
{
{
/**
/**
* @var string the event name. This property is set by [[Component::
raiseEvent
]].
* @var string the event name. This property is set by [[Component::
trigger()
]].
* Event handlers may use this property to check what event it is handling.
* Event handlers may use this property to check what event it is handling.
* The event name is in lower case.
*/
*/
public
$name
;
public
$name
;
/**
/**
...
@@ -41,19 +40,19 @@ class Event extends Object
...
@@ -41,19 +40,19 @@ class Event extends Object
*/
*/
public
$handled
=
false
;
public
$handled
=
false
;
/**
/**
* @var mixed extra
parameters
associated with the event.
* @var mixed extra
data
associated with the event.
*/
*/
public
$
params
;
public
$
data
;
/**
/**
* Constructor.
* Constructor.
*
*
* @param mixed $sender sender of the event
* @param mixed $sender sender of the event
* @param mixed $
params parameters of
the event
* @param mixed $
data extra data associated with
the event
*/
*/
public
function
__construct
(
$sender
=
null
,
$
params
=
null
)
public
function
__construct
(
$sender
=
null
,
$
data
=
null
)
{
{
$this
->
sender
=
$sender
;
$this
->
sender
=
$sender
;
$this
->
params
=
$params
;
$this
->
data
=
$data
;
}
}
}
}
framework/base/Initable.php
View file @
7a234327
...
@@ -12,9 +12,9 @@ namespace yii\base;
...
@@ -12,9 +12,9 @@ namespace yii\base;
/**
/**
* Initable is an interface indicating a class needs initialization to work properly.
* Initable is an interface indicating a class needs initialization to work properly.
*
*
* Initable requires a class to implement the [[init]] method.
* Initable requires a class to implement the [[init
()
]] method.
* When [[\Yii::createObject]] is being used to create a new component which implements
* When [[\Yii::createObject
()
]] is being used to create a new component which implements
* Initable, it will call the [[init]] method after setting the initial values of the
* Initable, it will call the [[init
()
]] method after setting the initial values of the
* component properties.
* component properties.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
framework/base/Model.php
View file @
7a234327
...
@@ -222,6 +222,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -222,6 +222,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
*/
*/
public
function
afterValidate
()
public
function
afterValidate
()
{
{
$this
->
trigger
(
'afterValidate'
);
if
(
$this
->
hasEventHandlers
(
'onAfterValidate'
))
{
if
(
$this
->
hasEventHandlers
(
'onAfterValidate'
))
{
$this
->
onAfterValidate
(
new
Event
(
$this
));
$this
->
onAfterValidate
(
new
Event
(
$this
));
}
}
...
...
framework/base/ModelBehavior.php
View file @
7a234327
...
@@ -21,7 +21,7 @@ namespace yii\base;
...
@@ -21,7 +21,7 @@ namespace yii\base;
class
ModelBehavior
extends
Behavior
class
ModelBehavior
extends
Behavior
{
{
/**
/**
* Declares event handlers for owner's events.
* Declares event handlers for
the
owner's events.
* The default implementation returns the following event handlers:
* The default implementation returns the following event handlers:
*
*
* - `beforeValidate` event
* - `beforeValidate` event
...
@@ -39,8 +39,8 @@ class ModelBehavior extends Behavior
...
@@ -39,8 +39,8 @@ class ModelBehavior extends Behavior
}
}
/**
/**
* Responds to
[[Model::onBeforeValidate]]
event.
* Responds to
the owner's `beforeValidate`
event.
* Override this method if you want to handle the
corresponding
event of the [[owner]].
* Override this method if you want to handle the
`beforeValidate`
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
* to be false to cancel the validation process.
* to be false to cancel the validation process.
* @param ModelEvent $event event parameter
* @param ModelEvent $event event parameter
...
@@ -50,8 +50,8 @@ class ModelBehavior extends Behavior
...
@@ -50,8 +50,8 @@ class ModelBehavior extends Behavior
}
}
/**
/**
* Responds to
[[Model::onAfterValidate]]
event.
* Responds to
the owner's `afterValidate`
event.
* Override this method if you want to handle the
corresponding
event of the [[owner]].
* Override this method if you want to handle the
`beforeValidate`
event of the [[owner]].
* @param Event $event event parameter
* @param Event $event event parameter
*/
*/
public
function
afterValidate
(
$event
)
public
function
afterValidate
(
$event
)
...
...
framework/base/ModelEvent.php
View file @
7a234327
...
@@ -21,7 +21,7 @@ class ModelEvent extends Event
...
@@ -21,7 +21,7 @@ class ModelEvent extends Event
{
{
/**
/**
* @var boolean whether the model is in valid status. Defaults to true.
* @var boolean whether the model is in valid status. Defaults to true.
* A model is in valid status if it passes validation
, or other
checks.
* A model is in valid status if it passes validation
s or certain
checks.
*/
*/
public
$isValid
=
true
;
public
$isValid
=
true
;
}
}
framework/base/Object.php
View file @
7a234327
...
@@ -10,52 +10,9 @@
...
@@ -10,52 +10,9 @@
namespace
yii\base
;
namespace
yii\base
;
/**
/**
* Object is the base class that
implement
s the *property* feature.
* Object is the base class that
provide
s the *property* feature.
*
*
* A property is defined by a getter method (e.g. `getLabel`),
* @include @yii/base/Object.md
* and/or a setter method (e.g. `setLabel`). For example, the following
* getter and setter methods define a property named `label`:
*
* ~~~
* private $_label;
*
* public function getLabel()
* {
* return $this->_label;
* }
*
* public function setLabel($value)
* {
* $this->_label = $value;
* }
* ~~~
*
* A property can be accessed like a member variable of an object.
* Reading or writing a property will cause the invocation of the corresponding
* getter or setter method. For example,
*
* ~~~
* // equivalent to $label = $object->getLabel();
* $label = $object->label;
* // equivalent to $object->setLabel('abc');
* $object->label = 'abc';
* ~~~
*
* If a property has only a getter method and has no setter method, it is
* considered as *read-only*. In this case, trying to modify the property value
* will cause an exception.
*
* Property names are *case-insensitive*.
*
* One can call [[hasProperty]], [[canGetProperty]] and/or [[canSetProperty]]
* to check the existence of a property.
*
* 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.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
...
...
framework/base/Vector.php
View file @
7a234327
...
@@ -13,10 +13,10 @@ namespace yii\base;
...
@@ -13,10 +13,10 @@ namespace yii\base;
* Vector implements an integer-indexed collection class.
* Vector implements an integer-indexed collection class.
*
*
* You can access, append, insert, remove an item from the vector
* You can access, append, insert, remove an item from the vector
* by calling methods such as [[itemAt
]], [[add]], [[insertAt
]],
* by calling methods such as [[itemAt
()]], [[add()]], [[insertAt()
]],
* [[remove
]] and [[removeAt
]].
* [[remove
()]] and [[removeAt()
]].
*
*
* To get the number of the items in the vector, use [[getCount]].
* To get the number of the items in the vector, use [[getCount
()
]].
*
*
* Because Vector implements a set of SPL interfaces, it can be used
* Because Vector implements a set of SPL interfaces, it can be used
* like a regular PHP array as follows,
* like a regular PHP array as follows,
...
@@ -32,7 +32,9 @@ namespace yii\base;
...
@@ -32,7 +32,9 @@ namespace yii\base;
*
*
* Note that if you plan to extend Vector by performing additional operations
* Note that if you plan to extend Vector by performing additional operations
* with each addition or removal of an item (e.g. performing type check),
* with each addition or removal of an item (e.g. performing type check),
* please make sure you override [[insertAt]] and [[removeAt]].
* please make sure you override [[insertAt()]] and [[removeAt()]].
*
* @property integer $count the number of items in the vector
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
...
...
framework/db/ar/ActiveRecordBehavior.php
View file @
7a234327
<?php
<?php
/**
/**
*
C
ActiveRecordBehavior class file.
* ActiveRecordBehavior class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\db\ar
;
use
yii\base\ModelBehavior
;
/**
/**
* CActiveRecordBehavior is the base class for behaviors that can be attached to {@link CActiveRecord}.
* ActiveRecordBehavior is the base class for behaviors that can be attached to [[ActiveRecord]].
* Compared with {@link CModelBehavior}, CActiveRecordBehavior attaches to more events
*
* that are only defined by {@link CActiveRecord}.
* Compared to [[\yii\base\ModelBehavior]], ActiveRecordBehavior responds to more events
* that are specific to [[ActiveRecord]].
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
CActiveRecordBehavior
extends
C
ModelBehavior
class
ActiveRecordBehavior
extends
ModelBehavior
{
{
/**
/**
* Declares events and the corresponding event handler methods.
* Declares events and the corresponding event handler methods.
* If you override this method, make sure you merge the parent result to the return value.
* If you override this method, make sure you merge the parent result to the return value.
* @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).
* @see
CBehavior::events
* @see
\yii\base\Behavior::events()
*/
*/
public
function
events
()
public
function
events
()
{
{
return
array_merge
(
parent
::
events
(),
array
(
return
array_merge
(
parent
::
events
(),
array
(
'onBeforeInsert'
=>
'beforeInsert'
,
'beforeInsert'
=>
'beforeInsert'
,
'onAfterInsert'
=>
'afterInsert'
,
'afterInsert'
=>
'afterInsert'
,
'onBeforeUpdate'
=>
'beforeUpdate'
,
'beforeUpdate'
=>
'beforeUpdate'
,
'onAfterUpdate'
=>
'afterUpdate'
,
'afterUpdate'
=>
'afterUpdate'
,
'onBeforeDelete'
=>
'beforeDelete'
,
'beforeDelete'
=>
'beforeDelete'
,
'onAfterDelete'
=>
'afterDelete'
,
'afterDelete'
=>
'afterDelete'
,
'onBeforeFind'
=>
'beforeFind'
,
'onAfterFind'
=>
'afterFind'
,
));
));
}
}
/**
/**
* Responds to {@link CActiveRecord::onBeforeSave} event.
* Responds to the owner's `beforeInsert` event.
* Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
* Overrides this method if you want to handle the corresponding event of the owner.
* You may set {@link CModelEvent::isValid} to be false to quit the saving process.
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter
* @param CModelEvent $event event parameter
* to be false to quit the ActiveRecord inserting process.
* @param \yii\base\ModelEvent $event event parameter
*/
*/
public
function
beforeInsert
(
$event
)
public
function
beforeInsert
(
$event
)
{
{
}
}
/**
/**
* Responds to
{@link CActiveRecord::onAfterSave}
event.
* Responds to
the owner's `afterInsert`
event.
* Overrides this method if you want to handle the corresponding event of the
{@link CBehavior::owner owner}
.
* Overrides this method if you want to handle the corresponding event of the
owner
.
* @param
C
ModelEvent $event event parameter
* @param
\yii\base\
ModelEvent $event event parameter
*/
*/
public
function
afterInsert
(
$event
)
public
function
afterInsert
(
$event
)
{
{
}
}
/**
/**
* Responds to {@link CActiveRecord::onBeforeSave} event.
* Responds to the owner's `beforeUpdate` event.
* Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
* Overrides this method if you want to handle the corresponding event of the owner.
* You may set {@link CModelEvent::isValid} to be false to quit the saving process.
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter
* @param CModelEvent $event event parameter
* to be false to quit the ActiveRecord updating process.
* @param \yii\base\ModelEvent $event event parameter
*/
*/
public
function
beforeUpdate
(
$event
)
public
function
beforeUpdate
(
$event
)
{
{
}
}
/**
/**
* Responds to
{@link CActiveRecord::onAfterSave}
event.
* Responds to
the owner's `afterUpdate`
event.
* Overrides this method if you want to handle the corresponding event of the
{@link CBehavior::owner owner}
.
* Overrides this method if you want to handle the corresponding event of the
owner
.
* @param
C
ModelEvent $event event parameter
* @param
\yii\base\
ModelEvent $event event parameter
*/
*/
public
function
afterUpdate
(
$event
)
public
function
afterUpdate
(
$event
)
{
{
}
}
/**
/**
* Responds to {@link CActiveRecord::onBeforeDelete} event.
* Responds to the owner's `beforeDelete` event.
* Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
* Overrides this method if you want to handle the corresponding event of the owner.
* You may set {@link CModelEvent::isValid} to be false to quit the deletion process.
* You may set the [[ModelEvent::isValid|isValid]] property of the event parameter
* @param CEvent $event event parameter
* to be false to quit the ActiveRecord deleting process.
* @param \yii\base\ModelEvent $event event parameter
*/
*/
public
function
beforeDelete
(
$event
)
public
function
beforeDelete
(
$event
)
{
{
}
}
/**
/**
* Responds to
{@link CActiveRecord::onAfterDelete}
event.
* Responds to
the owner's `afterDelete`
event.
* Overrides this method if you want to handle the corresponding event of the
{@link CBehavior::owner owner}
.
* Overrides this method if you want to handle the corresponding event of the
owner
.
* @param
C
Event $event event parameter
* @param
\yii\base\Model
Event $event event parameter
*/
*/
public
function
afterDelete
(
$event
)
public
function
afterDelete
(
$event
)
{
{
}
}
/**
* Responds to {@link CActiveRecord::onBeforeFind} event.
* Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
* @param CEvent $event event parameter
*/
public
function
beforeFind
(
$event
)
{
}
/**
* Responds to {@link CActiveRecord::onAfterFind} event.
* Overrides this method if you want to handle the corresponding event of the {@link CBehavior::owner owner}.
* @param CEvent $event event parameter
*/
public
function
afterFind
(
$event
)
{
}
}
}
framework/db/dao/Command.php
View file @
7a234327
...
@@ -222,7 +222,7 @@ class Command extends \yii\base\Component
...
@@ -222,7 +222,7 @@ class Command extends \yii\base\Component
}
}
\Yii
::
trace
(
"Executing SQL:
{
$sql
}{
$paramLog
}
"
,
__CLASS__
);
\Yii
::
trace
(
"Executing SQL:
{
$sql
}{
$paramLog
}
"
,
__CLASS__
);
echo
$sql
.
"
\n\n
"
;
//
echo $sql . "\n\n";
try
{
try
{
if
(
$this
->
connection
->
enableProfiling
)
{
if
(
$this
->
connection
->
enableProfiling
)
{
\Yii
::
beginProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
\Yii
::
beginProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS__
);
...
@@ -355,7 +355,7 @@ echo $sql . "\n\n";
...
@@ -355,7 +355,7 @@ echo $sql . "\n\n";
}
}
\Yii
::
trace
(
"Querying SQL:
{
$sql
}{
$paramLog
}
"
,
__CLASS__
);
\Yii
::
trace
(
"Querying SQL:
{
$sql
}{
$paramLog
}
"
,
__CLASS__
);
echo
$sql
.
"
\n\n
"
;
//
echo $sql . "\n\n";
if
(
$db
->
queryCachingCount
>
0
&&
$db
->
queryCachingDuration
>=
0
&&
$method
!==
''
)
{
if
(
$db
->
queryCachingCount
>
0
&&
$db
->
queryCachingDuration
>=
0
&&
$method
!==
''
)
{
$cache
=
\Yii
::
$application
->
getComponent
(
$db
->
queryCacheID
);
$cache
=
\Yii
::
$application
->
getComponent
(
$db
->
queryCacheID
);
}
}
...
...
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