helpers.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. if (!function_exists('debugbar')) {
  3. /**
  4. * Get the Debugbar instance
  5. *
  6. * @return \Barryvdh\Debugbar\LaravelDebugbar
  7. */
  8. function debugbar()
  9. {
  10. return app(\Barryvdh\Debugbar\LaravelDebugbar::class);
  11. }
  12. }
  13. if (!function_exists('debug')) {
  14. /**
  15. * Adds one or more messages to the MessagesCollector
  16. *
  17. * @param mixed ...$value
  18. * @return string
  19. */
  20. function debug($value)
  21. {
  22. $debugbar = debugbar();
  23. foreach (func_get_args() as $value) {
  24. $debugbar->addMessage($value, 'debug');
  25. }
  26. }
  27. }
  28. if (!function_exists('start_measure')) {
  29. /**
  30. * Starts a measure
  31. *
  32. * @param string $name Internal name, used to stop the measure
  33. * @param string $label Public name
  34. */
  35. function start_measure($name, $label = null)
  36. {
  37. debugbar()->startMeasure($name, $label);
  38. }
  39. }
  40. if (!function_exists('stop_measure')) {
  41. /**
  42. * Stop a measure
  43. *
  44. * @param string $name Internal name, used to stop the measure
  45. */
  46. function stop_measure($name)
  47. {
  48. debugbar()->stopMeasure($name);
  49. }
  50. }
  51. if (!function_exists('add_measure')) {
  52. /**
  53. * Adds a measure
  54. *
  55. * @param string $label
  56. * @param float $start
  57. * @param float $end
  58. */
  59. function add_measure($label, $start, $end)
  60. {
  61. debugbar()->addMeasure($label, $start, $end);
  62. }
  63. }
  64. if (!function_exists('measure')) {
  65. /**
  66. * Utility function to measure the execution of a Closure
  67. *
  68. * @param string $label
  69. * @param \Closure $closure
  70. */
  71. function measure($label, \Closure $closure)
  72. {
  73. debugbar()->measure($label, $closure);
  74. }
  75. }