Add function to check if object with given identifier exists

This commit is contained in:
root 2022-11-28 20:33:21 +01:00
parent a75d91ff6d
commit 794e174748
2 changed files with 26 additions and 7 deletions

View File

@ -88,6 +88,32 @@ class JsonDatabase implements IJsonUnflattener
return $retPath; return $retPath;
} }
public function exists(string $class, string $name, ?int $timestamp = null): bool
{
if ($class == null || empty(trim($name)))
return false;
if ($name != null && !empty(trim(strval($name))))
$name = JSONDatabase::SanitizeIdentifier($name);
else
return false;
$class = trim($class);
if (!$this->audit && $timestamp != null)
return false;
$objPath = $this->getObjectPath($class, $name, ($timestamp != null));
if (strlen($objPath) > PHP_MAXPATHLEN)
return false;
if (!is_file($objPath))
return false;
return true;
}
public function load(string $class, string $name, ?int $timestamp = null): JsonSerializable|null public function load(string $class, string $name, ?int $timestamp = null): JsonSerializable|null
{ {
if ($class == null || empty(trim($name))) if ($class == null || empty(trim($name)))

View File

@ -1,7 +0,0 @@
<?php
namespace SeriousJSON;
class JsonHistoryItem extends \SeriousJSON\JsonSerializable implements \SeriousJSON\IJsonIdentifiable {
}