This repository has been archived on 2024-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
epubreader/lib/Db/ReaderEntity.php
Michel Roux cb8cf250a5
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Use php 8.0 for nextcloud 22
2023-06-22 13:54:41 +02:00

56 lines
1.1 KiB
PHP

<?php
/**
* @author Frank de Lange
* @copyright 2015 Frank de Lange
*
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace OCA\Epubreader\Db;
use OCP\AppFramework\Db\Entity;
/**
* @psalm-type SerializedEntity = array<string|int|array>
*/
abstract class ReaderEntity extends Entity {
protected int $lastModified; // modification timestamp
/**
* returns decoded json if input is json, otherwise returns input
*
* @return string|array
*/
public function conditional_json_decode(string $el): mixed {
/** @var array $result */
$result = json_decode($el);
if (json_last_error() === JSON_ERROR_NONE) {
return $result;
} else {
return $el;
}
}
public function getLastModified(): int {
return $this->lastModified;
}
public function setLastModified(int $lastModified): void {
$this->lastModified = $lastModified;
$this->markFieldUpdated('lastModified');
}
/**
* @psalm-return SerializedEntity
*/
abstract public function toService(): array;
/**
* @psalm-return SerializedEntity
*/
abstract public function jsonSerialize(): array;
}