familytree365 /
php-gedcom
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * php-gedcom. |
||||
| 4 | * |
||||
| 5 | * php-gedcom is a library for parsing, manipulating, importing and exporting |
||||
| 6 | * GEDCOM 5.5 files in PHP 5.3+. |
||||
| 7 | * |
||||
| 8 | * @author Kristopher Wilson <[email protected]> |
||||
| 9 | * @copyright Copyright (c) 2010-2013, Kristopher Wilson |
||||
| 10 | * @license MIT |
||||
| 11 | * |
||||
| 12 | * @link http://github.com/mrkrstphr/php-gedcom |
||||
| 13 | */ |
||||
| 14 | |||||
| 15 | namespace Gedcom\Parser; |
||||
| 16 | |||||
| 17 | class Subm extends \Gedcom\Parser\Component |
||||
| 18 | { |
||||
| 19 | public static function parse(\Gedcom\Parser $parser) |
||||
| 20 | { |
||||
| 21 | $record = $parser->getCurrentLineRecord(); |
||||
| 22 | $depth = (int) $record[0]; |
||||
| 23 | if (isset($record[1])) { |
||||
| 24 | $identifier = $parser->normalizeIdentifier($record[1]); |
||||
| 25 | } else { |
||||
| 26 | $parser->skipToNextLevel($depth); |
||||
| 27 | |||||
| 28 | return null; |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | $subm = new \Gedcom\Record\Subm(); |
||||
| 32 | $subm->setSubm($identifier); |
||||
| 33 | |||||
| 34 | $parser->getGedcom()->addSubm($subm); |
||||
| 35 | |||||
| 36 | $parser->forward(); |
||||
| 37 | |||||
| 38 | while (!$parser->eof()) { |
||||
| 39 | $record = $parser->getCurrentLineRecord(); |
||||
| 40 | $currentDepth = (int) $record[0]; |
||||
| 41 | $recordType = strtoupper(trim($record[1])); |
||||
| 42 | |||||
| 43 | if ($currentDepth <= $depth) { |
||||
| 44 | $parser->back(); |
||||
| 45 | break; |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | switch ($recordType) { |
||||
| 49 | case 'NAME': |
||||
| 50 | $subm->setName(isset($record[2]) ? trim($record[2]) : ''); |
||||
| 51 | break; |
||||
| 52 | case 'ADDR': |
||||
| 53 | $addr = \Gedcom\Parser\Addr::parse($parser); |
||||
| 54 | $subm->setAddr($addr); |
||||
| 55 | break; |
||||
| 56 | case 'PHON': |
||||
| 57 | $phone = isset($record[2]) ? trim($record[2]) : ''; |
||||
| 58 | $subm->addPhon($phone); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 59 | break; |
||||
| 60 | case 'EMAIL': |
||||
| 61 | $email = isset($record[2]) ? trim($record[2]) : ''; |
||||
| 62 | $subm->addEmail($email); |
||||
| 63 | break; |
||||
| 64 | case 'FAX': |
||||
| 65 | $fax = isset($record[2]) ? trim($record[2]) : ''; |
||||
| 66 | $subm->addFax($fax); |
||||
| 67 | break; |
||||
| 68 | case 'WWW': |
||||
| 69 | $www = isset($record[2]) ? trim($record[2]) : ''; |
||||
| 70 | $subm->addWww($www); |
||||
| 71 | break; |
||||
| 72 | case 'NOTE': |
||||
| 73 | $note = \Gedcom\Parser\NoteRef::parse($parser); |
||||
| 74 | if ($note) { |
||||
| 75 | $subm->addNote($note); |
||||
|
0 ignored issues
–
show
$note of type Gedcom\Record\NoteRef is incompatible with the type Gedcom\Record\Note expected by parameter $note of Gedcom\Record\Subm::addNote().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 76 | } |
||||
| 77 | break; |
||||
| 78 | case 'OBJE': |
||||
| 79 | $obje = \Gedcom\Parser\ObjeRef::parse($parser); |
||||
| 80 | $subm->addObje($obje); |
||||
| 81 | break; |
||||
| 82 | case 'CHAN': |
||||
| 83 | $chan = \Gedcom\Parser\Chan::parse($parser); |
||||
| 84 | $subm->setChan($chan); |
||||
| 85 | break; |
||||
| 86 | case 'RIN': |
||||
| 87 | $subm->setRin(isset($record[2]) ? trim($record[2]) : ''); |
||||
| 88 | break; |
||||
| 89 | case 'RFN': |
||||
| 90 | $subm->setRfn(isset($record[2]) ? trim($record[2]) : ''); |
||||
| 91 | break; |
||||
| 92 | case 'LANG': |
||||
| 93 | $subm->addLang(isset($record[2]) ? trim($record[2]) : ''); |
||||
| 94 | break; |
||||
| 95 | default: |
||||
| 96 | $parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
||||
| 97 | } |
||||
| 98 | |||||
| 99 | $parser->forward(); |
||||
| 100 | } |
||||
| 101 | |||||
| 102 | return $subm; |
||||
| 103 | } |
||||
| 104 | } |
||||
| 105 |