Passed
Push — master ( 7e7284...62fa85 )
by Roeland
17:42 queued 12s
created

Template::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
nc 1
nop 0
dl 0
loc 14
c 1
b 0
f 0
cc 1
rs 9.8333
1
<?php
2
/*
3
 * @copyright Copyright (c) 2021 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
declare(strict_types=1);
25
26
27
namespace OCP\Files\Template;
28
29
use OCP\Files\File;
30
31
/**
32
 * @since 21.0.0
33
 */
34
final class Template implements \JsonSerializable {
35
36
	/** @var string */
37
	private $templateType;
38
	/** @var string */
39
	private $templateId;
40
	/** @var File */
41
	private $file;
42
	/** @var bool */
43
	private $hasPreview = false;
44
	/** @var string|null */
45
	private $previewUrl = null;
46
47
	/**
48
	 * @since 21.0.0
49
	 */
50
	public function __construct(string $templateType, string $templateId, File $file) {
51
		$this->templateType = $templateType;
52
		$this->templateId = $templateId;
53
		$this->file = $file;
54
	}
55
56
	/**
57
	 * @since 21.0.0
58
	 */
59
	public function setCustomPreviewUrl(string $previewUrl): void {
60
		$this->previewUrl = $previewUrl;
61
	}
62
63
	/**
64
	 * @since 21.0.0
65
	 */
66
	public function setHasPreview(bool $hasPreview): void {
67
		$this->hasPreview = $hasPreview;
68
	}
69
70
	/**
71
	 * @since 21.0.0
72
	 */
73
	public function jsonSerialize() {
74
		return [
75
			'templateType' => $this->templateType,
76
			'templateId' => $this->templateId,
77
			'basename' => $this->file->getName(),
78
			'etag' => $this->file->getEtag(),
79
			'fileid' => $this->file->getId(),
80
			'filename' => $this->templateId,
81
			'lastmod' => $this->file->getMTime(),
82
			'mime' => $this->file->getMimetype(),
83
			'size' => $this->file->getSize(),
84
			'type' => $this->file->getType(),
85
			'hasPreview' => $this->hasPreview,
86
			'previewUrl' => $this->previewUrl
87
		];
88
	}
89
}
90