Skip to content

Commit

Permalink
Merge pull request #1040 from nextcloud/fix/noid/deserialize-list
Browse files Browse the repository at this point in the history
using deserializeList instead
  • Loading branch information
ArtificialOwl authored Jun 13, 2022
2 parents 5ae52ac + 93b3f91 commit ec72970
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Service/ShareWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function getSharedWith(
throw new InvalidItemException();
}

return $this->deserializeArray($cachedData, ShareWrapper::class);
return $this->deserializeList($cachedData, ShareWrapper::class);
} catch (InvalidItemException $e) {
}

Expand Down
31 changes: 30 additions & 1 deletion lib/Tools/Traits/TDeserialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,42 @@ public function deserialize(array $data, string $class): IDeserializable {
}


/**
* @param array $data
* @param string $class
* @param bool $associative
*
* @return IDeserializable[]
*/
public function deserializeArray(array $data, string $class, bool $associative = false): array {
$arr = [];
foreach ($data as $key => $entry) {
if (!is_array($entry)) {
continue;
}

try {
if ($associative) {
$arr[$key] = $this->deserialize($entry, $class);
} else {
$arr[] = $this->deserialize($entry, $class);
}
} catch (InvalidItemException $e) {
}
}

return $arr;
}


/**
* @param string $json
* @param string $class
*
* @return IDeserializable[]
* @throws InvalidItemException
*/
public function deserializeArray(string $json, string $class): array {
public function deserializeList(string $json, string $class): array {
$arr = [];
$data = json_decode($json, true);
if (!is_array($data)) {
Expand All @@ -99,6 +127,7 @@ public function deserializeArray(string $json, string $class): array {
}



/**
* @param string $json
* @param string $class
Expand Down

0 comments on commit ec72970

Please sign in to comment.