AbstractDataCollector.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
  5. *
  6. * @author Carl Schwan <carl@carlschwan.eu>
  7. * @author Fabien Potencier <fabien@symfony.com>
  8. *
  9. * @license AGPL-3.0-or-later AND MIT
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCP\DataCollector;
  26. /**
  27. * Children of this class must store the collected data in
  28. * the data property.
  29. *
  30. * @author Fabien Potencier <fabien@symfony.com>
  31. * @author Bernhard Schussek <bschussek@symfony.com>
  32. * @author Carl Schwan <carl@carlschwan.eu>
  33. * @since 24.0.0
  34. */
  35. abstract class AbstractDataCollector implements IDataCollector, \JsonSerializable {
  36. /** @var array */
  37. protected $data = [];
  38. /**
  39. * @since 24.0.0
  40. */
  41. public function getName(): string {
  42. return static::class;
  43. }
  44. /**
  45. * Reset the state of the profiler. By default it only empties the
  46. * $this->data contents, but you can override this method to do
  47. * additional cleaning.
  48. * @since 24.0.0
  49. */
  50. public function reset(): void {
  51. $this->data = [];
  52. }
  53. /**
  54. * @since 24.0.0
  55. */
  56. public function __sleep(): array {
  57. return ['data'];
  58. }
  59. /**
  60. * @internal to prevent implementing \Serializable
  61. * @since 24.0.0
  62. */
  63. final protected function serialize() {
  64. }
  65. /**
  66. * @internal to prevent implementing \Serializable
  67. * @since 24.0.0
  68. */
  69. final protected function unserialize(string $data) {
  70. }
  71. /**
  72. * @since 24.0.0
  73. */
  74. #[\ReturnTypeWillChange]
  75. public function jsonSerialize() {
  76. return $this->data;
  77. }
  78. }