diff --git a/src/SeriousJSON/JsonDatabase.php b/src/SeriousJSON/JsonDatabase.php index b9dd89f..7b0c359 100644 --- a/src/SeriousJSON/JsonDatabase.php +++ b/src/SeriousJSON/JsonDatabase.php @@ -189,6 +189,37 @@ class JsonDatabase implements IJsonUnflattener return $name; } + public function delete(string $className, $identifier): 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 true; + + return unlink($objPath); + } + + public function delete(IJsonIdentifiable $obj): bool + { + return $this->delete(get_class($obj), $obj->flatIdentifier()); + } + /** * Restore a JsonSerializable from the Database by using it's Identifier reference. * @param string $className the full class name with domain of the JsonSerializable property