xref: /webtrees/app/Contracts/ElementInterface.php (revision 2ebcf907ed34213f816592af04e6c160335d6311)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Contracts;
21
22use Fisharebest\Webtrees\Tree;
23
24/**
25 * A GEDCOM element is a tag/primitive in a GEDCOM file.
26 */
27interface ElementInterface
28{
29    /**
30     * Convert a value to a canonical form.
31     *
32     * @param string $value
33     *
34     * @return string
35     */
36    public function canonical(string $value): string;
37
38    /**
39     * Create a default value for this element.
40     *
41     * @param Tree $tree
42     *
43     * @return string
44     */
45    public function default(Tree $tree): string;
46
47    /**
48     * An edit control for this data.
49     *
50     * @param string $id
51     * @param string $name
52     * @param string $value
53     * @param Tree   $tree
54     *
55     * @return string
56     */
57    public function edit(string $id, string $name, string $value, Tree $tree): string;
58
59    /**
60     * Escape @ signs in a GEDCOM export.
61     *
62     * @param string $value
63     *
64     * @return string
65     */
66    public function escape(string $value): string;
67
68    /**
69     * Name for this GEDCOM primitive.
70     *
71     * @return string
72     */
73    public function label(): string;
74
75    /**
76     * Create a label/value pair for this element.
77     *
78     * @param string $value
79     * @param Tree   $tree
80     *
81     * @return string
82     */
83    public function labelValue(string $value, Tree $tree): string;
84
85    /**
86     * Set, remove or replace a subtag.
87     *
88     * @param string $subtag
89     * @param string $repeat
90     * @param string $before
91     *
92     * @return void
93     */
94    public function subtag(string $subtag, string $repeat = '0:1', string $before = ''): void;
95
96    /**
97     * @return array<string,string>
98     */
99    public function subtags(): array;
100
101    /**
102     * Display the value of this type of element.
103     *
104     * @param string $value
105     * @param Tree   $tree
106     *
107     * @return string
108     */
109    public function value(string $value, Tree $tree): string;
110
111    /**
112     * A list of controlled values for this element
113     *
114     * @return array<int|string,string>
115     */
116    public function values(): array;
117}
118