Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move EventSource to OC namespace #45375

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,7 @@
'OC\\Encryption\\Util' => $baseDir . '/lib/private/Encryption/Util.php',
'OC\\EventDispatcher\\EventDispatcher' => $baseDir . '/lib/private/EventDispatcher/EventDispatcher.php',
'OC\\EventDispatcher\\ServiceEventListener' => $baseDir . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventSource' => $baseDir . '/lib/private/EventSource.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',
Expand Down Expand Up @@ -1905,7 +1906,6 @@
'OC_API' => $baseDir . '/lib/private/legacy/OC_API.php',
'OC_App' => $baseDir . '/lib/private/legacy/OC_App.php',
'OC_Defaults' => $baseDir . '/lib/private/legacy/OC_Defaults.php',
'OC_EventSource' => $baseDir . '/lib/private/legacy/OC_EventSource.php',
'OC_FileChunking' => $baseDir . '/lib/private/legacy/OC_FileChunking.php',
'OC_Files' => $baseDir . '/lib/private/legacy/OC_Files.php',
'OC_Helper' => $baseDir . '/lib/private/legacy/OC_Helper.php',
Expand Down
2 changes: 1 addition & 1 deletion lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Encryption\\Util' => __DIR__ . '/../../..' . '/lib/private/Encryption/Util.php',
'OC\\EventDispatcher\\EventDispatcher' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/EventDispatcher.php',
'OC\\EventDispatcher\\ServiceEventListener' => __DIR__ . '/../../..' . '/lib/private/EventDispatcher/ServiceEventListener.php',
'OC\\EventSource' => __DIR__ . '/../../..' . '/lib/private/EventSource.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',
Expand Down Expand Up @@ -1946,7 +1947,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC_API' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_API.php',
'OC_App' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_App.php',
'OC_Defaults' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Defaults.php',
'OC_EventSource' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_EventSource.php',
'OC_FileChunking' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_FileChunking.php',
'OC_Files' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Files.php',
'OC_Helper' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_Helper.php',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use OCP\IRequest;
declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
Expand Down Expand Up @@ -29,36 +29,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
class OC_EventSource implements \OCP\IEventSource {
/**
* @var bool
*/
private $fallback;

/**
* @var int
*/
private $fallBackId = 0;
namespace OC;

/**
* @var bool
*/
private $started = false;
use OCP\IEventSource;
use OCP\IRequest;

private IRequest $request;
class EventSource implements IEventSource {
private bool $fallback = false;
private int $fallBackId = 0;
private bool $started = false;

public function __construct(IRequest $request) {
$this->request = $request;
public function __construct(
private IRequest $request,
) {
}

protected function init() {
protected function init(): void {
if ($this->started) {
return;
}
$this->started = true;

// prevent php output buffering, caching and nginx buffering
OC_Util::obEnd();
\OC_Util::obEnd();
header('Cache-Control: no-cache');
header('X-Accel-Buffering: no');
$this->fallback = isset($_GET['fallback']) and $_GET['fallback'] == 'true';
Expand Down Expand Up @@ -104,7 +98,7 @@ protected function init() {
*/
public function send($type, $data = null) {
if ($data and !preg_match('/^[A-Za-z0-9_]+$/', $type)) {
throw new BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
throw new \BadMethodCallException('Type needs to be alphanumeric ('. $type .')');
}
$this->init();
if (is_null($data)) {
Expand Down
19 changes: 7 additions & 12 deletions lib/private/EventSourceFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de>
*
Expand Down Expand Up @@ -27,20 +30,12 @@
use OCP\IRequest;

class EventSourceFactory implements IEventSourceFactory {
private IRequest $request;


public function __construct(IRequest $request) {
$this->request = $request;
public function __construct(
private IRequest $request,
) {
}

/**
* Create a new event source
*
* @return IEventSource
* @since 28.0.0
come-nc marked this conversation as resolved.
Show resolved Hide resolved
*/
public function create(): IEventSource {
return new \OC_EventSource($this->request);
return new EventSource($this->request);
}
}
2 changes: 2 additions & 0 deletions lib/public/IEventSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface IEventSource {
*
* @param string $type One of success, notice, error, failure and done. Used in core/js/update.js
* @param mixed $data
* @return void
*
* if only one parameter is given, a typeless message will be send with that parameter as data
* @since 8.0.0
Expand All @@ -45,6 +46,7 @@ public function send($type, $data = null);

/**
* close the connection of the event source
* @return void
* @since 8.0.0
*/
public function close();
Expand Down
Loading