Passed
Push — 2.0 ( 401112...fa4b31 )
by Greg
13:39
created

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