xref: /webtrees/app/SurnameTradition/DefaultSurnameTradition.php (revision 8121b9bec19818120092699199161a1357bb8f3f)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\SurnameTradition;
19
20/**
21 * All family members keep their original surname
22 */
23class DefaultSurnameTradition implements SurnameTraditionInterface
24{
25    /** Extract a GIVN from a NAME */
26    protected const REGEX_GIVN = '~^(?<GIVN>[^/ ]+)~';
27
28    /** Extract a SPFX and SURN from a NAME */
29    protected const REGEX_SPFX_SURN = '~(?<NAME>/(?<SPFX>[a-z’\']{0,4}(?: [a-z’\']{1,4})*) ?(?<SURN>[^/]*)/)~';
30
31    /** Extract a simple SURN from a NAME */
32    protected const REGEX_SURN = '~(?<NAME>/(?<SURN>[^/]+)/)~';
33
34    /** Extract two Spanish/Portuguese SURNs from a NAME */
35    protected const REGEX_SURNS = '~/(?<SURN1>[^ /]+)(?: | y |/ /|/ y /)(?<SURN2>[^ /]+)/~';
36
37    /**
38     * Does this surname tradition change surname at marriage?
39     *
40     * @return bool
41     */
42    public function hasMarriedNames(): bool
43    {
44        return false;
45    }
46
47    /**
48     * Does this surname tradition use surnames?
49     *
50     * @return bool
51     */
52    public function hasSurnames(): bool
53    {
54        return true;
55    }
56
57    /**
58     * What names are given to a new child
59     *
60     * @param string $father_name A GEDCOM NAME
61     * @param string $mother_name A GEDCOM NAME
62     * @param string $child_sex   M, F or U
63     *
64     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
65     */
66    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
67    {
68        return [
69            'NAME' => '//',
70        ];
71    }
72
73    /**
74     * What names are given to a new parent
75     *
76     * @param string $child_name A GEDCOM NAME
77     * @param string $parent_sex M, F or U
78     *
79     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
80     */
81    public function newParentNames(string $child_name, string $parent_sex): array
82    {
83        return [
84            'NAME' => '//',
85        ];
86    }
87
88    /**
89     * What names are given to a new spouse
90     *
91     * @param string $spouse_name A GEDCOM NAME
92     * @param string $spouse_sex  M, F or U
93     *
94     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
95     */
96    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
97    {
98        return [
99            'NAME' => '//',
100        ];
101    }
102}
103