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. Surnames are inflected to indicate an individual’s sex. 20 */ 21class PolishSurnameTradition extends PaternalSurnameTradition implements SurnameTraditionInterface { 22 /** @var string[] Inflect a surname for females */ 23 protected $inflect_female = [ 24 'cki\b' => 'cka', 25 'dzki\b' => 'dzka', 26 'ski\b' => 'ska', 27 'żki\b' => 'żka', 28 ]; 29 30 /** @var string[] Inflect a surname for males */ 31 protected $inflect_male = [ 32 'cka\b' => 'cki', 33 'dzka\b' => 'dzki', 34 'ska\b' => 'ski', 35 'żka\b' => 'żki', 36 ]; 37 38 /** 39 * What names are given to a new child 40 * 41 * @param string $father_name A GEDCOM NAME 42 * @param string $mother_name A GEDCOM NAME 43 * @param string $child_sex M, F or U 44 * 45 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 46 */ 47 public function newChildNames($father_name, $mother_name, $child_sex) { 48 if (preg_match(self::REGEX_SURN, $father_name, $match)) { 49 if ($child_sex === 'F') { 50 return array_filter([ 51 'NAME' => $this->inflect($match['NAME'], $this->inflect_female), 52 'SURN' => $this->inflect($match['SURN'], $this->inflect_male), 53 ]); 54 } else { 55 return array_filter([ 56 'NAME' => $this->inflect($match['NAME'], $this->inflect_male), 57 'SURN' => $this->inflect($match['SURN'], $this->inflect_male), 58 ]); 59 } 60 } else { 61 return [ 62 'NAME' => '//', 63 ]; 64 } 65 } 66 67 /** 68 * What names are given to a new parent 69 * 70 * @param string $child_name A GEDCOM NAME 71 * @param string $parent_sex M, F or U 72 * 73 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 74 */ 75 public function newParentNames($child_name, $parent_sex) { 76 if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) { 77 return array_filter([ 78 'NAME' => $this->inflect($match['NAME'], $this->inflect_male), 79 'SURN' => $this->inflect($match['SURN'], $this->inflect_male), 80 ]); 81 } else { 82 return [ 83 'NAME' => '//', 84 ]; 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($spouse_name, $spouse_sex) { 97 if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { 98 return [ 99 'NAME' => '//', 100 '_MARNM' => $this->inflect($match['NAME'], $this->inflect_female), 101 ]; 102 } else { 103 return [ 104 'NAME' => '//', 105 ]; 106 } 107 } 108} 109