Application.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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\Controller\Notifications;
  31. use OCA\Comments\EventHandler;
  32. use OCA\Comments\Listener\CommentsEntityEventListener;
  33. use OCA\Comments\Listener\LoadAdditionalScripts;
  34. use OCA\Comments\Listener\LoadSidebarScripts;
  35. use OCA\Comments\MaxAutoCompleteResultsInitialState;
  36. use OCA\Comments\Notification\Notifier;
  37. use OCA\Comments\Search\LegacyProvider;
  38. use OCA\Comments\Search\CommentsSearchProvider;
  39. use OCA\Files\Event\LoadAdditionalScriptsEvent;
  40. use OCA\Files\Event\LoadSidebar;
  41. use OCP\AppFramework\App;
  42. use OCP\AppFramework\Bootstrap\IBootContext;
  43. use OCP\AppFramework\Bootstrap\IBootstrap;
  44. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  45. use OCP\Comments\CommentsEntityEvent;
  46. use OCP\ISearch;
  47. use OCP\IServerContainer;
  48. use OCP\Comments\ICommentsManager;
  49. class Application extends App implements IBootstrap {
  50. public const APP_ID = 'comments';
  51. public function __construct(array $urlParams = []) {
  52. parent::__construct(self::APP_ID, $urlParams);
  53. }
  54. public function register(IRegistrationContext $context): void {
  55. $context->registerCapability(Capabilities::class);
  56. $context->registerServiceAlias('NotificationsController', Notifications::class);
  57. $context->registerEventListener(
  58. LoadAdditionalScriptsEvent::class,
  59. LoadAdditionalScripts::class
  60. );
  61. $context->registerEventListener(
  62. LoadSidebar::class,
  63. LoadSidebarScripts::class
  64. );
  65. $context->registerEventListener(
  66. CommentsEntityEvent::EVENT_ENTITY,
  67. CommentsEntityEventListener::class
  68. );
  69. $context->registerSearchProvider(CommentsSearchProvider::class);
  70. $context->registerInitialStateProvider(MaxAutoCompleteResultsInitialState::class);
  71. $context->registerNotifierService(Notifier::class);
  72. }
  73. public function boot(IBootContext $context): void {
  74. $context->injectFn(Closure::fromCallable([$this, 'registerCommentsEventHandler']));
  75. $context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
  76. }
  77. protected function registerCommentsEventHandler(IServerContainer $container): void {
  78. $container->get(ICommentsManager::class)->registerEventHandler(function (): EventHandler {
  79. return $this->getContainer()->get(EventHandler::class);
  80. });
  81. }
  82. }