xref: /webtrees/app/SurnameTradition/MatrilinealSurnameTradition.php (revision 73df4c545c87012519818766e1a8eb02272a59b5)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2016 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 */
16namespace Fisharebest\Webtrees\SurnameTradition;
17
18/**
19 * Children take their mother’s surname.
20 */
21class MatrilinealSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface {
22	/**
23	 * What names are given to a new child
24	 *
25	 * @param string $father_name A GEDCOM NAME
26	 * @param string $mother_name A GEDCOM NAME
27	 * @param string $child_sex   M, F or U
28	 *
29	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
30	 */
31	public function newChildNames($father_name, $mother_name, $child_sex) {
32		if (preg_match(self::REGEX_SPFX_SURN, $mother_name, $match)) {
33			return array_filter(array(
34				'NAME' => $match['NAME'],
35				'SPFX' => $match['SPFX'],
36				'SURN' => $match['SURN'],
37			));
38		} else {
39			return array(
40				'NAME' => '//',
41			);
42		}
43	}
44
45	/**
46	 * What names are given to a new parent
47	 *
48	 * @param string $child_name A GEDCOM NAME
49	 * @param string $parent_sex M, F or U
50	 *
51	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
52	 */
53	public function newParentNames($child_name, $parent_sex) {
54		if ($parent_sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) {
55			return array_filter(array(
56				'NAME' => $match['NAME'],
57				'SPFX' => $match['SPFX'],
58				'SURN' => $match['SURN'],
59			));
60		} else {
61			return array(
62				'NAME' => '//',
63			);
64		}
65	}
66}
67