1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees\SurnameTradition; 20 21/** 22 * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 23 */ 24class PolishSurnameTradition extends PaternalSurnameTradition 25{ 26 // Inflect a surname for females 27 private const INFLECT_FEMALE = [ 28 'cki\b' => 'cka', 29 'dzki\b' => 'dzka', 30 'ski\b' => 'ska', 31 'żki\b' => 'żka', 32 ]; 33 34 // Inflect a surname for males 35 private const INFLECT_MALE = [ 36 'cka\b' => 'cki', 37 'dzka\b' => 'dzki', 38 'ska\b' => 'ski', 39 'żka\b' => 'żki', 40 ]; 41 42 /** 43 * What names are given to a new child 44 * 45 * @param string $father_name A GEDCOM NAME 46 * @param string $mother_name A GEDCOM NAME 47 * @param string $child_sex M, F or U 48 * 49 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 50 */ 51 public function newChildNames(string $father_name, string $mother_name, string $child_sex): array 52 { 53 if (preg_match(self::REGEX_SURN, $father_name, $match)) { 54 if ($child_sex === 'F') { 55 return array_filter([ 56 'NAME' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), 57 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 58 ]); 59 } 60 61 return array_filter([ 62 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), 63 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 64 ]); 65 } 66 67 return [ 68 'NAME' => '//', 69 ]; 70 } 71 72 /** 73 * What names are given to a new parent 74 * 75 * @param string $child_name A GEDCOM NAME 76 * @param string $parent_sex M, F or U 77 * 78 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 79 */ 80 public function newParentNames(string $child_name, string $parent_sex): array 81 { 82 if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) { 83 return array_filter([ 84 'NAME' => $this->inflect($match['NAME'], self::INFLECT_MALE), 85 'SURN' => $this->inflect($match['SURN'], self::INFLECT_MALE), 86 ]); 87 } 88 89 return [ 90 'NAME' => '//', 91 ]; 92 } 93 94 /** 95 * What names are given to a new spouse 96 * 97 * @param string $spouse_name A GEDCOM NAME 98 * @param string $spouse_sex M, F or U 99 * 100 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 101 */ 102 public function newSpouseNames(string $spouse_name, string $spouse_sex): array 103 { 104 if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) { 105 return [ 106 'NAME' => '//', 107 '_MARNM' => $this->inflect($match['NAME'], self::INFLECT_FEMALE), 108 ]; 109 } 110 111 return [ 112 'NAME' => '//', 113 ]; 114 } 115} 116