diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-05-14 16:50:55 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-05-14 16:50:55 +0300 |
commit | 7b1652351ce1b6b4c342fb7f817d3b68f0941f13 (patch) | |
tree | c89a4bc5bdc62b2d0664e9eac590a4d4e30bd5a6 /lib | |
parent | 8a5e445a0e170ce1e43f335753525fbc6b45de50 (diff) |
Remove modal mask limit
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/EventSource.php | 102 |
1 files changed, 0 insertions, 102 deletions
diff --git a/lib/EventSource.php b/lib/EventSource.php deleted file mode 100644 index 4fd531803..000000000 --- a/lib/EventSource.php +++ /dev/null @@ -1,102 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net> - * - * @author Julius Härtl <jus@bitgrid.net> - * - * @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\Text\Controller; - -use OCP\IEventSource; - - -class EventSource implements IEventSource { - - /** - * @var bool - */ - private $started = false; - - protected function init(): void { - if ($this->started) { - return; - } - $this->started = true; - - // prevent php output buffering, caching and nginx buffering - while (ob_get_level()) { - ob_end_clean(); - } - header('Cache-Control: no-cache'); - header('X-Accel-Buffering: no'); - header("Content-Type: text/event-stream"); - flush(); - } - - /** - * Sends a message to the client - * - * If only one parameter is given, a typeless message will be sent with that parameter as data - * - * @param string $type - * @param mixed $data - * - * @throws \BadMethodCallException - */ - public function send($type, $data = null) { - $this->validateMessage($type, $data); - $this->init(); - if (is_null($data)) { - $data = $type; - $type = null; - } - - if (!empty($type)) { - echo 'event: ' . $type . PHP_EOL; - } - echo 'data: ' . json_encode($data) . PHP_EOL; - - echo PHP_EOL; - flush(); - } - - /** - * Closes the connection of the event source - * - * It's best to let the client close the stream - */ - public function close() { - $this->send( - '__internal__', 'close' - ); - } - - /** - * Makes sure we have a message we can use - * - * @param string $type - * @param mixed $data - */ - private function validateMessage($type, $data) { - if ($data && !preg_match('/^[A-Za-z0-9_]+$/', $type)) { - throw new \BadMethodCallException('Type needs to be alphanumeric (' . $type . ')'); - } - } -} |