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 NoteRef extends \Gedcom\Parser\Component |
18
|
|
|
{ |
19
|
|
|
public static function parse(\Gedcom\Parser $parser) |
20
|
|
|
{ |
21
|
|
|
$record = $parser->getCurrentLineRecord(); |
22
|
|
|
$depth = (int) $record[0]; |
23
|
|
|
|
24
|
|
|
$note = new \Gedcom\Record\NoteRef(); |
25
|
|
|
|
26
|
|
|
if (count($record) < 3) { |
|
|
|
|
27
|
|
|
$parser->logSkippedRecord('Missing note information; '.self::class, ' @ '.__LINE__); |
|
|
|
|
28
|
|
|
$parser->skipToNextLevel($depth); |
29
|
|
|
|
30
|
|
|
return null; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if (preg_match('/^@(.*)@$/', trim($record[2]))) { |
34
|
|
|
$note->setIsReference(true); |
35
|
|
|
$note->setNote($parser->normalizeIdentifier($record[2])); |
|
|
|
|
36
|
|
|
} else { |
37
|
|
|
$parser->getCurrentLine(); |
38
|
|
|
$note->setIsReference(false); |
39
|
|
|
$note->setNote($parser->parseMultiLineRecord()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$parser->forward(); |
43
|
|
|
|
44
|
|
|
while (!$parser->eof()) { |
45
|
|
|
$record = $parser->getCurrentLineRecord(); |
46
|
|
|
$recordType = strtoupper(trim($record[1])); |
47
|
|
|
$currentDepth = (int) $record[0]; |
48
|
|
|
|
49
|
|
|
if ($currentDepth <= $depth) { |
50
|
|
|
$parser->back(); |
51
|
|
|
break; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
switch ($recordType) { |
55
|
|
|
case 'SOUR': |
56
|
|
|
$sour = \Gedcom\Parser\SourRef::parse($parser); |
57
|
|
|
$note->addSour($sour); |
58
|
|
|
break; |
59
|
|
|
default: |
60
|
|
|
$parser->logUnhandledRecord(self::class.' @ '.__LINE__); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$parser->forward(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $note; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|