Event.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Diagnostics;
  24. use OCP\Diagnostics\IEvent;
  25. class Event implements IEvent {
  26. /**
  27. * @var string
  28. */
  29. protected $id;
  30. /**
  31. * @var float
  32. */
  33. protected $start;
  34. /**
  35. * @var float
  36. */
  37. protected $end;
  38. /**
  39. * @var string
  40. */
  41. protected $description;
  42. /**
  43. * @param string $id
  44. * @param string $description
  45. * @param float $start
  46. */
  47. public function __construct($id, $description, $start) {
  48. $this->id = $id;
  49. $this->description = $description;
  50. $this->start = $start;
  51. }
  52. /**
  53. * @param float $time
  54. */
  55. public function end($time) {
  56. $this->end = $time;
  57. }
  58. /**
  59. * @return float
  60. */
  61. public function getStart() {
  62. return $this->start;
  63. }
  64. /**
  65. * @return string
  66. */
  67. public function getId() {
  68. return $this->id;
  69. }
  70. /**
  71. * @return string
  72. */
  73. public function getDescription() {
  74. return $this->description;
  75. }
  76. /**
  77. * @return float
  78. */
  79. public function getEnd() {
  80. return $this->end;
  81. }
  82. /**
  83. * @return float
  84. */
  85. public function getDuration() {
  86. if (!$this->end) {
  87. $this->end = microtime(true);
  88. }
  89. return $this->end - $this->start;
  90. }
  91. public function __toString() {
  92. return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration();
  93. }
  94. }