IInitialState.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\AppFramework\Services;
  8. use Closure;
  9. /**
  10. * @since 20.0.0
  11. */
  12. interface IInitialState {
  13. /**
  14. * Allows an app to provide its initial state to the template system.
  15. * Use this if you know your initial state sill be used for example if
  16. * you are in the render function of you controller.
  17. *
  18. * @since 20.0.0
  19. *
  20. * @param string $key
  21. * @param bool|int|float|string|array|\JsonSerializable $data
  22. */
  23. public function provideInitialState(string $key, $data): void;
  24. /**
  25. * Allows an app to provide its initial state via a lazy method.
  26. * This will call the closure when the template is being generated.
  27. * Use this if your app is injected into pages. Since then the render method
  28. * is not called explicitly. But we do not want to load the state on webdav
  29. * requests for example.
  30. *
  31. * @since 20.0.0
  32. *
  33. * @param string $key
  34. * @param Closure $closure returns a primitive or an object that implements JsonSerializable
  35. * @psalm-param Closure():bool|Closure():int|Closure():float|Closure():string|Closure():\JsonSerializable $closure
  36. */
  37. public function provideLazyInitialState(string $key, Closure $closure): void;
  38. }