summaryrefslogtreecommitdiffstats
path: root/lib/private/ocsclient.php
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2015-04-07 13:48:33 +0200
committerLukas Reschke <lukas@owncloud.com>2015-04-07 13:48:33 +0200
commita2182cde9060b81ea8332598e68ecbdb654d569e (patch)
tree993a006f2006cd5515f285d545066d4777e0147c /lib/private/ocsclient.php
parent8e1a51731a9e02d50bc4c1d6ff636df5ab31966c (diff)
downloadnextcloud-server-a2182cde9060b81ea8332598e68ecbdb654d569e.tar.gz
nextcloud-server-a2182cde9060b81ea8332598e68ecbdb654d569e.zip
Deduplicate code
Diffstat (limited to 'lib/private/ocsclient.php')
-rw-r--r--lib/private/ocsclient.php75
1 files changed, 31 insertions, 44 deletions
diff --git a/lib/private/ocsclient.php b/lib/private/ocsclient.php
index df988d7d3a9..84469cb5e0d 100644
--- a/lib/private/ocsclient.php
+++ b/lib/private/ocsclient.php
@@ -81,6 +81,29 @@ class OCSClient {
}
/**
+ * @param string $body
+ * @param string $action
+ * @return null|\SimpleXMLElement
+ */
+ private function loadData($body, $action) {
+ $loadEntities = libxml_disable_entity_loader(true);
+ $data = @simplexml_load_string($body);
+ libxml_disable_entity_loader($loadEntities);
+
+ if($data === false) {
+ $this->logger->error(
+ sprintf('Could not get %s, content was no valid XML', $action),
+ [
+ 'app' => 'core',
+ ]
+ );
+ return null;
+ }
+
+ return $data;
+ }
+
+ /**
* Get all the categories from the OCS server
*
* @return array|null an array of category ids or null
@@ -110,17 +133,8 @@ class OCSClient {
return null;
}
- $loadEntities = libxml_disable_entity_loader(true);
- $data = @simplexml_load_string($response->getBody());
- libxml_disable_entity_loader($loadEntities);
-
- if($data === false) {
- $this->logger->error(
- 'Could not get categories, content was no valid XML',
- [
- 'app' => 'core',
- ]
- );
+ $data = $this->loadData($response->getBody(), 'categories');
+ if($data === null) {
return null;
}
@@ -175,17 +189,8 @@ class OCSClient {
return [];
}
- $loadEntities = libxml_disable_entity_loader(true);
- $data = @simplexml_load_string($response->getBody());
- libxml_disable_entity_loader($loadEntities);
-
- if($data === false) {
- $this->logger->error(
- 'Could not get applications, content was no valid XML',
- [
- 'app' => 'core',
- ]
- );
+ $data = $this->loadData($response->getBody(), 'applications');
+ if($data === null) {
return [];
}
@@ -251,17 +256,8 @@ class OCSClient {
return null;
}
- $loadEntities = libxml_disable_entity_loader(true);
- $data = @simplexml_load_string($response->getBody());
- libxml_disable_entity_loader($loadEntities);
-
- if($data === false) {
- $this->logger->error(
- 'Could not get application, content was no valid XML',
- [
- 'app' => 'core',
- ]
- );
+ $data = $this->loadData($response->getBody(), 'application');
+ if($data === null) {
return null;
}
@@ -316,17 +312,8 @@ class OCSClient {
return null;
}
- $loadEntities = libxml_disable_entity_loader(true);
- $data = @simplexml_load_string($response->getBody());
- libxml_disable_entity_loader($loadEntities);
-
- if($data === false) {
- $this->logger->error(
- 'Could not get application download URL, content was no valid XML',
- [
- 'app' => 'core',
- ]
- );
+ $data = $this->loadData($response->getBody(), 'application download URL');
+ if($data === null) {
return null;
}