Base for a static organization website

TimedBehavior.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. App::uses('DebugKitDebugger', 'DebugKit.Lib');
  15. /**
  16. * Class TimedBehavior
  17. *
  18. * @since DebugKit 1.3
  19. */
  20. class TimedBehavior extends ModelBehavior {
  21. /**
  22. * Behavior settings
  23. *
  24. * @var array
  25. */
  26. public $settings = array();
  27. /**
  28. * Default setting values
  29. *
  30. * @var array
  31. */
  32. protected $_defaults = array();
  33. /**
  34. * Setup the behavior and import required classes.
  35. *
  36. * @param \Model|object $Model Model using the behavior
  37. * @param array $settings Settings to override for model.
  38. * @return void
  39. */
  40. public function setup(Model $Model, $settings = null) {
  41. if (is_array($settings)) {
  42. $this->settings[$Model->alias] = array_merge($this->_defaults, $settings);
  43. } else {
  44. $this->settings[$Model->alias] = $this->_defaults;
  45. }
  46. }
  47. /**
  48. * beforeFind, starts a timer for a find operation.
  49. *
  50. * @param Model $Model
  51. * @param array $queryData Array of query data (not modified)
  52. * @return boolean true
  53. */
  54. public function beforeFind(Model $Model, $queryData) {
  55. DebugKitDebugger::startTimer($Model->alias . '_find', $Model->alias . '->find()');
  56. return true;
  57. }
  58. /**
  59. * afterFind, stops a timer for a find operation.
  60. *
  61. * @param Model $Model
  62. * @param array $results Array of results
  63. * @param $primary
  64. * @return boolean true.
  65. */
  66. public function afterFind(Model $Model, $results, $primary = false) {
  67. DebugKitDebugger::stopTimer($Model->alias . '_find');
  68. return true;
  69. }
  70. /**
  71. * beforeSave, starts a time before a save is initiated.
  72. *
  73. * @param Model $Model
  74. * @param array $options
  75. * @return boolean true
  76. */
  77. public function beforeSave(Model $Model, $options = array()) {
  78. DebugKitDebugger::startTimer($Model->alias . '_save', $Model->alias . '->save()');
  79. return true;
  80. }
  81. /**
  82. * afterSave, stop the timer started from a save.
  83. *
  84. * @param \Model $Model
  85. * @param string $created
  86. * @return boolean Always true
  87. */
  88. public function afterSave(Model $Model, $created, $options = array()) {
  89. DebugKitDebugger::stopTimer($Model->alias . '_save');
  90. return true;
  91. }
  92. }