blob: 86f6a3e72fa182ae8eaded697ed2079a18f04702 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
<?php
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Files\Template;
use OCP\Files\Template\InvalidFieldTypeException;
class Field implements \JsonSerializable {
private int $index;
private string $content;
private FieldType $type;
private ?int $id;
private ?string $tag;
public function __construct($index, $content, $type, $id = null, $tag = null) {
$this->index = $index;
$this->id = $id;
$this->tag = $tag;
// TODO: Sanitize content
$this->content = $content;
if ($type instanceof FieldType) {
$this->type = $type;
} else {
// TODO: Throw a proper enum with descriptive message
$this->type = FieldType::tryFrom($type) ?? throw new InvalidFieldTypeException();
}
}
public function jsonSerialize(): array {
return [
"index" => $this->index,
"content" => $this->content,
"type" => $this->type->value,
"id" => $this->id,
"tag" => $this->tag,
];
}
}
|