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