Application.php 3.1 KB

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