|
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; |
|
16
|
|
|
|
|
17
|
|
|
abstract class Record |
|
18
|
|
|
{ |
|
19
|
|
|
public function __call($method, $args) |
|
20
|
|
|
{ |
|
21
|
|
|
if (substr($method, 0, 3) == 'add') { |
|
22
|
|
|
$arr = strtolower(substr($method, 3)); |
|
23
|
|
|
|
|
24
|
|
|
if (!property_exists($this, '_'.$arr) || !is_array($this->{'_'.$arr})) { |
|
25
|
|
|
throw new \Exception('Unknown '.$this::class.'::'.$arr); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
if (!is_array($args)) { |
|
29
|
|
|
throw new \Exception('Incorrect arguments to '.$method); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if (!isset($args[0])) { |
|
33
|
|
|
// Argument can be empty since we trim it's value |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if (is_object($args[0])) { |
|
38
|
|
|
// Type safety? |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$this->{'_'.$arr}[] = $args[0]; |
|
42
|
|
|
|
|
43
|
|
|
return $this; |
|
44
|
|
|
} elseif (substr($method, 0, 3) == 'set') { |
|
45
|
|
|
$arr = strtolower(substr($method, 3)); |
|
46
|
|
|
|
|
47
|
|
|
if (!property_exists($this, '_'.$arr)) { |
|
48
|
|
|
throw new \Exception('Unknown '.$this::class.'::'.$arr); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (!is_array($args)) { |
|
52
|
|
|
throw new \Exception('Incorrect arguments to '.$method); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if (!isset($args[0])) { |
|
56
|
|
|
// Argument can be empty since we trim it's value |
|
57
|
|
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if (is_object($args[0])) { |
|
61
|
|
|
// Type safety? |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->{'_'.$arr} = $args[0]; |
|
65
|
|
|
|
|
66
|
|
|
return $this; |
|
67
|
|
|
} elseif (substr($method, 0, 3) == 'get') { |
|
68
|
|
|
$arr = strtolower(substr($method, 3)); |
|
69
|
|
|
|
|
70
|
|
|
// hotfix getData |
|
71
|
|
|
if ('data' == $arr) { |
|
72
|
|
|
if (!property_exists($this, '_text')) { |
|
73
|
|
|
throw new \Exception('Unknown '.$this::class.'::'.$arr); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $this->{'_text'}; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
if (!property_exists($this, '_'.$arr)) { |
|
80
|
|
|
throw new \Exception('Unknown '.$this::class.'::'.$arr); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $this->{'_'.$arr}; |
|
84
|
|
|
} else { |
|
85
|
|
|
throw new \Exception('Unknown method called: '.$method); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function __set($var, $val) |
|
90
|
|
|
{ |
|
91
|
|
|
// this class does not have any public vars |
|
92
|
|
|
throw new \Exception('Undefined property '.self::class.'::'.$var); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Checks if this GEDCOM object has the provided attribute (ie, if the provided |
|
97
|
|
|
* attribute exists below the current object in its tree). |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $var The name of the attribute |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool True if this object has the provided attribute |
|
102
|
|
|
*/ |
|
103
|
|
|
public function hasAttribute($var) |
|
104
|
|
|
{ |
|
105
|
|
|
return property_exists($this, '_'.$var) || property_exists($this, $var); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|