1
0

Application.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 OCA\Testing\TaskProcessing\FakeContextWriteProvider;
  18. use OCA\Testing\TaskProcessing\FakeTextToImageProvider;
  19. use OCA\Testing\TaskProcessing\FakeTextToTextProvider;
  20. use OCA\Testing\TaskProcessing\FakeTextToTextSummaryProvider;
  21. use OCA\Testing\TaskProcessing\FakeTranscribeProvider;
  22. use OCA\Testing\TaskProcessing\FakeTranslateProvider;
  23. use OCP\AppFramework\App;
  24. use OCP\AppFramework\Bootstrap\IBootContext;
  25. use OCP\AppFramework\Bootstrap\IBootstrap;
  26. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  27. use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
  28. use OCP\Settings\Events\DeclarativeSettingsRegisterFormEvent;
  29. use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
  30. class Application extends App implements IBootstrap {
  31. public const APP_ID = 'testing';
  32. public function __construct(array $urlParams = []) {
  33. parent::__construct(self::APP_ID, $urlParams);
  34. }
  35. public function register(IRegistrationContext $context): void {
  36. $context->registerTranslationProvider(FakeTranslationProvider::class);
  37. $context->registerTextProcessingProvider(FakeTextProcessingProvider::class);
  38. $context->registerTextProcessingProvider(FakeTextProcessingProviderSync::class);
  39. $context->registerTextToImageProvider(FakeText2ImageProvider::class);
  40. $context->registerTaskProcessingProvider(FakeTextToTextProvider::class);
  41. $context->registerTaskProcessingProvider(FakeTextToTextSummaryProvider::class);
  42. $context->registerTaskProcessingProvider(FakeTextToImageProvider::class);
  43. $context->registerTaskProcessingProvider(FakeTranslateProvider::class);
  44. $context->registerTaskProcessingProvider(FakeTranscribeProvider::class);
  45. $context->registerTaskProcessingProvider(FakeContextWriteProvider::class);
  46. $context->registerDeclarativeSettings(DeclarativeSettingsForm::class);
  47. $context->registerEventListener(DeclarativeSettingsRegisterFormEvent::class, RegisterDeclarativeSettingsListener::class);
  48. $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, GetDeclarativeSettingsValueListener::class);
  49. $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, SetDeclarativeSettingsValueListener::class);
  50. }
  51. public function boot(IBootContext $context): void {
  52. $server = $context->getServerContainer();
  53. $config = $server->getConfig();
  54. if ($config->getAppValue(self::APP_ID, 'enable_alt_user_backend', 'no') === 'yes') {
  55. $userManager = $server->getUserManager();
  56. // replace all user backends with this one
  57. $userManager->clearBackends();
  58. $userManager->registerBackend($context->getAppContainer()->get(AlternativeHomeUserBackend::class));
  59. }
  60. }
  61. }