1
0

Application.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud GmbH
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Testing\AppInfo;
  8. use OCA\Testing\AlternativeHomeUserBackend;
  9. use OCA\Testing\Listener\GetDeclarativeSettingsValueListener;
  10. use OCA\Testing\Listener\RegisterDeclarativeSettingsListener;
  11. use OCA\Testing\Listener\SetDeclarativeSettingsValueListener;
  12. use OCA\Testing\Provider\FakeText2ImageProvider;
  13. use OCA\Testing\Provider\FakeTextProcessingProvider;
  14. use OCA\Testing\Provider\FakeTextProcessingProviderSync;
  15. use OCA\Testing\Provider\FakeTranslationProvider;
  16. use OCA\Testing\Settings\DeclarativeSettingsForm;
  17. use OCP\AppFramework\App;
  18. use OCP\AppFramework\Bootstrap\IBootContext;
  19. use OCP\AppFramework\Bootstrap\IBootstrap;
  20. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  21. use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
  22. use OCP\Settings\Events\DeclarativeSettingsRegisterFormEvent;
  23. use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
  24. class Application extends App implements IBootstrap {
  25. public function __construct(array $urlParams = []) {
  26. parent::__construct('testing', $urlParams);
  27. }
  28. public function register(IRegistrationContext $context): void {
  29. $context->registerTranslationProvider(FakeTranslationProvider::class);
  30. $context->registerTextProcessingProvider(FakeTextProcessingProvider::class);
  31. $context->registerTextProcessingProvider(FakeTextProcessingProviderSync::class);
  32. $context->registerTextToImageProvider(FakeText2ImageProvider::class);
  33. $context->registerDeclarativeSettings(DeclarativeSettingsForm::class);
  34. $context->registerEventListener(DeclarativeSettingsRegisterFormEvent::class, RegisterDeclarativeSettingsListener::class);
  35. $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, GetDeclarativeSettingsValueListener::class);
  36. $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, SetDeclarativeSettingsValueListener::class);
  37. }
  38. public function boot(IBootContext $context): void {
  39. $server = $context->getServerContainer();
  40. $config = $server->getConfig();
  41. if ($config->getAppValue('testing', 'enable_alt_user_backend', 'no') === 'yes') {
  42. $userManager = $server->getUserManager();
  43. // replace all user backends with this one
  44. $userManager->clearBackends();
  45. $userManager->registerBackend($context->getAppContainer()->get(AlternativeHomeUserBackend::class));
  46. }
  47. }
  48. }