summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-01-17 10:01:56 +0100
committerGitHub <noreply@github.com>2018-01-17 10:01:56 +0100
commit6e95bd7a518f587836124e7cb3a3762fb4a62e8c (patch)
treedd0ca0226eac3261ba72c88009768eed5ea6cf61 /lib/private
parent22b3280ac2b60e52049a07ada007768e3cef05ed (diff)
parent569b8413d46e7f4132793f4bc34485233b2cf60f (diff)
downloadnextcloud-server-6e95bd7a518f587836124e7cb3a3762fb4a62e8c.tar.gz
nextcloud-server-6e95bd7a518f587836124e7cb3a3762fb4a62e8c.zip
Merge pull request #7899 from nextcloud/strict_discservice
Strict DiscoveryService
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/OCS/DiscoveryService.php24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/private/OCS/DiscoveryService.php b/lib/private/OCS/DiscoveryService.php
index 4425947c55d..016331e908f 100644
--- a/lib/private/OCS/DiscoveryService.php
+++ b/lib/private/OCS/DiscoveryService.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
*
@@ -60,11 +61,14 @@ class DiscoveryService implements IDiscoveryService {
* @param string $service the service you want to discover
* @return array
*/
- public function discover($remote, $service) {
+ public function discover(string $remote, string $service): array {
// Check the cache first
$cacheData = $this->cache->get($remote . '#' . $service);
if($cacheData) {
- return json_decode($cacheData, true);
+ $data = json_decode($cacheData, true);
+ if (\is_array($data)) {
+ return $data;
+ }
}
$discoveredServices = [];
@@ -77,7 +81,9 @@ class DiscoveryService implements IDiscoveryService {
]);
if($response->getStatusCode() === Http::STATUS_OK) {
$decodedServices = json_decode($response->getBody(), true);
- $discoveredServices = $this->getEndpoints($decodedServices, $service);
+ if (\is_array($decodedServices)) {
+ $discoveredServices = $this->getEndpoints($decodedServices, $service);
+ }
}
} catch (\Exception $e) {
// if we couldn't discover the service or any end-points we return a empty array
@@ -91,17 +97,15 @@ class DiscoveryService implements IDiscoveryService {
/**
* get requested end-points from the requested service
*
- * @param $decodedServices
- * @param $service
+ * @param array $decodedServices
+ * @param string $service
* @return array
*/
- protected function getEndpoints($decodedServices, $service) {
+ protected function getEndpoints(array $decodedServices, string $service): array {
$discoveredServices = [];
- if(is_array($decodedServices) &&
- isset($decodedServices['services'][$service]['endpoints'])
- ) {
+ if(isset($decodedServices['services'][$service]['endpoints'])) {
foreach ($decodedServices['services'][$service]['endpoints'] as $endpoint => $url) {
if($this->isSafeUrl($url)) {
$discoveredServices[$endpoint] = $url;
@@ -119,7 +123,7 @@ class DiscoveryService implements IDiscoveryService {
* @param string $url
* @return bool
*/
- protected function isSafeUrl($url) {
+ protected function isSafeUrl(string $url): bool {
return (bool)preg_match('/^[\/\.\-A-Za-z0-9]+$/', $url);
}