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