AbstractDataCollector.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\DataCollector;
  8. /**
  9. * Children of this class must store the collected data in
  10. * the data property.
  11. *
  12. * @author Fabien Potencier <fabien@symfony.com>
  13. * @author Bernhard Schussek <bschussek@symfony.com>
  14. * @author Carl Schwan <carl@carlschwan.eu>
  15. * @since 24.0.0
  16. */
  17. abstract class AbstractDataCollector implements IDataCollector, \JsonSerializable {
  18. /** @var array */
  19. protected $data = [];
  20. /**
  21. * @since 24.0.0
  22. */
  23. public function getName(): string {
  24. return static::class;
  25. }
  26. /**
  27. * Reset the state of the profiler. By default it only empties the
  28. * $this->data contents, but you can override this method to do
  29. * additional cleaning.
  30. * @since 24.0.0
  31. */
  32. public function reset(): void {
  33. $this->data = [];
  34. }
  35. /**
  36. * @since 24.0.0
  37. */
  38. public function __sleep(): array {
  39. return ['data'];
  40. }
  41. /**
  42. * @internal to prevent implementing \Serializable
  43. * @since 24.0.0
  44. */
  45. final protected function serialize() {
  46. }
  47. /**
  48. * @internal to prevent implementing \Serializable
  49. * @since 24.0.0
  50. */
  51. final protected function unserialize(string $data) {
  52. }
  53. /**
  54. * @since 24.0.0
  55. */
  56. #[\ReturnTypeWillChange]
  57. public function jsonSerialize() {
  58. return $this->data;
  59. }
  60. }