ActiveRecordBehavior.php 3.03 KB
Newer Older
w  
Qiang Xue committed
1 2
<?php
/**
Qiang Xue committed
3
 * ActiveRecordBehavior class file.
w  
Qiang Xue committed
4 5
 *
 * @link http://www.yiiframework.com/
Qiang Xue committed
6
 * @copyright Copyright &copy; 2008-2012 Yii Software LLC
w  
Qiang Xue committed
7 8 9
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
10
namespace yii\db;
Qiang Xue committed
11 12 13

use yii\base\ModelBehavior;

w  
Qiang Xue committed
14
/**
Qiang Xue committed
15 16 17 18
 * ActiveRecordBehavior is the base class for behaviors that can be attached to [[ActiveRecord]].
 *
 * Compared to [[\yii\base\ModelBehavior]], ActiveRecordBehavior responds to more events
 * that are specific to [[ActiveRecord]].
w  
Qiang Xue committed
19 20
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
Alexander Makarov committed
21
 * @since 2.0
w  
Qiang Xue committed
22
 */
Qiang Xue committed
23
class ActiveRecordBehavior extends ModelBehavior
w  
Qiang Xue committed
24 25 26 27 28
{
	/**
	 * Declares events and the corresponding event handler methods.
	 * 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).
Qiang Xue committed
29
	 * @see \yii\base\Behavior::events()
w  
Qiang Xue committed
30 31 32 33
	 */
	public function events()
	{
		return array_merge(parent::events(), array(
Qiang Xue committed
34 35 36 37 38 39
			'beforeInsert' => 'beforeInsert',
			'afterInsert' => 'afterInsert',
			'beforeUpdate' => 'beforeUpdate',
			'afterUpdate' => 'afterUpdate',
			'beforeDelete' => 'beforeDelete',
			'afterDelete' => 'afterDelete',
w  
Qiang Xue committed
40 41 42 43
		));
	}

	/**
Qiang Xue committed
44 45 46 47 48
	 * Responds to the owner's `beforeInsert` event.
	 * Overrides 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
	 * to be false to quit the ActiveRecord inserting process.
	 * @param \yii\base\ModelEvent $event event parameter
w  
Qiang Xue committed
49
	 */
Qiang Xue committed
50
	public function beforeInsert($event)
w  
Qiang Xue committed
51 52 53 54
	{
	}

	/**
Qiang Xue committed
55 56 57
	 * Responds to the owner's `afterInsert` event.
	 * Overrides this method if you want to handle the corresponding event of the owner.
	 * @param \yii\base\ModelEvent $event event parameter
w  
Qiang Xue committed
58
	 */
Qiang Xue committed
59 60 61 62 63
	public function afterInsert($event)
	{
	}

	/**
Qiang Xue committed
64 65 66 67 68
	 * Responds to the owner's `beforeUpdate` event.
	 * Overrides 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
	 * to be false to quit the ActiveRecord updating process.
	 * @param \yii\base\ModelEvent $event event parameter
Qiang Xue committed
69 70 71 72 73 74
	 */
	public function beforeUpdate($event)
	{
	}

	/**
Qiang Xue committed
75 76 77
	 * Responds to the owner's `afterUpdate` event.
	 * Overrides this method if you want to handle the corresponding event of the owner.
	 * @param \yii\base\ModelEvent $event event parameter
Qiang Xue committed
78 79
	 */
	public function afterUpdate($event)
w  
Qiang Xue committed
80 81 82 83
	{
	}

	/**
Qiang Xue committed
84 85 86 87 88
	 * Responds to the owner's `beforeDelete` event.
	 * Overrides 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
	 * to be false to quit the ActiveRecord deleting process.
	 * @param \yii\base\ModelEvent $event event parameter
w  
Qiang Xue committed
89 90 91 92 93 94
	 */
	public function beforeDelete($event)
	{
	}

	/**
Qiang Xue committed
95 96 97
	 * Responds to the owner's `afterDelete` event.
	 * Overrides this method if you want to handle the corresponding event of the owner.
	 * @param \yii\base\ModelEvent $event event parameter
w  
Qiang Xue committed
98 99 100 101 102
	 */
	public function afterDelete($event)
	{
	}
}