Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12345 anikendra 1
<?php
2
/**
3
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5
 *
6
 * Licensed under The MIT License
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
10
 * @link          http://cakephp.org CakePHP(tm) Project
11
 * @since         DebugKit 1.3
12
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
13
 */
14
 
15
App::uses('DebugKitDebugger', 'DebugKit.Lib');
16
 
17
/**
18
 * Class TimedBehavior
19
 *
20
 * @since         DebugKit 1.3
21
 */
22
class TimedBehavior extends ModelBehavior {
23
 
24
/**
25
 * Behavior settings
26
 *
27
 * @var array
28
 */
29
	public $settings = array();
30
 
31
/**
32
 * Default setting values
33
 *
34
 * @var array
35
 */
36
	protected $_defaults = array();
37
 
38
/**
39
 * Setup the behavior and import required classes.
40
 *
41
 * @param \Model|object $Model Model using the behavior
42
 * @param array $settings Settings to override for model.
43
 * @return void
44
 */
45
	public function setup(Model $Model, $settings = null) {
46
		if (is_array($settings)) {
47
			$this->settings[$Model->alias] = array_merge($this->_defaults, $settings);
48
		} else {
49
			$this->settings[$Model->alias] = $this->_defaults;
50
		}
51
	}
52
 
53
/**
54
 * beforeFind, starts a timer for a find operation.
55
 *
56
 * @param Model $Model
57
 * @param array $queryData Array of query data (not modified)
58
 * @return boolean true
59
 */
60
	public function beforeFind(Model $Model, $queryData) {
61
		DebugKitDebugger::startTimer($Model->alias . '_find', $Model->alias . '->find()');
62
		return true;
63
	}
64
 
65
/**
66
 * afterFind, stops a timer for a find operation.
67
 *
68
 * @param Model $Model
69
 * @param array $results Array of results
70
 * @param $primary
71
 * @return boolean true.
72
 */
73
	public function afterFind(Model $Model, $results, $primary = false) {
74
		DebugKitDebugger::stopTimer($Model->alias . '_find');
75
		return true;
76
	}
77
 
78
/**
79
 * beforeSave, starts a time before a save is initiated.
80
 *
81
 * @param Model $Model
82
 * @param array $options
83
 * @return boolean true
84
 */
85
	public function beforeSave(Model $Model, $options = array()) {
86
		DebugKitDebugger::startTimer($Model->alias . '_save', $Model->alias . '->save()');
87
		return true;
88
	}
89
 
90
/**
91
 * afterSave, stop the timer started from a save.
92
 *
93
 * @param \Model $Model
94
 * @param string $created
95
 * @return boolean Always true
96
 */
97
	public function afterSave(Model $Model, $created, $options = array()) {
98
		DebugKitDebugger::stopTimer($Model->alias . '_save');
99
		return true;
100
	}
101
 
102
}