Passed
Push — 2.0 ( 0f9198...c8a95e )
by Greg
06:29
created

Registry::locationFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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