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; |
||||
16 | |||||
17 | use PhpGedcom\Writer\Fam; |
||||
18 | use PhpGedcom\Writer\Head; |
||||
19 | use PhpGedcom\Writer\Indi; |
||||
20 | use PhpGedcom\Writer\Note; |
||||
21 | use PhpGedcom\Writer\Obje; |
||||
22 | use PhpGedcom\Writer\Repo; |
||||
23 | use PhpGedcom\Writer\Sour; |
||||
24 | use PhpGedcom\Writer\Subm; |
||||
25 | use PhpGedcom\Writer\Subn; |
||||
26 | |||||
27 | class Writer |
||||
28 | { |
||||
29 | const GEDCOM55 = 'gedcom5.5'; |
||||
30 | |||||
31 | protected $_output = null; |
||||
32 | |||||
33 | /** |
||||
34 | * @param \PhpGedcom\Gedcom $gedcom The GEDCOM object |
||||
35 | * @param string $format The format to convert the GEDCOM object to |
||||
36 | * |
||||
37 | * @return string The contents of the document in the converted format |
||||
38 | */ |
||||
39 | public static function convert(Gedcom $gedcom, $format = self::GEDCOM55) |
||||
40 | { |
||||
41 | $head = $gedcom->getHead(); |
||||
42 | $subn = $gedcom->getSubn(); |
||||
43 | $subms = $gedcom->getSubm(); // array() |
||||
44 | $sours = $gedcom->getSour(); // array() |
||||
45 | $indis = $gedcom->getIndi(); // array() |
||||
46 | $fams = $gedcom->getFam(); // array() |
||||
47 | $notes = $gedcom->getNote(); // array() |
||||
48 | $repos = $gedcom->getRepo(); // array() |
||||
49 | $objes = $gedcom->getObje(); // array() |
||||
50 | |||||
51 | $output = '0 FORMAT '.$format."\n"; |
||||
52 | |||||
53 | // head |
||||
54 | if ($head) { |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
55 | $output = Head::convert($head, $format); |
||||
56 | } |
||||
57 | |||||
58 | // subn |
||||
59 | if ($subn) { |
||||
0 ignored issues
–
show
|
|||||
60 | $output .= Subn::convert($subn); |
||||
61 | } |
||||
62 | |||||
63 | // subms |
||||
64 | if (!empty($subms) && count($subms) > 0) { |
||||
65 | foreach ($subms as $item) { |
||||
66 | if ($item) { |
||||
67 | $output .= Subm::convert($item); |
||||
68 | } |
||||
69 | } |
||||
70 | } |
||||
71 | |||||
72 | // sours |
||||
73 | if (!empty($sours) && count($sours) > 0) { |
||||
74 | foreach ($sours as $item) { |
||||
75 | if ($item) { |
||||
76 | $output .= Sour::convert($item); |
||||
0 ignored issues
–
show
The call to
PhpGedcom\Writer\Sour::convert() has too few arguments starting with level .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
77 | } |
||||
78 | } |
||||
79 | } |
||||
80 | |||||
81 | // indis |
||||
82 | if (!empty($indis) && count($indis) > 0) { |
||||
83 | foreach ($indis as $item) { |
||||
84 | if ($item) { |
||||
85 | $output .= Indi::convert($item); |
||||
86 | } |
||||
87 | } |
||||
88 | } |
||||
89 | |||||
90 | // fams |
||||
91 | if (!empty($fams) && count($fams) > 0) { |
||||
92 | foreach ($fams as $item) { |
||||
93 | if ($item) { |
||||
94 | $output .= Fam::convert($item); |
||||
95 | } |
||||
96 | } |
||||
97 | } |
||||
98 | // notes |
||||
99 | if (!empty($notes) && count($notes) > 0) { |
||||
100 | foreach ($notes as $item) { |
||||
101 | if ($item) { |
||||
102 | $output .= Note::convert($item); |
||||
103 | } |
||||
104 | } |
||||
105 | } |
||||
106 | |||||
107 | // repos |
||||
108 | if (!empty($repos) && count($repos) > 0) { |
||||
109 | foreach ($repos as $item) { |
||||
110 | if ($item) { |
||||
111 | $output .= Repo::convert($item); |
||||
112 | } |
||||
113 | } |
||||
114 | } |
||||
115 | // Objes |
||||
116 | if (!empty($objes) && count($objes) > 0) { |
||||
117 | foreach ($objes as $item) { |
||||
118 | if ($item) { |
||||
119 | $output .= Obje::convert($item); |
||||
120 | } |
||||
121 | } |
||||
122 | } |
||||
123 | // EOF |
||||
124 | $output .= "0 TRLR\n"; |
||||
125 | |||||
126 | return $output; |
||||
127 | } |
||||
128 | } |
||||
129 |