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