aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDaniel Kesselberg <mail@danielkesselberg.de>2023-05-21 23:05:40 +0200
committerDaniel Kesselberg <mail@danielkesselberg.de>2023-06-03 21:42:51 +0200
commita2afc7b6a9b42598cadcc3d3e9dde80e0a8a9ce4 (patch)
tree214512080370ac8ce227ab60a6f331163db045da /lib
parent2fd7febffd0ade3f33c8833126c2b8eceabc5d14 (diff)
downloadnextcloud-server-a2afc7b6a9b42598cadcc3d3e9dde80e0a8a9ce4.tar.gz
nextcloud-server-a2afc7b6a9b42598cadcc3d3e9dde80e0a8a9ce4.zip
refactor: migrate OC_EventSource to dependency injection
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/private/EventSourceFactory.php46
-rw-r--r--lib/private/Server.php13
-rw-r--r--lib/private/legacy/OC_EventSource.php13
-rw-r--r--lib/public/IEventSourceFactory.php38
-rw-r--r--lib/public/IServerContainer.php9
7 files changed, 102 insertions, 21 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index f35b9c94fbc..9f9ff8f60f3 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -453,6 +453,7 @@ return array(
'OCP\\IDateTimeZone' => $baseDir . '/lib/public/IDateTimeZone.php',
'OCP\\IEmojiHelper' => $baseDir . '/lib/public/IEmojiHelper.php',
'OCP\\IEventSource' => $baseDir . '/lib/public/IEventSource.php',
+ 'OCP\\IEventSourceFactory' => $baseDir . '/lib/public/IEventSourceFactory.php',
'OCP\\IGroup' => $baseDir . '/lib/public/IGroup.php',
'OCP\\IGroupManager' => $baseDir . '/lib/public/IGroupManager.php',
'OCP\\IImage' => $baseDir . '/lib/public/IImage.php',
@@ -1196,6 +1197,7 @@ return array(
'OC\\EventDispatcher\\GenericEventWrapper' => $baseDir . '/lib/private/EventDispatcher/GenericEventWrapper.php',
'OC\\EventDispatcher\\ServiceEventListener' => $baseDir . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventDispatcher\\SymfonyAdapter' => $baseDir . '/lib/private/EventDispatcher/SymfonyAdapter.php',
+ 'OC\\EventSourceFactory' => $baseDir . '/lib/private/EventSourceFactory.php',
'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php',
'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php',
'OC\\Federation\\CloudFederationProviderManager' => $baseDir . '/lib/private/Federation/CloudFederationProviderManager.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 8de7ef99d02..546fa72c325 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -486,6 +486,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\IDateTimeZone' => __DIR__ . '/../../..' . '/lib/public/IDateTimeZone.php',
'OCP\\IEmojiHelper' => __DIR__ . '/../../..' . '/lib/public/IEmojiHelper.php',
'OCP\\IEventSource' => __DIR__ . '/../../..' . '/lib/public/IEventSource.php',
+ 'OCP\\IEventSourceFactory' => __DIR__ . '/../../..' . '/lib/public/IEventSourceFactory.php',
'OCP\\IGroup' => __DIR__ . '/../../..' . '/lib/public/IGroup.php',
'OCP\\IGroupManager' => __DIR__ . '/../../..' . '/lib/public/IGroupManager.php',
'OCP\\IImage' => __DIR__ . '/../../..' . '/lib/public/IImage.php',
@@ -1229,6 +1230,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\EventDispatcher\\GenericEventWrapper' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/GenericEventWrapper.php',
'OC\\EventDispatcher\\ServiceEventListener' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventDispatcher\\SymfonyAdapter' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/SymfonyAdapter.php',
+ 'OC\\EventSourceFactory' => __DIR__ . '/../../..' . '/lib/private/EventSourceFactory.php',
'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php',
'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php',
'OC\\Federation\\CloudFederationProviderManager' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationProviderManager.php',
diff --git a/lib/private/EventSourceFactory.php b/lib/private/EventSourceFactory.php
new file mode 100644
index 00000000000..197c8bf9e6c
--- /dev/null
+++ b/lib/private/EventSourceFactory.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de>
+ *
+ * @author Daniel Kesselberg <mail@danielkesselberg.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC;
+
+use OCP\IEventSource;
+use OCP\IEventSourceFactory;
+use OCP\IRequest;
+
+class EventSourceFactory implements IEventSourceFactory {
+ private IRequest $request;
+
+
+ public function __construct(IRequest $request) {
+ $this->request = $request;
+ }
+
+ /**
+ * Create a new event source
+ *
+ * @return IEventSource
+ * @since 28.0.0
+ */
+ public function create(): IEventSource {
+ return new \OC_EventSource($this->request);
+ }
+}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index 84860f8c494..f98ee051a32 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -211,6 +211,7 @@ use OCP\IBinaryFinder;
use OCP\IDateTimeFormatter;
use OCP\IDateTimeZone;
use OCP\IDBConnection;
+use OCP\IEventSourceFactory;
use OCP\IGroupManager;
use OCP\IInitialStateService;
use OCP\IL10N;
@@ -1467,6 +1468,8 @@ class Server extends ServerContainer implements IServerContainer {
$this->registerAlias(ISpeechToTextManager::class, SpeechToTextManager::class);
+ $this->registerAlias(IEventSourceFactory::class, EventSourceFactory::class);
+
$this->connectDispatcher();
}
@@ -1929,16 +1932,6 @@ class Server extends ServerContainer implements IServerContainer {
}
/**
- * Create a new event source
- *
- * @return \OCP\IEventSource
- * @deprecated 20.0.0
- */
- public function createEventSource() {
- return new \OC_EventSource();
- }
-
- /**
* Get the active event logger
*
* The returned logger only logs data when debug mode is enabled
diff --git a/lib/private/legacy/OC_EventSource.php b/lib/private/legacy/OC_EventSource.php
index c733316050f..cd72ba1f2d5 100644
--- a/lib/private/legacy/OC_EventSource.php
+++ b/lib/private/legacy/OC_EventSource.php
@@ -1,4 +1,7 @@
<?php
+
+use OCP\IRequest;
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -42,6 +45,12 @@ class OC_EventSource implements \OCP\IEventSource {
*/
private $started = false;
+ private IRequest $request;
+
+ public function __construct(IRequest $request) {
+ $this->request = $request;
+ }
+
protected function init() {
if ($this->started) {
return;
@@ -71,11 +80,11 @@ class OC_EventSource implements \OCP\IEventSource {
} else {
header("Content-Type: text/event-stream");
}
- if (!\OC::$server->getRequest()->passesStrictCookieCheck()) {
+ if (!$this->request->passesStrictCookieCheck()) {
header('Location: '.\OC::$WEBROOT);
exit();
}
- if (!\OC::$server->getRequest()->passesCSRFCheck()) {
+ if (!$this->request->passesCSRFCheck()) {
$this->send('error', 'Possible CSRF attack. Connection will be closed.');
$this->close();
exit();
diff --git a/lib/public/IEventSourceFactory.php b/lib/public/IEventSourceFactory.php
new file mode 100644
index 00000000000..5876189cebb
--- /dev/null
+++ b/lib/public/IEventSourceFactory.php
@@ -0,0 +1,38 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de>
+ *
+ * @author Daniel Kesselberg <mail@danielkesselberg.de>
+ *
+ * @license AGPL-3.0-or-later
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OCP;
+
+/**
+ * @since 28.0.0
+ */
+interface IEventSourceFactory {
+ /**
+ * Create a new event source
+ *
+ * @return IEventSource
+ * @since 28.0.0
+ */
+ public function create(): IEventSource;
+}
diff --git a/lib/public/IServerContainer.php b/lib/public/IServerContainer.php
index c69dab8b3c6..f438838b98e 100644
--- a/lib/public/IServerContainer.php
+++ b/lib/public/IServerContainer.php
@@ -396,15 +396,6 @@ interface IServerContainer extends ContainerInterface, IContainer {
public function getCertificateManager();
/**
- * Create a new event source
- *
- * @return \OCP\IEventSource
- * @since 8.0.0
- * @deprecated 20.0.0 have it injected or fetch it through \Psr\Container\ContainerInterface::get
- */
- public function createEventSource();
-
- /**
* Returns an instance of the HTTP client service
*
* @return \OCP\Http\Client\IClientService