1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 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 father’s surname. Wives take their husband’s surname. 20 */ 21class PaternalSurnameTradition extends PatrilinealSurnameTradition implements SurnameTraditionInterface 22{ 23 /** 24 * Does this surname tradition change surname at marriage? 25 * 26 * @return bool 27 */ 28 public function hasMarriedNames() 29 { 30 return true; 31 } 32 33 /** 34 * What names are given to a new parent 35 * 36 * @param string $child_name A GEDCOM NAME 37 * @param string $parent_sex M, F or U 38 * 39 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 40 */ 41 public function newParentNames($child_name, $parent_sex) 42 { 43 if (preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) { 44 switch ($parent_sex) { 45 case 'M': 46 return array_filter([ 47 'NAME' => $match['NAME'], 48 'SPFX' => $match['SPFX'], 49 'SURN' => $match['SURN'], 50 ]); 51 case 'F': 52 return [ 53 'NAME' => '//', 54 '_MARNM' => '/' . trim($match['SPFX'] . ' ' . $match['SURN']) . '/', 55 ]; 56 } 57 } 58 59 return [ 60 'NAME' => '//', 61 ]; 62 } 63 64 /** 65 * What names are given to a new spouse 66 * 67 * @param string $spouse_name A GEDCOM NAME 68 * @param string $spouse_sex M, F or U 69 * 70 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 71 */ 72 public function newSpouseNames($spouse_name, $spouse_sex) 73 { 74 if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { 75 return [ 76 'NAME' => '//', 77 '_MARNM' => $match['NAME'], 78 ]; 79 } else { 80 return [ 81 'NAME' => '//', 82 ]; 83 } 84 } 85} 86