genealogiawebsite /
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 PhpGedcom\Parser; |
||
| 16 | |||
| 17 | class Head extends \PhpGedcom\Parser\Component |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @param \PhpGedcom\Parser $parser |
||
| 21 | * |
||
| 22 | * @return \PhpGedcom\Record\Head |
||
| 23 | */ |
||
| 24 | public static function parse(\PhpGedcom\Parser $parser) |
||
| 25 | { |
||
| 26 | $record = $parser->getCurrentLineRecord(); |
||
| 27 | $depth = (int) $record[0]; |
||
| 28 | if (isset($record[1])) { |
||
| 29 | $identifier = $parser->normalizeIdentifier($record[1]); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 30 | } else { |
||
| 31 | $parser->skipToNextLevel($depth); |
||
| 32 | |||
| 33 | return null; |
||
| 34 | } |
||
| 35 | |||
| 36 | $head = new \PhpGedcom\Record\Head(); |
||
| 37 | |||
| 38 | $parser->getGedcom()->setHead($head); |
||
| 39 | |||
| 40 | $parser->forward(); |
||
| 41 | |||
| 42 | while (!$parser->eof()) { |
||
| 43 | $record = $parser->getCurrentLineRecord(); |
||
| 44 | $currentDepth = (int) $record[0]; |
||
| 45 | $recordType = strtoupper(trim($record[1])); |
||
| 46 | |||
| 47 | if ($currentDepth <= $depth) { |
||
| 48 | $parser->back(); |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | |||
| 52 | switch ($recordType) { |
||
| 53 | case 'SOUR': |
||
| 54 | $sour = \PhpGedcom\Parser\Head\Sour::parse($parser); |
||
| 55 | $head->setSour($sour); |
||
| 56 | break; |
||
| 57 | case 'DEST': |
||
| 58 | $head->setDest(trim($record[2])); |
||
| 59 | break; |
||
| 60 | case 'SUBM': |
||
| 61 | $head->setSubm($parser->normalizeIdentifier($record[2])); |
||
| 62 | break; |
||
| 63 | case 'SUBN': |
||
| 64 | $head->setSubn($parser->normalizeIdentifier($record[2])); |
||
| 65 | break; |
||
| 66 | case 'DEST': |
||
| 67 | $head->setDest(trim($record[2])); |
||
| 68 | break; |
||
| 69 | case 'FILE': |
||
| 70 | $head->setFile(trim($record[2])); |
||
| 71 | break; |
||
| 72 | case 'COPR': |
||
| 73 | $head->setCopr(trim($record[2])); |
||
| 74 | break; |
||
| 75 | case 'LANG': |
||
| 76 | $head->setLang(trim($record[2])); |
||
| 77 | break; |
||
| 78 | case 'DATE': |
||
| 79 | $date = \PhpGedcom\Parser\Head\Date::parse($parser); |
||
| 80 | $head->setDate($date); |
||
| 81 | break; |
||
| 82 | case 'GEDC': |
||
| 83 | $gedc = \PhpGedcom\Parser\Head\Gedc::parse($parser); |
||
| 84 | $head->setGedc($gedc); |
||
| 85 | break; |
||
| 86 | case 'CHAR': |
||
| 87 | $char = \PhpGedcom\Parser\Head\Char::parse($parser); |
||
| 88 | $head->setChar($char); |
||
| 89 | break; |
||
| 90 | case 'PLAC': |
||
| 91 | $plac = \PhpGedcom\Parser\Head\Plac::parse($parser); |
||
| 92 | $head->setPlac($plac); |
||
| 93 | break; |
||
| 94 | case 'NOTE': |
||
| 95 | $head->setNote($parser->parseMultiLineRecord()); |
||
| 96 | break; |
||
| 97 | default: |
||
| 98 | $parser->logUnhandledRecord(get_class().' @ '.__LINE__); |
||
| 99 | } |
||
| 100 | |||
| 101 | $parser->forward(); |
||
| 102 | } |
||
| 103 | |||
| 104 | return $head; |
||
| 105 | } |
||
| 106 | } |
||
| 107 |