Event.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Diagnostics;
  8. use OCP\Diagnostics\IEvent;
  9. class Event implements IEvent {
  10. /**
  11. * @var string
  12. */
  13. protected $id;
  14. /**
  15. * @var float
  16. */
  17. protected $start;
  18. /**
  19. * @var float
  20. */
  21. protected $end;
  22. /**
  23. * @var string
  24. */
  25. protected $description;
  26. /**
  27. * @param string $id
  28. * @param string $description
  29. * @param float $start
  30. */
  31. public function __construct($id, $description, $start) {
  32. $this->id = $id;
  33. $this->description = $description;
  34. $this->start = $start;
  35. }
  36. /**
  37. * @param float $time
  38. */
  39. public function end($time) {
  40. $this->end = $time;
  41. }
  42. /**
  43. * @return float
  44. */
  45. public function getStart() {
  46. return $this->start;
  47. }
  48. /**
  49. * @return string
  50. */
  51. public function getId() {
  52. return $this->id;
  53. }
  54. /**
  55. * @return string
  56. */
  57. public function getDescription() {
  58. return $this->description;
  59. }
  60. /**
  61. * @return float
  62. */
  63. public function getEnd() {
  64. return $this->end;
  65. }
  66. /**
  67. * @return float
  68. */
  69. public function getDuration() {
  70. if (!$this->end) {
  71. $this->end = microtime(true);
  72. }
  73. return $this->end - $this->start;
  74. }
  75. public function __toString(): string {
  76. return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration();
  77. }
  78. }