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

59 lines
1.1 KiB
PHP
Raw Normal View History

2020-04-21 22:37:42 +02:00
<?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;
2020-04-21 22:37:42 +02:00
use OCP\AppFramework\Db\Entity;
2023-06-16 21:31:46 +02:00
/**
* @psalm-type SerializedEntity = array<string|int|array>
*/
2023-08-02 22:04:03 +02:00
abstract class ReaderEntity extends Entity
{
2023-06-16 21:20:03 +02:00
protected int $lastModified; // modification timestamp
2023-06-16 16:58:23 +02:00
2023-06-16 21:31:46 +02:00
/**
2023-08-02 22:04:03 +02:00
* returns decoded json if input is json, otherwise returns input.
2023-06-16 21:31:46 +02:00
*
2023-08-02 22:04:03 +02:00
* @return array|string
2023-06-16 21:31:46 +02:00
*/
2023-08-02 22:04:03 +02:00
public function conditional_json_decode(string $el): mixed
{
2023-06-16 21:31:46 +02:00
/** @var array $result */
2023-06-16 16:58:23 +02:00
$result = json_decode($el);
2023-08-02 22:04:03 +02:00
if (JSON_ERROR_NONE === json_last_error()) {
2023-06-16 16:58:23 +02:00
return $result;
}
2023-08-02 22:04:03 +02:00
return $el;
2023-06-16 16:58:23 +02:00
}
2023-08-02 22:04:03 +02:00
public function getLastModified(): int
{
2023-06-16 16:58:23 +02:00
return $this->lastModified;
}
2020-04-21 22:37:42 +02:00
2023-08-02 22:04:03 +02:00
public function setLastModified(int $lastModified): void
{
2023-06-16 16:58:23 +02:00
$this->lastModified = $lastModified;
2023-06-17 01:17:29 +02:00
$this->markFieldUpdated('lastModified');
2023-06-16 16:58:23 +02:00
}
2023-06-16 21:31:46 +02:00
/**
2023-08-02 22:04:03 +02:00
* @return SerializedEntity
2023-06-16 21:31:46 +02:00
*/
2023-06-16 21:20:03 +02:00
abstract public function toService(): array;
2023-06-16 21:31:46 +02:00
/**
2023-08-02 22:04:03 +02:00
* @return SerializedEntity
2023-06-16 21:31:46 +02:00
*/
abstract public function jsonSerialize(): array;
2023-06-16 16:58:23 +02:00
}