xref: /webtrees/app/SurnameTradition/PatrilinealSurnameTradition.php (revision 323788f4145f5a5554b028e0581a6e2063364968)
1*323788f4SGreg Roach<?php
2*323788f4SGreg Roach/**
3*323788f4SGreg Roach * webtrees: online genealogy
4*323788f4SGreg Roach * Copyright (C) 2015 webtrees development team
5*323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
6*323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
7*323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8*323788f4SGreg Roach * (at your option) any later version.
9*323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
10*323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*323788f4SGreg Roach * GNU General Public License for more details.
13*323788f4SGreg Roach * You should have received a copy of the GNU General Public License
14*323788f4SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15*323788f4SGreg Roach */
16*323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
17*323788f4SGreg Roach
18*323788f4SGreg Roach/**
19*323788f4SGreg Roach * Children take their father’s surname.
20*323788f4SGreg Roach */
21*323788f4SGreg Roachclass PatrilinealSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface {
22*323788f4SGreg Roach	/**
23*323788f4SGreg Roach	 * What names are given to a new child
24*323788f4SGreg Roach	 *
25*323788f4SGreg Roach	 * @param string $father_name A GEDCOM NAME
26*323788f4SGreg Roach	 * @param string $mother_name A GEDCOM NAME
27*323788f4SGreg Roach	 * @param string $child_sex   M, F or U
28*323788f4SGreg Roach	 *
29*323788f4SGreg Roach	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
30*323788f4SGreg Roach	 */
31*323788f4SGreg Roach	public function newChildNames($father_name, $mother_name, $child_sex) {
32*323788f4SGreg Roach		if (preg_match(self::REGEX_SPFX_SURN, $father_name, $match)) {
33*323788f4SGreg Roach			return array_filter(array(
34*323788f4SGreg Roach				'NAME' => $match['NAME'],
35*323788f4SGreg Roach				'SPFX' => $match['SPFX'],
36*323788f4SGreg Roach				'SURN' => $match['SURN'],
37*323788f4SGreg Roach			));
38*323788f4SGreg Roach		} else {
39*323788f4SGreg Roach			return array(
40*323788f4SGreg Roach				'NAME' => '//',
41*323788f4SGreg Roach			);
42*323788f4SGreg Roach		}
43*323788f4SGreg Roach	}
44*323788f4SGreg Roach
45*323788f4SGreg Roach	/**
46*323788f4SGreg Roach	 * What names are given to a new parent
47*323788f4SGreg Roach	 *
48*323788f4SGreg Roach	 * @param string $child_name A GEDCOM NAME
49*323788f4SGreg Roach	 * @param string $parent_sex M, F or U
50*323788f4SGreg Roach	 *
51*323788f4SGreg Roach	 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
52*323788f4SGreg Roach	 */
53*323788f4SGreg Roach	public function newParentNames($child_name, $parent_sex) {
54*323788f4SGreg Roach		if ($parent_sex === 'M' && preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) {
55*323788f4SGreg Roach			return array_filter(array(
56*323788f4SGreg Roach				'NAME' => $match['NAME'],
57*323788f4SGreg Roach				'SPFX' => $match['SPFX'],
58*323788f4SGreg Roach				'SURN' => $match['SURN'],
59*323788f4SGreg Roach			));
60*323788f4SGreg Roach		} else {
61*323788f4SGreg Roach			return array(
62*323788f4SGreg Roach				'NAME' => '//',
63*323788f4SGreg Roach			);
64*323788f4SGreg Roach		}
65*323788f4SGreg Roach	}
66*323788f4SGreg Roach
67*323788f4SGreg Roach	/**
68*323788f4SGreg Roach	 * @param string   $name        A name
69*323788f4SGreg Roach	 * @param string[] $inflections A list of inflections
70*323788f4SGreg Roach	 *
71*323788f4SGreg Roach	 * @return string An inflected name
72*323788f4SGreg Roach	 */
73*323788f4SGreg Roach	protected function inflect($name, $inflections) {
74*323788f4SGreg Roach		foreach ($inflections as $from => $to) {
75*323788f4SGreg Roach			$name = preg_replace('~' . $from . '~u', $to, $name);
76*323788f4SGreg Roach		}
77*323788f4SGreg Roach
78*323788f4SGreg Roach		return $name;
79*323788f4SGreg Roach	}
80*323788f4SGreg Roach}
81