Skip to content

Commit 7f8d6b6

Browse files
committed
Add real events to load additionalscripts
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
1 parent 3772031 commit 7f8d6b6

File tree

6 files changed

+87
-5
lines changed

6 files changed

+87
-5
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
'OCP\\AppFramework\\Http\\DownloadResponse' => $baseDir . '/lib/public/AppFramework/Http/DownloadResponse.php',
4242
'OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy' => $baseDir . '/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php',
4343
'OCP\\AppFramework\\Http\\EmptyFeaturePolicy' => $baseDir . '/lib/public/AppFramework/Http/EmptyFeaturePolicy.php',
44+
'OCP\\AppFramework\\Http\\Events\\LoadAdditionalScriptsEvent' => $baseDir . '/lib/public/AppFramework/Http/Events/LoadAdditionalScriptsEvent.php',
45+
'OCP\\AppFramework\\Http\\Events\\LoadAdditionalScriptsLoggedInEvent' => $baseDir . '/lib/public/AppFramework/Http/Events/LoadAdditionalScriptsLoggedInEvent.php',
4446
'OCP\\AppFramework\\Http\\FeaturePolicy' => $baseDir . '/lib/public/AppFramework/Http/FeaturePolicy.php',
4547
'OCP\\AppFramework\\Http\\FileDisplayResponse' => $baseDir . '/lib/public/AppFramework/Http/FileDisplayResponse.php',
4648
'OCP\\AppFramework\\Http\\ICallbackResponse' => $baseDir . '/lib/public/AppFramework/Http/ICallbackResponse.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
7070
'OCP\\AppFramework\\Http\\DownloadResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/DownloadResponse.php',
7171
'OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php',
7272
'OCP\\AppFramework\\Http\\EmptyFeaturePolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/EmptyFeaturePolicy.php',
73+
'OCP\\AppFramework\\Http\\Events\\LoadAdditionalScriptsEvent' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Events/LoadAdditionalScriptsEvent.php',
74+
'OCP\\AppFramework\\Http\\Events\\LoadAdditionalScriptsLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/Events/LoadAdditionalScriptsLoggedInEvent.php',
7375
'OCP\\AppFramework\\Http\\FeaturePolicy' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/FeaturePolicy.php',
7476
'OCP\\AppFramework\\Http\\FileDisplayResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/FileDisplayResponse.php',
7577
'OCP\\AppFramework\\Http\\ICallbackResponse' => __DIR__ . '/../../..' . '/lib/public/AppFramework/Http/ICallbackResponse.php',

lib/private/AppFramework/Middleware/AdditionalScriptsMiddleware.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,30 @@
2727

2828
namespace OC\AppFramework\Middleware;
2929

30+
use OCP\AppFramework\Http\Events\LoadAdditionalScriptsEvent;
31+
use OCP\AppFramework\Http\Events\LoadAdditionalScriptsLoggedInEvent;
3032
use OCP\AppFramework\Http\Response;
3133
use OCP\AppFramework\Http\StandaloneTemplateResponse;
3234
use OCP\AppFramework\Http\TemplateResponse;
3335
use OCP\AppFramework\Middleware;
3436
use OCP\AppFramework\PublicShareController;
3537
use OCP\EventDispatcher\GenericEvent;
38+
use OCP\EventDispatcher\IEventDispatcher;
3639
use OCP\IUserSession;
3740
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
3841

3942
class AdditionalScriptsMiddleware extends Middleware {
4043
/** @var EventDispatcherInterface */
41-
private $dispatcher;
44+
private $legacyDispatcher;
4245
/** @var IUserSession */
4346
private $userSession;
47+
/** @var IEventDispatcher */
48+
private $dispatcher;
4449

45-
public function __construct(EventDispatcherInterface $dispatcher, IUserSession $userSession) {
46-
$this->dispatcher = $dispatcher;
50+
public function __construct(EventDispatcherInterface $legacyDispatcher, IUserSession $userSession, IEventDispatcher $dispatcher) {
51+
$this->legacyDispatcher = $legacyDispatcher;
4752
$this->userSession = $userSession;
53+
$this->dispatcher = $dispatcher;
4854
}
4955

5056
public function afterController($controller, $methodName, Response $response): Response {
@@ -57,10 +63,12 @@ public function afterController($controller, $methodName, Response $response): R
5763
}
5864

5965
if ($response instanceof TemplateResponse) {
60-
$this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent());
66+
$this->dispatcher->dispatchTyped(new LoadAdditionalScriptsEvent());
67+
$this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS, new GenericEvent());
6168

6269
if (!($response instanceof StandaloneTemplateResponse) && $this->userSession->isLoggedIn()) {
63-
$this->dispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent());
70+
$this->dispatcher->dispatchTyped(new LoadAdditionalScriptsLoggedInEvent());
71+
$this->legacyDispatcher->dispatch(TemplateResponse::EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN, new GenericEvent());
6472
}
6573
}
6674

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
6+
*
7+
* @author Roeland Jago Douma <roeland@famdouma.nl>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OCP\AppFramework\Http\Events;
27+
28+
use OCP\EventDispatcher\Event;
29+
30+
class LoadAdditionalScriptsEvent extends Event {
31+
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
6+
*
7+
* @author Roeland Jago Douma <roeland@famdouma.nl>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
namespace OCP\AppFramework\Http\Events;
27+
28+
use OCP\EventDispatcher\Event;
29+
30+
class LoadAdditionalScriptsLoggedInEvent extends Event {
31+
32+
}

lib/public/AppFramework/Http/TemplateResponse.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@
3838
* @since 6.0.0
3939
*/
4040
class TemplateResponse extends Response {
41+
/**
42+
* @deprecated 20.0.0 use OCP\AppFramework\Http\Events\LoadAdditionalScriptsEvent
43+
*/
4144
public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts';
45+
/**
46+
* @deprecated 20.0.0 use OCP\AppFramework\Http\Events\LoadAdditionalScriptsLoggedInEvent
47+
*/
4248
public const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn';
4349

4450
/**

0 commit comments

Comments
 (0)