Application.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\Comments\AppInfo;
  28. use Closure;
  29. use OCA\Comments\Capabilities;
  30. use OCA\Comments\EventHandler;
  31. use OCA\Comments\Listener\CommentsEntityEventListener;
  32. use OCA\Comments\Listener\LoadAdditionalScripts;
  33. use OCA\Comments\Listener\LoadSidebarScripts;
  34. use OCA\Comments\MaxAutoCompleteResultsInitialState;
  35. use OCA\Comments\Notification\Notifier;
  36. use OCA\Comments\Search\CommentsSearchProvider;
  37. use OCA\Comments\Search\LegacyProvider;
  38. use OCA\Files\Event\LoadAdditionalScriptsEvent;
  39. use OCA\Files\Event\LoadSidebar;
  40. use OCP\AppFramework\App;
  41. use OCP\AppFramework\Bootstrap\IBootContext;
  42. use OCP\AppFramework\Bootstrap\IBootstrap;
  43. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  44. use OCP\Comments\CommentsEntityEvent;
  45. use OCP\Comments\ICommentsManager;
  46. use OCP\ISearch;
  47. use OCP\IServerContainer;
  48. class Application extends App implements IBootstrap {
  49. public const APP_ID = 'comments';
  50. public function __construct(array $urlParams = []) {
  51. parent::__construct(self::APP_ID, $urlParams);
  52. }
  53. public function register(IRegistrationContext $context): void {
  54. $context->registerCapability(Capabilities::class);
  55. $context->registerEventListener(
  56. LoadAdditionalScriptsEvent::class,
  57. LoadAdditionalScripts::class
  58. );
  59. $context->registerEventListener(
  60. LoadSidebar::class,
  61. LoadSidebarScripts::class
  62. );
  63. $context->registerEventListener(
  64. CommentsEntityEvent::class,
  65. CommentsEntityEventListener::class
  66. );
  67. $context->registerSearchProvider(CommentsSearchProvider::class);
  68. $context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class);
  69. $context->registerNotifierService(Notifier::class);
  70. }
  71. public function boot(IBootContext $context): void {
  72. $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
  73. $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
  74. }
  75. protected function registerCommentsEventHandler(IServerContainer $container): void {
  76. $container->get(ICommentsManager::class)->registerEventHandler(function (): EventHandler {
  77. return $this->getContainer()->get(EventHandler::class);
  78. });
  79. }
  80. }