xref: /webtrees/app/Registry.php (revision 701f5d180b85b9d3e0747b6ddc9e9d64dd73d0d6)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 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\CalendarDateFactoryInterface;
24use Fisharebest\Webtrees\Contracts\EncodingFactoryInterface;
25use Fisharebest\Webtrees\Contracts\FamilyFactoryInterface;
26use Fisharebest\Webtrees\Contracts\FilesystemFactoryInterface;
27use Fisharebest\Webtrees\Contracts\ElementFactoryInterface;
28use Fisharebest\Webtrees\Contracts\GedcomRecordFactoryInterface;
29use Fisharebest\Webtrees\Contracts\HeaderFactoryInterface;
30use Fisharebest\Webtrees\Contracts\ImageFactoryInterface;
31use Fisharebest\Webtrees\Contracts\IndividualFactoryInterface;
32use Fisharebest\Webtrees\Contracts\LocationFactoryInterface;
33use Fisharebest\Webtrees\Contracts\MarkdownFactoryInterface;
34use Fisharebest\Webtrees\Contracts\MediaFactoryInterface;
35use Fisharebest\Webtrees\Contracts\NoteFactoryInterface;
36use Fisharebest\Webtrees\Contracts\RepositoryFactoryInterface;
37use Fisharebest\Webtrees\Contracts\ResponseFactoryInterface;
38use Fisharebest\Webtrees\Contracts\RouteFactoryInterface;
39use Fisharebest\Webtrees\Contracts\SharedNoteFactoryInterface;
40use Fisharebest\Webtrees\Contracts\SlugFactoryInterface;
41use Fisharebest\Webtrees\Contracts\SourceFactoryInterface;
42use Fisharebest\Webtrees\Contracts\SubmissionFactoryInterface;
43use Fisharebest\Webtrees\Contracts\SubmitterFactoryInterface;
44use Fisharebest\Webtrees\Contracts\SurnameTraditionFactoryInterface;
45use Fisharebest\Webtrees\Contracts\TimestampFactoryInterface;
46use Fisharebest\Webtrees\Contracts\XrefFactoryInterface;
47
48/**
49 * Provide access to factory objects and those that represent external entities (filesystems, caches)
50 */
51class Registry
52{
53    private static CacheFactoryInterface $cache_factory;
54
55    private static CalendarDateFactoryInterface $calendar_date_factory;
56
57    private static ElementFactoryInterface $element_factory;
58
59    private static EncodingFactoryInterface $encoding_factory;
60
61    private static FamilyFactoryInterface $family_factory;
62
63    private static FilesystemFactoryInterface $filesystem_factory;
64
65    private static GedcomRecordFactoryInterface $gedcom_record_factory;
66
67    private static HeaderFactoryInterface $header_factory;
68
69    private static ImageFactoryInterface $image_factory;
70
71    private static IndividualFactoryInterface $individual_factory;
72
73    private static LocationFactoryInterface $location_factory;
74
75    private static MarkdownFactoryInterface $markdown_factory;
76
77    private static MediaFactoryInterface $media_factory;
78
79    private static NoteFactoryInterface $note_factory;
80
81    private static RepositoryFactoryInterface $repository_factory;
82
83    private static ResponseFactoryInterface $response_factory;
84
85    private static RouteFactoryInterface $route_factory;
86
87    private static SharedNoteFactoryInterface $shared_note_factory;
88
89    private static SlugFactoryInterface $slug_factory;
90
91    private static SourceFactoryInterface $source_factory;
92
93    private static SubmissionFactoryInterface $submission_factory;
94
95    private static SubmitterFactoryInterface $submitter_factory;
96
97    private static SurnameTraditionFactoryInterface $surname_tradition_factory;
98
99    private static TimestampFactoryInterface $timestamp_factory;
100
101    private static XrefFactoryInterface $xref_factory;
102
103    /**
104     * Store or retrieve a factory object.
105     *
106     * @param CacheFactoryInterface|null $factory
107     *
108     * @return CacheFactoryInterface
109     */
110    public static function cache(CacheFactoryInterface $factory = null): CacheFactoryInterface
111    {
112        if ($factory instanceof CacheFactoryInterface) {
113            self::$cache_factory = $factory;
114        }
115
116        return self::$cache_factory;
117    }
118
119    /**
120     * Store or retrieve a factory object.
121     *
122     * @param CalendarDateFactoryInterface|null $factory
123     *
124     * @return CalendarDateFactoryInterface
125     */
126    public static function calendarDateFactory(CalendarDateFactoryInterface $factory = null): CalendarDateFactoryInterface
127    {
128        if ($factory instanceof CalendarDateFactoryInterface) {
129            self::$calendar_date_factory = $factory;
130        }
131
132        return self::$calendar_date_factory;
133    }
134
135    /**
136     * Store or retrieve a factory object.
137     *
138     * @param ElementFactoryInterface|null $factory
139     *
140     * @return ElementFactoryInterface
141     */
142    public static function elementFactory(ElementFactoryInterface $factory = null): ElementFactoryInterface
143    {
144        if ($factory instanceof ElementFactoryInterface) {
145            self::$element_factory = $factory;
146        }
147
148        return self::$element_factory;
149    }
150
151    /**
152     * Store or retrieve a factory object.
153     *
154     * @param EncodingFactoryInterface|null $factory
155     *
156     * @return EncodingFactoryInterface
157     */
158    public static function encodingFactory(EncodingFactoryInterface $factory = null): EncodingFactoryInterface
159    {
160        if ($factory instanceof EncodingFactoryInterface) {
161            self::$encoding_factory = $factory;
162        }
163
164        return self::$encoding_factory;
165    }
166
167    /**
168     * Store or retrieve a factory object.
169     *
170     * @param FamilyFactoryInterface|null $factory
171     *
172     * @return FamilyFactoryInterface
173     */
174    public static function familyFactory(FamilyFactoryInterface $factory = null): FamilyFactoryInterface
175    {
176        if ($factory instanceof FamilyFactoryInterface) {
177            self::$family_factory = $factory;
178        }
179
180        return self::$family_factory;
181    }
182
183    /**
184     * Store or retrieve a factory object.
185     *
186     * @param FilesystemFactoryInterface|null $factory
187     *
188     * @return FilesystemFactoryInterface
189     */
190    public static function filesystem(FilesystemFactoryInterface $factory = null): FilesystemFactoryInterface
191    {
192        if ($factory instanceof FilesystemFactoryInterface) {
193            self::$filesystem_factory = $factory;
194        }
195
196        return self::$filesystem_factory;
197    }
198
199    /**
200     * Store or retrieve a factory object.
201     *
202     * @param GedcomRecordFactoryInterface|null $factory
203     *
204     * @return GedcomRecordFactoryInterface
205     */
206    public static function gedcomRecordFactory(GedcomRecordFactoryInterface $factory = null): GedcomRecordFactoryInterface
207    {
208        if ($factory instanceof GedcomRecordFactoryInterface) {
209            self::$gedcom_record_factory = $factory;
210        }
211
212        return self::$gedcom_record_factory;
213    }
214
215    /**
216     * Store or retrieve a factory object.
217     *
218     * @param HeaderFactoryInterface|null $factory
219     *
220     * @return HeaderFactoryInterface
221     */
222    public static function headerFactory(HeaderFactoryInterface $factory = null): HeaderFactoryInterface
223    {
224        if ($factory instanceof HeaderFactoryInterface) {
225            self::$header_factory = $factory;
226        }
227
228        return self::$header_factory;
229    }
230
231    /**
232     * Store or retrieve a factory object.
233     *
234     * @param ImageFactoryInterface|null $factory
235     *
236     * @return ImageFactoryInterface
237     */
238    public static function imageFactory(ImageFactoryInterface $factory = null): ImageFactoryInterface
239    {
240        if ($factory instanceof ImageFactoryInterface) {
241            self::$image_factory = $factory;
242        }
243
244        return self::$image_factory;
245    }
246
247    /**
248     * Store or retrieve a factory object.
249     *
250     * @param IndividualFactoryInterface|null $factory
251     *
252     * @return IndividualFactoryInterface
253     */
254    public static function individualFactory(IndividualFactoryInterface $factory = null): IndividualFactoryInterface
255    {
256        if ($factory instanceof IndividualFactoryInterface) {
257            self::$individual_factory = $factory;
258        }
259
260        return self::$individual_factory;
261    }
262
263    /**
264     * Store or retrieve a factory object.
265     *
266     * @param LocationFactoryInterface|null $factory
267     *
268     * @return LocationFactoryInterface
269     */
270    public static function locationFactory(LocationFactoryInterface $factory = null): LocationFactoryInterface
271    {
272        if ($factory instanceof LocationFactoryInterface) {
273            self::$location_factory = $factory;
274        }
275
276        return self::$location_factory;
277    }
278
279    /**
280     * Store or retrieve a factory object.
281     *
282     * @param MarkdownFactoryInterface|null $factory
283     *
284     * @return MarkdownFactoryInterface
285     */
286    public static function markdownFactory(MarkdownFactoryInterface $factory = null): MarkdownFactoryInterface
287    {
288        if ($factory instanceof MarkdownFactoryInterface) {
289            self::$markdown_factory = $factory;
290        }
291
292        return self::$markdown_factory;
293    }
294
295    /**
296     * Store or retrieve a factory object.
297     *
298     * @param MediaFactoryInterface|null $factory
299     *
300     * @return MediaFactoryInterface
301     */
302    public static function mediaFactory(MediaFactoryInterface $factory = null): MediaFactoryInterface
303    {
304        if ($factory instanceof MediaFactoryInterface) {
305            self::$media_factory = $factory;
306        }
307
308        return self::$media_factory;
309    }
310
311    /**
312     * Store or retrieve a factory object.
313     *
314     * @param NoteFactoryInterface|null $factory
315     *
316     * @return NoteFactoryInterface
317     */
318    public static function noteFactory(NoteFactoryInterface $factory = null): NoteFactoryInterface
319    {
320        if ($factory instanceof NoteFactoryInterface) {
321            self::$note_factory = $factory;
322        }
323
324        return self::$note_factory;
325    }
326
327    /**
328     * Store or retrieve a factory object.
329     *
330     * @param RepositoryFactoryInterface|null $factory
331     *
332     * @return RepositoryFactoryInterface
333     */
334    public static function repositoryFactory(RepositoryFactoryInterface $factory = null): RepositoryFactoryInterface
335    {
336        if ($factory instanceof RepositoryFactoryInterface) {
337            self::$repository_factory = $factory;
338        }
339
340        return self::$repository_factory;
341    }
342
343    /**
344     * Store or retrieve a factory object.
345     *
346     * @param ResponseFactoryInterface|null $factory
347     *
348     * @return ResponseFactoryInterface
349     */
350    public static function responseFactory(ResponseFactoryInterface $factory = null): ResponseFactoryInterface
351    {
352        if ($factory instanceof ResponseFactoryInterface) {
353            self::$response_factory = $factory;
354        }
355
356        return self::$response_factory;
357    }
358
359    /**
360     * Store or retrieve a factory object.
361     *
362     * @param RouteFactoryInterface|null $factory
363     *
364     * @return RouteFactoryInterface
365     */
366    public static function routeFactory(RouteFactoryInterface $factory = null): RouteFactoryInterface
367    {
368        if ($factory instanceof RouteFactoryInterface) {
369            self::$route_factory = $factory;
370        }
371
372        return self::$route_factory;
373    }
374
375    /**
376     * Store or retrieve a factory object.
377     *
378     * @param SharedNoteFactoryInterface|null $factory
379     *
380     * @return SharedNoteFactoryInterface
381     */
382    public static function sharedNoteFactory(SharedNoteFactoryInterface $factory = null): SharedNoteFactoryInterface
383    {
384        if ($factory instanceof SharedNoteFactoryInterface) {
385            self::$shared_note_factory = $factory;
386        }
387
388        return self::$shared_note_factory;
389    }
390
391    /**
392     * Store or retrieve a factory object.
393     *
394     * @param SlugFactoryInterface|null $factory
395     *
396     * @return SlugFactoryInterface
397     */
398    public static function slugFactory(SlugFactoryInterface $factory = null): SlugFactoryInterface
399    {
400        if ($factory instanceof SlugFactoryInterface) {
401            self::$slug_factory = $factory;
402        }
403
404        return self::$slug_factory;
405    }
406
407    /**
408     * Store or retrieve a factory object.
409     *
410     * @param SourceFactoryInterface|null $factory
411     *
412     * @return SourceFactoryInterface
413     */
414    public static function sourceFactory(SourceFactoryInterface $factory = null): SourceFactoryInterface
415    {
416        if ($factory instanceof SourceFactoryInterface) {
417            self::$source_factory = $factory;
418        }
419
420        return self::$source_factory;
421    }
422
423    /**
424     * Store or retrieve a factory object.
425     *
426     * @param SubmissionFactoryInterface|null $factory
427     *
428     * @return SubmissionFactoryInterface
429     */
430    public static function submissionFactory(SubmissionFactoryInterface $factory = null): SubmissionFactoryInterface
431    {
432        if ($factory instanceof SubmissionFactoryInterface) {
433            self::$submission_factory = $factory;
434        }
435
436        return self::$submission_factory;
437    }
438
439    /**
440     * Store or retrieve a factory object.
441     *
442     * @param SubmitterFactoryInterface|null $factory
443     *
444     * @return SubmitterFactoryInterface
445     */
446    public static function submitterFactory(SubmitterFactoryInterface $factory = null): SubmitterFactoryInterface
447    {
448        if ($factory instanceof SubmitterFactoryInterface) {
449            self::$submitter_factory = $factory;
450        }
451
452        return self::$submitter_factory;
453    }
454
455    /**
456     * Store or retrieve a factory object.
457     *
458     * @param SurnameTraditionFactoryInterface|null $factory
459     *
460     * @return SurnameTraditionFactoryInterface
461     */
462    public static function surnameTraditionFactory(SurnameTraditionFactoryInterface $factory = null): SurnameTraditionFactoryInterface
463    {
464        if ($factory instanceof SurnameTraditionFactoryInterface) {
465            self::$surname_tradition_factory = $factory;
466        }
467
468        return self::$surname_tradition_factory;
469    }
470
471    /**
472     * Store or retrieve a factory object.
473     *
474     * @param TimestampFactoryInterface|null $factory
475     *
476     * @return TimestampFactoryInterface
477     */
478    public static function timestampFactory(TimestampFactoryInterface $factory = null): TimestampFactoryInterface
479    {
480        if ($factory instanceof TimestampFactoryInterface) {
481            self::$timestamp_factory = $factory;
482        }
483
484        return self::$timestamp_factory;
485    }
486
487    /**
488     * Store or retrieve a factory object.
489     *
490     * @param XrefFactoryInterface|null $factory
491     *
492     * @return XrefFactoryInterface
493     */
494    public static function xrefFactory(XrefFactoryInterface $factory = null): XrefFactoryInterface
495    {
496        if ($factory instanceof XrefFactoryInterface) {
497            self::$xref_factory = $factory;
498        }
499
500        return self::$xref_factory;
501    }
502}
503