Application.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\SystemTags\AppInfo;
  25. use OCA\Files\Event\LoadAdditionalScriptsEvent;
  26. use OCA\SystemTags\Activity\Listener;
  27. use OCA\SystemTags\Capabilities;
  28. use OCA\SystemTags\Search\TagSearchProvider;
  29. use OCP\AppFramework\App;
  30. use OCP\AppFramework\Bootstrap\IBootContext;
  31. use OCP\AppFramework\Bootstrap\IBootstrap;
  32. use OCP\AppFramework\Bootstrap\IRegistrationContext;
  33. use OCP\EventDispatcher\IEventDispatcher;
  34. use OCP\SystemTag\ManagerEvent;
  35. use OCP\SystemTag\MapperEvent;
  36. class Application extends App implements IBootstrap {
  37. public const APP_ID = 'systemtags';
  38. public function __construct() {
  39. parent::__construct(self::APP_ID);
  40. }
  41. public function register(IRegistrationContext $context): void {
  42. $context->registerSearchProvider(TagSearchProvider::class);
  43. $context->registerCapability(Capabilities::class);
  44. }
  45. public function boot(IBootContext $context): void {
  46. $context->injectFn(function (IEventDispatcher $dispatcher) use ($context) {
  47. /*
  48. * @todo move the OCP events and then move the registration to `register`
  49. */
  50. $dispatcher->addListener(
  51. LoadAdditionalScriptsEvent::class,
  52. function () {
  53. \OCP\Util::addScript('core', 'systemtags');
  54. \OCP\Util::addInitScript(self::APP_ID, 'init');
  55. }
  56. );
  57. $managerListener = function (ManagerEvent $event) use ($context) {
  58. /** @var \OCA\SystemTags\Activity\Listener $listener */
  59. $listener = $context->getServerContainer()->query(Listener::class);
  60. $listener->event($event);
  61. };
  62. $dispatcher->addListener(ManagerEvent::EVENT_CREATE, $managerListener);
  63. $dispatcher->addListener(ManagerEvent::EVENT_DELETE, $managerListener);
  64. $dispatcher->addListener(ManagerEvent::EVENT_UPDATE, $managerListener);
  65. $mapperListener = function (MapperEvent $event) use ($context) {
  66. /** @var \OCA\SystemTags\Activity\Listener $listener */
  67. $listener = $context->getServerContainer()->query(Listener::class);
  68. $listener->mapperEvent($event);
  69. };
  70. $dispatcher->addListener(MapperEvent::EVENT_ASSIGN, $mapperListener);
  71. $dispatcher->addListener(MapperEvent::EVENT_UNASSIGN, $mapperListener);
  72. });
  73. }
  74. }