xref: /webtrees/app/Elements/PlaceHierarchy.php (revision 1821c9e596679be8717c51394b448df204b1f577)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 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\Elements;
21
22use function preg_replace;
23use function trim;
24
25/**
26 * PLACE_HIERARCHY := {Size=1:120}
27 * This shows the jurisdictional entities that are named in a sequence from the
28 * lowest to the highest jurisdiction. The jurisdictions are separated by
29 * commas, and any jurisdiction's name that is missing is still accounted for
30 * by a comma. When a PLAC.FORM structure is included in the HEADER of a GEDCOM
31 * transmission, it implies that all place names follow this jurisdictional
32 * format and each jurisdiction is accounted for by a comma, whether the name
33 * is known or not. When the PLAC.FORM is subordinate to an event, it
34 * temporarily overrides the implications made by the PLAC.FORM structure
35 * stated in the HEADER. This usage is not common and, therefore, not
36 * encouraged. It should only be used when a system has over-structured its
37 * place-names.
38 */
39class PlaceHierarchy extends AbstractElement
40{
41    protected const MAXIMUM_LENGTH = 120;
42
43    /**
44     * Convert a value to a canonical form.
45     *
46     * @param string $value
47     *
48     * @return string
49     */
50    public function canonical(string $value): string
51    {
52        $value = parent::canonical($value);
53        $value = preg_replace('/[, ]+/', ', ', $value);
54
55        return trim($value, ', ');
56    }
57}
58