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