Skip to content

Commit

Permalink
Merge pull request #7 from mostafaznv/dev
Browse files Browse the repository at this point in the history
fix a bug related to guessing the type of a cache item
  • Loading branch information
mostafaznv authored Jun 17, 2023
2 parents 0d4f112 + 29e997d commit 618ac6c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function entityToArray(CacheEntity $entity, string $model, bool $withV

if ($withValue) {
$value = [
'type' => is_null($cache->value) ? null : get_class($cache->value),
'type' => $this->getTypeOfCacheItem($cache->value),
'content' => $cache->value
];
}
Expand Down Expand Up @@ -91,4 +91,21 @@ protected function entityToArray(CacheEntity $entity, string $model, bool $withV
],
];
}

private function getTypeOfCacheItem(mixed $value): ?string
{
if (is_null($value)) {
return null;
}

if (is_array($value)) {
$value = $value[0];
}

if (is_object($value)) {
return get_class($value);
}

return gettype($value);
}
}

0 comments on commit 618ac6c

Please sign in to comment.