IBootContext.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Bootstrap;
  8. use OCP\AppFramework\IAppContainer;
  9. use OCP\IServerContainer;
  10. use Psr\Container\ContainerExceptionInterface;
  11. use Throwable;
  12. /**
  13. * @since 20.0.0
  14. */
  15. interface IBootContext {
  16. /**
  17. * Get hold of the app's container
  18. *
  19. * Useful to register and query app-specific services
  20. *
  21. * @return IAppContainer
  22. * @since 20.0.0
  23. */
  24. public function getAppContainer(): IAppContainer;
  25. /**
  26. * Get hold of the server DI container
  27. *
  28. * Useful to register and query system-wide services
  29. *
  30. * @return IServerContainer
  31. * @since 20.0.0
  32. */
  33. public function getServerContainer(): IServerContainer;
  34. /**
  35. * Invoke the given callable and inject all parameters based on their types
  36. * and names
  37. *
  38. * Note: when used with methods, make sure they are public or use \Closure::fromCallable
  39. * to wrap the private method call, e.g.
  40. * * `$context->injectFn([$obj, 'publicMethod'])`
  41. * * `$context->injectFn([$this, 'publicMethod'])`
  42. * * `$context->injectFn(\Closure::fromCallable([$this, 'privateMethod']))`
  43. *
  44. * Note: the app container will be queried
  45. *
  46. * @param callable $fn
  47. * @throws ContainerExceptionInterface if at least one of the parameter can't be resolved
  48. * @throws Throwable any error the function invocation might cause
  49. * @return mixed|null the return value of the invoked function, if any
  50. * @since 20.0.0
  51. */
  52. public function injectFn(callable $fn);
  53. }