xref: /webtrees/app/Registry.php (revision a565e135d9aa2f3d9f55f82407a0703776784d78)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees;
21
22use Fisharebest\Webtrees\Contracts\CacheFactoryInterface;
23use Fisharebest\Webtrees\Contracts\FamilyFactoryInterface;
24use Fisharebest\Webtrees\Contracts\FilesystemFactoryInterface;
25use Fisharebest\Webtrees\Contracts\ElementFactoryInterface;
26use Fisharebest\Webtrees\Contracts\GedcomRecordFactoryInterface;
27use Fisharebest\Webtrees\Contracts\HeaderFactoryInterface;
28use Fisharebest\Webtrees\Contracts\ImageFactoryInterface;
29use Fisharebest\Webtrees\Contracts\IndividualFactoryInterface;
30use Fisharebest\Webtrees\Contracts\LocationFactoryInterface;
31use Fisharebest\Webtrees\Contracts\MediaFactoryInterface;
32use Fisharebest\Webtrees\Contracts\NoteFactoryInterface;
33use Fisharebest\Webtrees\Contracts\RepositoryFactoryInterface;
34use Fisharebest\Webtrees\Contracts\SourceFactoryInterface;
35use Fisharebest\Webtrees\Contracts\SubmissionFactoryInterface;
36use Fisharebest\Webtrees\Contracts\SubmitterFactoryInterface;
37use Fisharebest\Webtrees\Contracts\XrefFactoryInterface;
38
39/**
40 * Provide access to factory objects and those that represent external entities (filesystems, caches)
41 */
42class Registry
43{
44    /** @var CacheFactoryInterface */
45    private static $cache_factory;
46
47    /** @var ElementFactoryInterface */
48    private static $element_factory;
49
50    /** @var FamilyFactoryInterface */
51    private static $family_factory;
52
53    /** @var FilesystemFactoryInterface */
54    private static $filesystem_factory;
55
56    /** @var GedcomRecordFactoryInterface */
57    private static $gedcom_record_factory;
58
59    /** @var HeaderFactoryInterface */
60    private static $header_factory;
61
62    /** @var ImageFactoryInterface */
63    private static $image_factory;
64
65    /** @var IndividualFactoryInterface */
66    private static $individual_factory;
67
68    /** @var LocationFactoryInterface */
69    private static $location_factory;
70
71    /** @var MediaFactoryInterface */
72    private static $media_factory;
73
74    /** @var NoteFactoryInterface */
75    private static $note_factory;
76
77    /** @var RepositoryFactoryInterface */
78    private static $repository_factory;
79
80    /** @var SourceFactoryInterface */
81    private static $source_factory;
82
83    /** @var SubmissionFactoryInterface */
84    private static $submission_factory;
85
86    /** @var SubmitterFactoryInterface */
87    private static $submitter_factory;
88
89    /** @var XrefFactoryInterface */
90    private static $xref_factory;
91
92    /**
93     * Store or retrieve a factory object.
94     *
95     * @param CacheFactoryInterface|null $factory
96     *
97     * @return CacheFactoryInterface
98     */
99    public static function cache(CacheFactoryInterface $factory = null): CacheFactoryInterface
100    {
101        if ($factory instanceof CacheFactoryInterface) {
102            self::$cache_factory = $factory;
103        }
104
105        return self::$cache_factory;
106    }
107
108    /**
109     * Store or retrieve a factory object.
110     *
111     * @param ElementFactoryInterface|null $factory
112     *
113     * @return ElementFactoryInterface
114     */
115    public static function elementFactory(ElementFactoryInterface $factory = null): ElementFactoryInterface
116    {
117        if ($factory instanceof ElementFactoryInterface) {
118            self::$element_factory = $factory;
119        }
120
121        return self::$element_factory;
122    }
123
124    /**
125     * Store or retrieve a factory object.
126     *
127     * @param FamilyFactoryInterface|null $factory
128     *
129     * @return FamilyFactoryInterface
130     */
131    public static function familyFactory(FamilyFactoryInterface $factory = null): FamilyFactoryInterface
132    {
133        if ($factory instanceof FamilyFactoryInterface) {
134            self::$family_factory = $factory;
135        }
136
137        return self::$family_factory;
138    }
139
140    /**
141     * Store or retrieve a factory object.
142     *
143     * @param FilesystemFactoryInterface|null $factory
144     *
145     * @return FilesystemFactoryInterface
146     */
147    public static function filesystem(FilesystemFactoryInterface $factory = null): FilesystemFactoryInterface
148    {
149        if ($factory instanceof FilesystemFactoryInterface) {
150            self::$filesystem_factory = $factory;
151        }
152
153        return self::$filesystem_factory;
154    }
155
156    /**
157     * Store or retrieve a factory object.
158     *
159     * @param GedcomRecordFactoryInterface|null $factory
160     *
161     * @return GedcomRecordFactoryInterface
162     */
163    public static function gedcomRecordFactory(GedcomRecordFactoryInterface $factory = null): GedcomRecordFactoryInterface
164    {
165        if ($factory instanceof GedcomRecordFactoryInterface) {
166            self::$gedcom_record_factory = $factory;
167        }
168
169        return self::$gedcom_record_factory;
170    }
171
172    /**
173     * Store or retrieve a factory object.
174     *
175     * @param HeaderFactoryInterface|null $factory
176     *
177     * @return HeaderFactoryInterface
178     */
179    public static function headerFactory(HeaderFactoryInterface $factory = null): HeaderFactoryInterface
180    {
181        if ($factory instanceof HeaderFactoryInterface) {
182            self::$header_factory = $factory;
183        }
184
185        return self::$header_factory;
186    }
187
188    /**
189     * Store or retrieve a factory object.
190     *
191     * @param ImageFactoryInterface|null $factory
192     *
193     * @return ImageFactoryInterface
194     */
195    public static function imageFactory(ImageFactoryInterface $factory = null): ImageFactoryInterface
196    {
197        if ($factory instanceof ImageFactoryInterface) {
198            self::$image_factory = $factory;
199        }
200
201        return self::$image_factory;
202    }
203
204    /**
205     * Store or retrieve a factory object.
206     *
207     * @param IndividualFactoryInterface|null $factory
208     *
209     * @return IndividualFactoryInterface
210     */
211    public static function individualFactory(IndividualFactoryInterface $factory = null): IndividualFactoryInterface
212    {
213        if ($factory instanceof IndividualFactoryInterface) {
214            self::$individual_factory = $factory;
215        }
216
217        return self::$individual_factory;
218    }
219
220    /**
221     * Store or retrieve a factory object.
222     *
223     * @param LocationFactoryInterface|null $factory
224     *
225     * @return LocationFactoryInterface
226     */
227    public static function locationFactory(LocationFactoryInterface $factory = null): LocationFactoryInterface
228    {
229        if ($factory instanceof LocationFactoryInterface) {
230            self::$location_factory = $factory;
231        }
232
233        return self::$location_factory;
234    }
235
236    /**
237     * Store or retrieve a factory object.
238     *
239     * @param MediaFactoryInterface|null $factory
240     *
241     * @return MediaFactoryInterface
242     */
243    public static function mediaFactory(MediaFactoryInterface $factory = null): MediaFactoryInterface
244    {
245        if ($factory instanceof MediaFactoryInterface) {
246            self::$media_factory = $factory;
247        }
248
249        return self::$media_factory;
250    }
251
252    /**
253     * Store or retrieve a factory object.
254     *
255     * @param NoteFactoryInterface|null $factory
256     *
257     * @return NoteFactoryInterface
258     */
259    public static function noteFactory(NoteFactoryInterface $factory = null): NoteFactoryInterface
260    {
261        if ($factory instanceof NoteFactoryInterface) {
262            self::$note_factory = $factory;
263        }
264
265        return self::$note_factory;
266    }
267
268    /**
269     * Store or retrieve a factory object.
270     *
271     * @param RepositoryFactoryInterface|null $factory
272     *
273     * @return RepositoryFactoryInterface
274     */
275    public static function repositoryFactory(RepositoryFactoryInterface $factory = null): RepositoryFactoryInterface
276    {
277        if ($factory instanceof RepositoryFactoryInterface) {
278            self::$repository_factory = $factory;
279        }
280
281        return self::$repository_factory;
282    }
283
284    /**
285     * Store or retrieve a factory object.
286     *
287     * @param SourceFactoryInterface|null $factory
288     *
289     * @return SourceFactoryInterface
290     */
291    public static function sourceFactory(SourceFactoryInterface $factory = null): SourceFactoryInterface
292    {
293        if ($factory instanceof SourceFactoryInterface) {
294            self::$source_factory = $factory;
295        }
296
297        return self::$source_factory;
298    }
299
300    /**
301     * Store or retrieve a factory object.
302     *
303     * @param SubmissionFactoryInterface|null $factory
304     *
305     * @return SubmissionFactoryInterface
306     */
307    public static function submissionFactory(SubmissionFactoryInterface $factory = null): SubmissionFactoryInterface
308    {
309        if ($factory instanceof SubmissionFactoryInterface) {
310            self::$submission_factory = $factory;
311        }
312
313        return self::$submission_factory;
314    }
315
316    /**
317     * Store or retrieve a factory object.
318     *
319     * @param SubmitterFactoryInterface|null $factory
320     *
321     * @return SubmitterFactoryInterface
322     */
323    public static function submitterFactory(SubmitterFactoryInterface $factory = null): SubmitterFactoryInterface
324    {
325        if ($factory instanceof SubmitterFactoryInterface) {
326            self::$submitter_factory = $factory;
327        }
328
329        return self::$submitter_factory;
330    }
331
332    /**
333     * Store or retrieve a factory object.
334     *
335     * @param XrefFactoryInterface|null $factory
336     *
337     * @return XrefFactoryInterface
338     */
339    public static function xrefFactory(XrefFactoryInterface $factory = null): XrefFactoryInterface
340    {
341        if ($factory instanceof XrefFactoryInterface) {
342            self::$xref_factory = $factory;
343        }
344
345        return self::$xref_factory;
346    }
347}
348