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