Skip to content

Commit 9b0e483

Browse files
authored
Merge pull request #45375 from nextcloud/fix/move-eventsource-to-oc
Move EventSource to `OC` namespace
2 parents 54afea4 + d7ed056 commit 9b0e483

5 files changed

Lines changed: 25 additions & 34 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,7 @@
13821382
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
13831383
'OC\\EventDispatcher\\EventDispatcher' => $baseDir . '/lib/private/EventDispatcher/EventDispatcher.php',
13841384
'OC\\EventDispatcher\\ServiceEventListener' => $baseDir . '/lib/private/EventDispatcher/ServiceEventListener.php',
1385+
'OC\\EventSource' => $baseDir . '/lib/private/EventSource.php',
13851386
'OC\\EventSourceFactory' => $baseDir . '/lib/private/EventSourceFactory.php',
13861387
'OC\\Federation\\CloudFederationFactory' => $baseDir . '/lib/private/Federation/CloudFederationFactory.php',
13871388
'OC\\Federation\\CloudFederationNotification' => $baseDir . '/lib/private/Federation/CloudFederationNotification.php',
@@ -1905,7 +1906,6 @@
19051906
'OC_API' => $baseDir . '/lib/private/legacy/OC_API.php',
19061907
'OC_App' => $baseDir . '/lib/private/legacy/OC_App.php',
19071908
'OC_Defaults' => $baseDir . '/lib/private/legacy/OC_Defaults.php',
1908-
'OC_EventSource' => $baseDir . '/lib/private/legacy/OC_EventSource.php',
19091909
'OC_FileChunking' => $baseDir . '/lib/private/legacy/OC_FileChunking.php',
19101910
'OC_Files' => $baseDir . '/lib/private/legacy/OC_Files.php',
19111911
'OC_Helper' => $baseDir . '/lib/private/legacy/OC_Helper.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
14231423
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
14241424
'OC\\EventDispatcher\\EventDispatcher' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/EventDispatcher.php',
14251425
'OC\\EventDispatcher\\ServiceEventListener' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/ServiceEventListener.php',
1426+
'OC\\EventSource' => __DIR__ . '/../../..' . '/lib/private/EventSource.php',
14261427
'OC\\EventSourceFactory' => __DIR__ . '/../../..' . '/lib/private/EventSourceFactory.php',
14271428
'OC\\Federation\\CloudFederationFactory' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationFactory.php',
14281429
'OC\\Federation\\CloudFederationNotification' => __DIR__ . '/../../..' . '/lib/private/Federation/CloudFederationNotification.php',
@@ -1946,7 +1947,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
19461947
'OC_API' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_API.php',
19471948
'OC_App' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_App.php',
19481949
'OC_Defaults' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Defaults.php',
1949-
'OC_EventSource' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_EventSource.php',
19501950
'OC_FileChunking' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_FileChunking.php',
19511951
'OC_Files' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Files.php',
19521952
'OC_Helper' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Helper.php',
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use OCP\IRequest;
3+
declare(strict_types=1);
44

55
/**
66
* @copyright Copyright (c) 2016, ownCloud, Inc.
@@ -29,36 +29,30 @@
2929
* along with this program. If not, see <http://www.gnu.org/licenses/>
3030
*
3131
*/
32-
class OC_EventSource implements \OCP\IEventSource {
33-
/**
34-
* @var bool
35-
*/
36-
private $fallback;
3732

38-
/**
39-
* @var int
40-
*/
41-
private $fallBackId = 0;
33+
namespace OC;
4234

43-
/**
44-
* @var bool
45-
*/
46-
private $started = false;
35+
use OCP\IEventSource;
36+
use OCP\IRequest;
4737

48-
private IRequest $request;
38+
class EventSource implements IEventSource {
39+
private bool $fallback = false;
40+
private int $fallBackId = 0;
41+
private bool $started = false;
4942

50-
public function __construct(IRequest $request) {
51-
$this->request = $request;
43+
public function __construct(
44+
private IRequest $request,
45+
) {
5246
}
5347

54-
protected function init() {
48+
protected function init(): void {
5549
if ($this->started) {
5650
return;
5751
}
5852
$this->started = true;
5953

6054
// prevent php output buffering, caching and nginx buffering
61-
OC_Util::obEnd();
55+
\OC_Util::obEnd();
6256
header('Cache-Control: no-cache');
6357
header('X-Accel-Buffering: no');
6458
$this->fallback = isset($_GET['fallback']) and $_GET['fallback'] == 'true';
@@ -104,7 +98,7 @@ protected function init() {
10498
*/
10599
public function send($type, $data = null) {
106100
if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) {
107-
throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
101+
throw new \BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
108102
}
109103
$this->init();
110104
if (is_null($data)) {

lib/private/EventSourceFactory.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de>
47
*
@@ -27,20 +30,12 @@
2730
use OCP\IRequest;
2831

2932
class EventSourceFactory implements IEventSourceFactory {
30-
private IRequest $request;
31-
32-
33-
public function __construct(IRequest $request) {
34-
$this->request = $request;
33+
public function __construct(
34+
private IRequest $request,
35+
) {
3536
}
3637

37-
/**
38-
* Create a new event source
39-
*
40-
* @return IEventSource
41-
* @since 28.0.0
42-
*/
4338
public function create(): IEventSource {
44-
return new \OC_EventSource($this->request);
39+
return new EventSource($this->request);
4540
}
4641
}

lib/public/IEventSource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface IEventSource {
3737
*
3838
* @param string $type One of success, notice, error, failure and done. Used in core/js/update.js
3939
* @param mixed $data
40+
* @return void
4041
*
4142
* if only one parameter is given, a typeless message will be send with that parameter as data
4243
* @since 8.0.0
@@ -45,6 +46,7 @@ public function send($type, $data = null);
4546

4647
/**
4748
* close the connection of the event source
49+
* @return void
4850
* @since 8.0.0
4951
*/
5052
public function close();

0 commit comments

Comments
 (0)