This adds a new event that is in the new style of event dispatching.
This should allow more lazy loading and better sepeartion of concerns
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
'OCA\\Files\\Controller\\AjaxController' => $baseDir . '/../lib/Controller/AjaxController.php',
'OCA\\Files\\Controller\\ApiController' => $baseDir . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ViewController' => $baseDir . '/../lib/Controller/ViewController.php',
+ 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => $baseDir . '/../lib/Event/LoadAdditionalScriptsEvent.php',
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
+ 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Service\\TagService' => $baseDir . '/../lib/Service/TagService.php',
);
'OCA\\Files\\Controller\\AjaxController' => __DIR__ . '/..' . '/../lib/Controller/AjaxController.php',
'OCA\\Files\\Controller\\ApiController' => __DIR__ . '/..' . '/../lib/Controller/ApiController.php',
'OCA\\Files\\Controller\\ViewController' => __DIR__ . '/..' . '/../lib/Controller/ViewController.php',
+ 'OCA\\Files\\Event\\LoadAdditionalScriptsEvent' => __DIR__ . '/..' . '/../lib/Event/LoadAdditionalScriptsEvent.php',
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
+ 'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Service\\TagService' => __DIR__ . '/..' . '/../lib/Service/TagService.php',
);
use OCA\Files\Collaboration\Resources\Listener;
use OCA\Files\Collaboration\Resources\ResourceProvider;
use OCA\Files\Controller\ApiController;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
use OCP\AppFramework\App;
use \OCA\Files\Service\TagService;
use OCP\Collaboration\Resources\IManager;
+use OCP\EventDispatcher\IEventDispatcher;
use \OCP\IContainer;
use OCA\Files\Controller\ViewController;
use OCA\Files\Capabilities;
$resourceManager = $container->query(IManager::class);
$resourceManager->registerResourceProvider(ResourceProvider::class);
Listener::register($server->getEventDispatcher());
+
+ /** @var IEventDispatcher $dispatcher */
+ $dispatcher = $container->query(IEventDispatcher::class);
+ $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LegacyLoadAdditionalScriptsAdapter::class);
}
}
namespace OCA\Files\Controller;
use OCA\Files\Activity\Helper;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
-use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\App\IAppManager;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class ViewController
protected $l10n;
/** @var IConfig */
protected $config;
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
protected $eventDispatcher;
/** @var IUserSession */
protected $userSession;
IURLGenerator $urlGenerator,
IL10N $l10n,
IConfig $config,
- EventDispatcherInterface $eventDispatcherInterface,
+ IEventDispatcher $eventDispatcher,
IUserSession $userSession,
IAppManager $appManager,
IRootFolder $rootFolder,
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
$this->config = $config;
- $this->eventDispatcher = $eventDispatcherInterface;
+ $this->eventDispatcher = $eventDispatcher;
$this->userSession = $userSession;
$this->appManager = $appManager;
$this->rootFolder = $rootFolder;
];
}
- $event = new GenericEvent(null, ['hiddenFields' => []]);
- $this->eventDispatcher->dispatch('OCA\Files::loadAdditionalScripts', $event);
+ $event = new LoadAdditionalScriptsEvent();
+ $this->eventDispatcher->dispatch(LoadAdditionalScriptsEvent::class, $event);
$params = [];
$params['usedSpacePercent'] = (int) $storageInfo['relative'];
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
$params['appNavigation'] = $nav;
$params['appContents'] = $contentItems;
- $params['hiddenFields'] = $event->getArgument('hiddenFields');
+ $params['hiddenFields'] = $event->getHiddenFields();
$response = new TemplateResponse(
$this->appName,
--- /dev/null
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Files\Event;
+
+use OCP\EventDispatcher\Event;
+
+class LoadAdditionalScriptsEvent extends Event {
+
+ private $hiddenFields = [];
+
+ public function addHiddenField(string $name, string $value): void {
+ $this->hiddenFields[$name] = $value;
+ }
+
+ public function getHiddenFields(): array {
+ return $this->hiddenFields;
+ }
+}
--- /dev/null
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @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\Files\Listener;
+
+use OC\EventDispatcher\SymfonyAdapter;
+use OCA\Files\Event\LoadAdditionalScriptsEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use Symfony\Component\EventDispatcher\GenericEvent;
+
+class LegacyLoadAdditionalScriptsAdapter implements IEventListener {
+
+ /** @var SymfonyAdapter */
+ private $dispatcher;
+
+ public function __construct(SymfonyAdapter $dispatcher) {
+ $this->dispatcher = $dispatcher;
+ }
+
+ public function handle(Event $event): void {
+ if (!($event instanceof LoadAdditionalScriptsEvent)) {
+ return;
+ }
+
+ $legacyEvent = new GenericEvent(null, ['hiddenFields' => []]);
+ $this->dispatcher->dispatch('OCA\Files::loadAdditionalScripts', $legacyEvent);
+
+ $hiddenFields = $legacyEvent->getArgument('hiddenFields');
+ foreach ($hiddenFields as $name => $value) {
+ $event->addHiddenField($name, $value);
+ }
+ }
+
+}
use OCA\Files\Activity\Helper;
use OCA\Files\Controller\ViewController;
use OCP\AppFramework\Http;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
$this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
- $this->eventDispatcher = $this->getMockBuilder('\Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
+ $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->userSession = $this->getMockBuilder(IUserSession::class)->getMock();
$this->appManager = $this->getMockBuilder('\OCP\App\IAppManager')->getMock();
$this->user = $this->getMockBuilder(IUser::class)->getMock();