aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Files/Template/Field.php
blob: ea200b74a00b1059bfa0d0f8816bd299920ae4b1 (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
<?php

/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCP\Files\Template;

class Field implements \JsonSerializable {
	private string $index;
	private string $content;
	private FieldType $type;
	private ?string $alias;
	private ?int $id;
	private ?string $tag;

	public function __construct($index, $content, $type, $alias = null, $id = null, $tag = null) {
		$this->index = $index;
		$this->alias = $alias;
		$this->id = $id;
		$this->tag = $tag;
		$this->content = $content;

		if ($type instanceof FieldType) {
			$this->type = $type;
		} else {
			$this->type = FieldType::tryFrom($type) ?? throw new InvalidFieldTypeException();
		}
	}

	public function jsonSerialize(): array {
		return [
			"index" => $this->index,
			"content" => $this->content,
			"type" => $this->type->value,
			"alias" => $this->alias,
			"id" => $this->id,
			"tag" => $this->tag,
		];
	}
}