Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-07-09 20:55:15 +0300
committerJulius Härtl <jus@bitgrid.net>2020-07-10 08:58:40 +0300
commit759d6799bc1758498008494f4074b372f5259729 (patch)
tree8c7d0572ad86f6a44ea37eb6d1dc0333422a1dfc /lib
parent81689d3fc14cefad8b9952c16f126441e595883a (diff)
Use IBootstrap for the app bootstrap
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php86
-rw-r--r--lib/Listeners/FilesLoadAdditionalScriptsListener.php69
-rw-r--r--lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php62
-rw-r--r--lib/Listeners/LoadViewerListener.php40
-rw-r--r--lib/Listeners/RegisterDirectEditorEventListener.php47
5 files changed, 235 insertions, 69 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 70876a593..10292e292 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -24,85 +24,33 @@ declare(strict_types=1);
namespace OCA\Text\AppInfo;
-use OCA\Text\DirectEditing\TextDirectEditor;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\Text\Listeners\FilesLoadAdditionalScriptsListener;
+use OCA\Text\Listeners\FilesSharingLoadAdditionalScriptsListener;
+use OCA\Text\Listeners\LoadViewerListener;
+use OCA\Text\Listeners\RegisterDirectEditorEventListener;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\DirectEditing\RegisterDirectEditorEvent;
-use OCP\EventDispatcher\IEventDispatcher;
-use OCP\IInitialStateService;
-
-class Application extends App {
-
+class Application extends App implements IBootstrap {
const APP_NAME = 'text';
- /** @var IInitialStateService */
- private $initialStateService;
- /**
- * @var \OCP\IUserSession
- */
- private $userSession;
- /**
- * @var \OCP\IConfig
- */
- private $config;
-
-
- /**
- * Application constructor.
- *
- * @param array $params
- * @throws \OCP\AppFramework\QueryException
- */
public function __construct(array $params = []) {
parent::__construct(self::APP_NAME, $params);
+ }
- $container = $this->getContainer();
- $server = $container->getServer();
- /** @var IEventDispatcher $eventDispatcher */
- $eventDispatcher = $server->query(IEventDispatcher::class);
- $this->initialStateService = $server->query(IInitialStateService::class);
- $this->userSession = $server->getUserSession();
- $this->config = $this->getContainer()->getServer()->getConfig();
-
- $eventDispatcher->addListener(RegisterDirectEditorEvent::class, function (RegisterDirectEditorEvent $event) use ($container) {
- $editor = $container->query(TextDirectEditor::class);
- $event->register($editor);
- });
-
- $eventDispatcher->addListener(LoadViewer::class, function () {
- \OCP\Util::addScript('text', 'viewer');
- \OCP\Util::addStyle('text', 'icons');
- });
-
- if ($this->userSession->isLoggedIn()) {
- $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () {
- \OCP\Util::addScript('text', 'files');
- \OCP\Util::addStyle('text', 'icons');
-
- $this->initialStateService->provideInitialState(
- self::APP_NAME,
- 'workspace_available',
- $this->config->getAppValue(self::APP_NAME, 'workspace_available', '1') === '1'
- );
- $this->initialStateService->provideInitialState(
- self::APP_NAME,
- 'workspace_enabled',
- $this->config->getUserValue($this->userSession->getUser()->getUID(), self::APP_NAME, 'workspace_enabled', '1') === '1'
- );
- });
- }
-
- $eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () {
- \OCP\Util::addScript('text', 'public');
- \OCP\Util::addStyle('text', 'icons');
- $this->initialStateService->provideInitialState(
- self::APP_NAME,
- 'workspace_available',
- $this->config->getAppValue(self::APP_NAME, 'workspace_available', '1') === '1'
- );
- });
+ public function register(IRegistrationContext $context): void {
+ $context->registerEventListener(RegisterDirectEditorEvent::class, RegisterDirectEditorEventListener::class);
+ $context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
+ $context->registerEventListener('OCA\Files_Sharing::loadAdditionalScripts', FilesSharingLoadAdditionalScriptsListener::class);
+ $context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class);
}
+ public function boot(IBootContext $context): void {
+ }
}
diff --git a/lib/Listeners/FilesLoadAdditionalScriptsListener.php b/lib/Listeners/FilesLoadAdditionalScriptsListener.php
new file mode 100644
index 000000000..c49c6f88e
--- /dev/null
+++ b/lib/Listeners/FilesLoadAdditionalScriptsListener.php
@@ -0,0 +1,69 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Text\Listeners;
+
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\Text\AppInfo\Application;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\IConfig;
+use OCP\IInitialStateService;
+use OCP\IUserSession;
+
+class FilesLoadAdditionalScriptsListener implements IEventListener {
+ /** @var IConfig */
+ protected $config;
+ /** @var IInitialStateService */
+ protected $initialStateService;
+ /** @var IUserSession */
+ protected $userSession;
+
+ public function __construct(IConfig $config, IInitialStateService $initialStateService, IUserSession $userSession) {
+ $this->config = $config;
+ $this->initialStateService = $initialStateService;
+ $this->userSession = $userSession;
+ }
+
+ public function handle(Event $event): void {
+ if (!$event instanceof LoadAdditionalScriptsEvent) {
+ return;
+ }
+
+ \OCP\Util::addScript('text', 'files');
+ \OCP\Util::addStyle('text', 'icons');
+
+ $this->initialStateService->provideInitialState(
+ Application::APP_NAME,
+ 'workspace_available',
+ $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1'
+ );
+ $this->initialStateService->provideInitialState(
+ Application::APP_NAME,
+ 'workspace_enabled',
+ $this->config->getUserValue($this->userSession->getUser()->getUID(), Application::APP_NAME, 'workspace_enabled', '1') === '1'
+ );
+ }
+}
diff --git a/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php
new file mode 100644
index 000000000..bf097ddb4
--- /dev/null
+++ b/lib/Listeners/FilesSharingLoadAdditionalScriptsListener.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Text\Listeners;
+
+use OCA\Text\AppInfo\Application;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\IConfig;
+use OCP\IInitialStateService;
+use OCP\IUserSession;
+
+class FilesSharingLoadAdditionalScriptsListener implements IEventListener {
+ /** @var IConfig */
+ protected $config;
+ /** @var IInitialStateService */
+ protected $initialStateService;
+ /** @var IUserSession */
+ protected $userSession;
+
+ public function __construct(IConfig $config, IInitialStateService $initialStateService, IUserSession $userSession) {
+ $this->config = $config;
+ $this->initialStateService = $initialStateService;
+ $this->userSession = $userSession;
+ }
+
+ public function handle(Event $event): void {
+ if (!$this->userSession->isLoggedIn()) {
+ return;
+ }
+ \OCP\Util::addScript('text', 'public');
+ \OCP\Util::addStyle('text', 'icons');
+
+ $this->initialStateService->provideInitialState(
+ Application::APP_NAME,
+ 'workspace_available',
+ $this->config->getAppValue(Application::APP_NAME, 'workspace_available', '1') === '1'
+ );
+ }
+}
diff --git a/lib/Listeners/LoadViewerListener.php b/lib/Listeners/LoadViewerListener.php
new file mode 100644
index 000000000..291384afd
--- /dev/null
+++ b/lib/Listeners/LoadViewerListener.php
@@ -0,0 +1,40 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Text\Listeners;
+
+use OCA\Viewer\Event\LoadViewer;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+class LoadViewerListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!$event instanceof LoadViewer) {
+ return;
+ }
+ \OCP\Util::addScript('text', 'viewer');
+ \OCP\Util::addStyle('text', 'icons');
+ }
+}
diff --git a/lib/Listeners/RegisterDirectEditorEventListener.php b/lib/Listeners/RegisterDirectEditorEventListener.php
new file mode 100644
index 000000000..77770d991
--- /dev/null
+++ b/lib/Listeners/RegisterDirectEditorEventListener.php
@@ -0,0 +1,47 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020 Morris Jobke <hey@morrisjobke.de>
+ *
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Text\Listeners;
+
+use OCA\Text\DirectEditing\TextDirectEditor;
+use OCP\DirectEditing\RegisterDirectEditorEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+class RegisterDirectEditorEventListener implements IEventListener {
+ /** @var TextDirectEditor */
+ protected $editor;
+
+ public function __construct(TextDirectEditor $editor) {
+ $this->editor = $editor;
+ }
+
+ public function handle(Event $event): void {
+ if (!$event instanceof RegisterDirectEditorEvent) {
+ return;
+ }
+ $event->register($this->editor);
+ }
+}