@@ -24,5 +24,5 @@ |
||
24 | 24 | |
25 | 25 | interface GedcomRecordFactory { |
26 | 26 | |
27 | - public function createRecord(string $xref, string $gedcom, ?string $pending, Tree $tree): GedcomRecord; |
|
27 | + public function createRecord(string $xref, string $gedcom, ?string $pending, Tree $tree): GedcomRecord; |
|
28 | 28 | } |
@@ -22,7 +22,8 @@ |
||
22 | 22 | use Fisharebest\Webtrees\GedcomRecord; |
23 | 23 | use Fisharebest\Webtrees\Tree; |
24 | 24 | |
25 | -interface GedcomRecordFactory { |
|
25 | +interface GedcomRecordFactory |
|
26 | +{ |
|
26 | 27 | |
27 | 28 | public function createRecord(string $xref, string $gedcom, ?string $pending, Tree $tree): GedcomRecord; |
28 | 29 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | public static function getInstance(string $xref, Tree $tree, string $gedcom = null) |
186 | 186 | { |
187 | 187 | if (!Application::getInstance()->bound(GedcomRecordFactories::class)) { |
188 | - Application::getInstance()->singleton(GedcomRecordFactories::class); |
|
188 | + Application::getInstance()->singleton(GedcomRecordFactories::class); |
|
189 | 189 | } |
190 | 190 | $factories = app(GedcomRecordFactories::class); |
191 | 191 | $ret = $factories->getInstance($xref, $tree, $gedcom); |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | |
196 | 196 | public static function retrieveGedcomRecord(string $xref, int $tree_id): ?string |
197 | 197 | { |
198 | - return self::fetchGedcomRecord($xref, $tree_id); |
|
198 | + return self::fetchGedcomRecord($xref, $tree_id); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -183,7 +183,7 @@ |
||
183 | 183 | * @throws Exception |
184 | 184 | */ |
185 | 185 | public static function getInstance(string $xref, Tree $tree, string $gedcom = null) |
186 | - { |
|
186 | + { |
|
187 | 187 | if (!Application::getInstance()->bound(GedcomRecordFactories::class)) { |
188 | 188 | Application::getInstance()->singleton(GedcomRecordFactories::class); |
189 | 189 | } |
@@ -35,49 +35,49 @@ discard block |
||
35 | 35 | |
36 | 36 | class GedcomRecordFactories { |
37 | 37 | |
38 | - /** @var GedcomRecord[][] Allow getInstance() to return references to existing objects */ |
|
39 | - protected $gedcom_record_cache; |
|
38 | + /** @var GedcomRecord[][] Allow getInstance() to return references to existing objects */ |
|
39 | + protected $gedcom_record_cache; |
|
40 | 40 | |
41 | - /** @var stdClass[][] Fetch all pending edits in one database query */ |
|
42 | - protected $pending_record_cache; |
|
41 | + /** @var stdClass[][] Fetch all pending edits in one database query */ |
|
42 | + protected $pending_record_cache; |
|
43 | 43 | |
44 | - protected $factories = []; |
|
44 | + protected $factories = []; |
|
45 | 45 | |
46 | - public function __construct() { |
|
47 | - } |
|
46 | + public function __construct() { |
|
47 | + } |
|
48 | 48 | |
49 | - public function addFactory(string $type, GedcomRecordFactory $factory) { |
|
49 | + public function addFactory(string $type, GedcomRecordFactory $factory) { |
|
50 | 50 | $this->factories[$type] = $factory; |
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Get an instance of a GedcomRecord object. For single records, |
|
55 | - * we just receive the XREF. For bulk records (such as lists |
|
56 | - * and search results) we can receive the GEDCOM data as well. |
|
57 | - * |
|
58 | - * @param string $xref |
|
59 | - * @param Tree $tree |
|
60 | - * @param string|null $gedcom |
|
61 | - * |
|
62 | - * @throws Exception |
|
63 | - * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
|
64 | - */ |
|
65 | - public function getInstance(string $xref, Tree $tree, string $gedcom = null) { |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Get an instance of a GedcomRecord object. For single records, |
|
55 | + * we just receive the XREF. For bulk records (such as lists |
|
56 | + * and search results) we can receive the GEDCOM data as well. |
|
57 | + * |
|
58 | + * @param string $xref |
|
59 | + * @param Tree $tree |
|
60 | + * @param string|null $gedcom |
|
61 | + * |
|
62 | + * @throws Exception |
|
63 | + * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
|
64 | + */ |
|
65 | + public function getInstance(string $xref, Tree $tree, string $gedcom = null) { |
|
66 | 66 | $tree_id = $tree->id(); |
67 | 67 | |
68 | 68 | // Is this record already in the cache? |
69 | 69 | if (isset($this->gedcom_record_cache[$xref][$tree_id])) { |
70 | - return $this->gedcom_record_cache[$xref][$tree_id]; |
|
70 | + return $this->gedcom_record_cache[$xref][$tree_id]; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // Do we need to fetch the record from the database? |
74 | 74 | if ($gedcom === null) { |
75 | - $gedcom = GedcomRecord::retrieveGedcomRecord($xref, $tree_id); |
|
75 | + $gedcom = GedcomRecord::retrieveGedcomRecord($xref, $tree_id); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // If we can edit, then we also need to be able to see pending records. |
79 | 79 | if (Auth::isEditor($tree)) { |
80 | - if (!isset($this->pending_record_cache[$tree_id])) { |
|
80 | + if (!isset($this->pending_record_cache[$tree_id])) { |
|
81 | 81 | // Fetch all pending records in one database query |
82 | 82 | $this->pending_record_cache[$tree_id] = []; |
83 | 83 | $rows = DB::table('change') |
@@ -88,70 +88,70 @@ discard block |
||
88 | 88 | ->get(); |
89 | 89 | |
90 | 90 | foreach ($rows as $row) { |
91 | - $this->pending_record_cache[$tree_id][$row->xref] = $row->new_gedcom; |
|
91 | + $this->pending_record_cache[$tree_id][$row->xref] = $row->new_gedcom; |
|
92 | + } |
|
92 | 93 | } |
93 | - } |
|
94 | 94 | |
95 | - $pending = $this->pending_record_cache[$tree_id][$xref] ?? null; |
|
95 | + $pending = $this->pending_record_cache[$tree_id][$xref] ?? null; |
|
96 | 96 | } else { |
97 | - // There are no pending changes for this record |
|
98 | - $pending = null; |
|
97 | + // There are no pending changes for this record |
|
98 | + $pending = null; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // No such record exists |
102 | 102 | if ($gedcom === null && $pending === null) { |
103 | - return null; |
|
103 | + return null; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // No such record, but a pending creation exists |
107 | 107 | if ($gedcom === null) { |
108 | - $gedcom = ''; |
|
108 | + $gedcom = ''; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Create the object |
112 | 112 | if (preg_match('/^0 @(' . Gedcom::REGEX_XREF . ')@ (' . Gedcom::REGEX_TAG . ')/', $gedcom . $pending, $match)) { |
113 | - $xref = $match[1]; // Collation - we may have requested I123 and found i123 |
|
114 | - $type = $match[2]; |
|
113 | + $xref = $match[1]; // Collation - we may have requested I123 and found i123 |
|
114 | + $type = $match[2]; |
|
115 | 115 | } elseif (preg_match('/^0 (HEAD|TRLR)/', $gedcom . $pending, $match)) { |
116 | - $xref = $match[1]; |
|
117 | - $type = $match[1]; |
|
116 | + $xref = $match[1]; |
|
117 | + $type = $match[1]; |
|
118 | 118 | } elseif ($gedcom . $pending) { |
119 | - throw new Exception('Unrecognized GEDCOM record: ' . $gedcom); |
|
119 | + throw new Exception('Unrecognized GEDCOM record: ' . $gedcom); |
|
120 | 120 | } else { |
121 | - // A record with both pending creation and pending deletion |
|
122 | - $type = static::RECORD_TYPE; |
|
121 | + // A record with both pending creation and pending deletion |
|
122 | + $type = static::RECORD_TYPE; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $factory = $this->factories[$type] ?? null; |
126 | 126 | if ($factory !== null) { |
127 | - $record = $factory->createRecord($xref, $gedcom, $pending, $tree); |
|
127 | + $record = $factory->createRecord($xref, $gedcom, $pending, $tree); |
|
128 | 128 | |
129 | - // Store it in the cache |
|
130 | - $this->gedcom_record_cache[$xref][$tree_id] = $record; |
|
129 | + // Store it in the cache |
|
130 | + $this->gedcom_record_cache[$xref][$tree_id] = $record; |
|
131 | 131 | |
132 | - return $record; |
|
132 | + return $record; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | switch ($type) { |
136 | - case 'INDI': |
|
136 | + case 'INDI': |
|
137 | 137 | $record = new Individual($xref, $gedcom, $pending, $tree); |
138 | 138 | break; |
139 | - case 'FAM': |
|
139 | + case 'FAM': |
|
140 | 140 | $record = new Family($xref, $gedcom, $pending, $tree); |
141 | 141 | break; |
142 | - case 'SOUR': |
|
142 | + case 'SOUR': |
|
143 | 143 | $record = new Source($xref, $gedcom, $pending, $tree); |
144 | 144 | break; |
145 | - case 'OBJE': |
|
145 | + case 'OBJE': |
|
146 | 146 | $record = new Media($xref, $gedcom, $pending, $tree); |
147 | 147 | break; |
148 | - case 'REPO': |
|
148 | + case 'REPO': |
|
149 | 149 | $record = new Repository($xref, $gedcom, $pending, $tree); |
150 | 150 | break; |
151 | - case 'NOTE': |
|
151 | + case 'NOTE': |
|
152 | 152 | $record = new Note($xref, $gedcom, $pending, $tree); |
153 | 153 | break; |
154 | - default: |
|
154 | + default: |
|
155 | 155 | $record = new GedcomRecord($xref, $gedcom, $pending, $tree); |
156 | 156 | break; |
157 | 157 | } |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | $this->gedcom_record_cache[$xref][$tree_id] = $record; |
161 | 161 | |
162 | 162 | return $record; |
163 | - } |
|
163 | + } |
|
164 | 164 | |
165 | - public function clearCache() { |
|
165 | + public function clearCache() { |
|
166 | 166 | // Clear the cache |
167 | 167 | $this->gedcom_record_cache = []; |
168 | 168 | $this->pending_record_cache = []; |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | 171 | } |
@@ -33,7 +33,8 @@ discard block |
||
33 | 33 | use Fisharebest\Webtrees\Source; |
34 | 34 | use stdClass; |
35 | 35 | |
36 | -class GedcomRecordFactories { |
|
36 | +class GedcomRecordFactories |
|
37 | +{ |
|
37 | 38 | |
38 | 39 | /** @var GedcomRecord[][] Allow getInstance() to return references to existing objects */ |
39 | 40 | protected $gedcom_record_cache; |
@@ -43,10 +44,12 @@ discard block |
||
43 | 44 | |
44 | 45 | protected $factories = []; |
45 | 46 | |
46 | - public function __construct() { |
|
47 | + public function __construct() |
|
48 | + { |
|
47 | 49 | } |
48 | 50 | |
49 | - public function addFactory(string $type, GedcomRecordFactory $factory) { |
|
51 | + public function addFactory(string $type, GedcomRecordFactory $factory) |
|
52 | + { |
|
50 | 53 | $this->factories[$type] = $factory; |
51 | 54 | } |
52 | 55 | |
@@ -62,7 +65,8 @@ discard block |
||
62 | 65 | * @throws Exception |
63 | 66 | * @return GedcomRecord|Individual|Family|Source|Repository|Media|Note|null |
64 | 67 | */ |
65 | - public function getInstance(string $xref, Tree $tree, string $gedcom = null) { |
|
68 | + public function getInstance(string $xref, Tree $tree, string $gedcom = null) |
|
69 | + { |
|
66 | 70 | $tree_id = $tree->id(); |
67 | 71 | |
68 | 72 | // Is this record already in the cache? |
@@ -162,7 +166,8 @@ discard block |
||
162 | 166 | return $record; |
163 | 167 | } |
164 | 168 | |
165 | - public function clearCache() { |
|
169 | + public function clearCache() |
|
170 | + { |
|
166 | 171 | // Clear the cache |
167 | 172 | $this->gedcom_record_cache = []; |
168 | 173 | $this->pending_record_cache = []; |