diff options
author | Olivier Paroz <github@oparoz.com> | 2015-09-13 15:21:19 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-09-13 15:21:19 +0300 |
commit | 7b863e9a5ab4a90c53bf70af8c8c04368a286924 (patch) | |
tree | 09bc6e9568c59975c8e358814db842c4cae75519 /utility | |
parent | 0954492f514a5ada9c018d6d67ccf4ba8575c580 (diff) |
Decomplexify EventSource->send
Diffstat (limited to 'utility')
-rw-r--r-- | utility/eventsource.php | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/utility/eventsource.php b/utility/eventsource.php index bdfa651d..05f8121a 100644 --- a/utility/eventsource.php +++ b/utility/eventsource.php @@ -25,6 +25,7 @@ namespace OCA\Gallery\Utility; * Wrapper for server side events (http://en.wikipedia.org/wiki/Server-sent_events) * * This version is tailored for the Gallery app, do not use elsewhere! + * @link https://github.com/owncloud/core/blob/master/lib/private/eventsource.php * * @todo Replace with a library * @@ -64,9 +65,7 @@ class EventSource implements \OCP\IEventSource { * @throws \BadMethodCallException */ public function send($type, $data = null) { - if ($data && !preg_match('/^[A-Za-z0-9_]+$/', $type)) { - throw new \BadMethodCallException('Type needs to be alphanumeric (' . $type . ')'); - } + $this->validateMessage($type, $data); $this->init(); if (is_null($data)) { $data = $type; @@ -92,4 +91,16 @@ class EventSource implements \OCP\IEventSource { '__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 . ')'); + } + } } |