Passed
Push — master ( 933866...696755 )
by Greg
06:17
created

Factory::cache()   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
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
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
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\GedcomRecordFactoryInterface;
26
use Fisharebest\Webtrees\Contracts\HeaderFactoryInterface;
27
use Fisharebest\Webtrees\Contracts\IndividualFactoryInterface;
28
use Fisharebest\Webtrees\Contracts\LocationFactoryInterface;
29
use Fisharebest\Webtrees\Contracts\MediaFactoryInterface;
30
use Fisharebest\Webtrees\Contracts\NoteFactoryInterface;
31
use Fisharebest\Webtrees\Contracts\RepositoryFactoryInterface;
32
use Fisharebest\Webtrees\Contracts\SourceFactoryInterface;
33
use Fisharebest\Webtrees\Contracts\SubmissionFactoryInterface;
34
use Fisharebest\Webtrees\Contracts\SubmitterFactoryInterface;
35
use Fisharebest\Webtrees\Contracts\XrefFactoryInterface;
36
37
/**
38
 * A service locator for our various factory objects.
39
 */
40
class Factory
41
{
42
    /** @var CacheFactoryInterface */
43
    private static $cache_factory;
44
45
    /** @var FamilyFactoryInterface */
46
    private static $family_factory;
47
48
    /** @var FilesystemFactoryInterface */
49
    private static $filesystem_factory;
50
51
    /** @var GedcomRecordFactoryInterface */
52
    private static $gedcom_record_factory;
53
54
    /** @var HeaderFactoryInterface */
55
    private static $header_factory;
56
57
    /** @var IndividualFactoryInterface */
58
    private static $individual_factory;
59
60
    /** @var LocationFactoryInterface */
61
    private static $location_factory;
62
63
    /** @var MediaFactoryInterface */
64
    private static $media_factory;
65
66
    /** @var NoteFactoryInterface */
67
    private static $note_factory;
68
69
    /** @var RepositoryFactoryInterface */
70
    private static $repository_factory;
71
72
    /** @var SourceFactoryInterface */
73
    private static $source_factory;
74
75
    /** @var SubmissionFactoryInterface */
76
    private static $submission_factory;
77
78
    /** @var SubmitterFactoryInterface */
79
    private static $submitter_factory;
80
81
    /** @var XrefFactoryInterface */
82
    private static $xref_factory;
83
84
    /**
85
     * Store or retrieve a factory object.
86
     *
87
     * @param CacheFactoryInterface|null $factory
88
     *
89
     * @return CacheFactoryInterface
90
     */
91
    public static function cache(CacheFactoryInterface $factory = null): CacheFactoryInterface
92
    {
93
        if ($factory instanceof CacheFactoryInterface) {
94
            self::$cache_factory = $factory;
95
        }
96
97
        return self::$cache_factory;
98
    }
99
100
    /**
101
     * Store or retrieve a factory object.
102
     *
103
     * @param FamilyFactoryInterface|null $factory
104
     *
105
     * @return FamilyFactoryInterface
106
     */
107
    public static function family(FamilyFactoryInterface $factory = null): FamilyFactoryInterface
108
    {
109
        if ($factory instanceof FamilyFactoryInterface) {
110
            self::$family_factory = $factory;
111
        }
112
113
        return self::$family_factory;
114
    }
115
116
    /**
117
     * Store or retrieve a factory object.
118
     *
119
     * @param FilesystemFactoryInterface|null $factory
120
     *
121
     * @return FilesystemFactoryInterface
122
     */
123
    public static function filesystem(FilesystemFactoryInterface $factory = null): FilesystemFactoryInterface
124
    {
125
        if ($factory instanceof FilesystemFactoryInterface) {
126
            self::$filesystem_factory = $factory;
127
        }
128
129
        return self::$filesystem_factory;
130
    }
131
132
    /**
133
     * Store or retrieve a factory object.
134
     *
135
     * @param GedcomRecordFactoryInterface|null $factory
136
     *
137
     * @return GedcomRecordFactoryInterface
138
     */
139
    public static function gedcomRecord(GedcomRecordFactoryInterface $factory = null): GedcomRecordFactoryInterface
140
    {
141
        if ($factory instanceof GedcomRecordFactoryInterface) {
142
            self::$gedcom_record_factory = $factory;
143
        }
144
145
        return self::$gedcom_record_factory;
146
    }
147
148
    /**
149
     * Store or retrieve a factory object.
150
     *
151
     * @param HeaderFactoryInterface|null $factory
152
     *
153
     * @return HeaderFactoryInterface
154
     */
155
    public static function header(HeaderFactoryInterface $factory = null): HeaderFactoryInterface
156
    {
157
        if ($factory instanceof HeaderFactoryInterface) {
158
            self::$header_factory = $factory;
159
        }
160
161
        return self::$header_factory;
162
    }
163
164
    /**
165
     * Store or retrieve a factory object.
166
     *
167
     * @param IndividualFactoryInterface|null $factory
168
     *
169
     * @return IndividualFactoryInterface
170
     */
171
    public static function individual(IndividualFactoryInterface $factory = null): IndividualFactoryInterface
172
    {
173
        if ($factory instanceof IndividualFactoryInterface) {
174
            self::$individual_factory = $factory;
175
        }
176
177
        return self::$individual_factory;
178
    }
179
180
    /**
181
     * Store or retrieve a factory object.
182
     *
183
     * @param LocationFactoryInterface|null $factory
184
     *
185
     * @return LocationFactoryInterface
186
     */
187
    public static function location(LocationFactoryInterface $factory = null): LocationFactoryInterface
188
    {
189
        if ($factory instanceof LocationFactoryInterface) {
190
            self::$location_factory = $factory;
191
        }
192
193
        return self::$location_factory;
194
    }
195
196
    /**
197
     * Store or retrieve a factory object.
198
     *
199
     * @param MediaFactoryInterface|null $factory
200
     *
201
     * @return MediaFactoryInterface
202
     */
203
    public static function media(MediaFactoryInterface $factory = null): MediaFactoryInterface
204
    {
205
        if ($factory instanceof MediaFactoryInterface) {
206
            self::$media_factory = $factory;
207
        }
208
209
        return self::$media_factory;
210
    }
211
212
    /**
213
     * Store or retrieve a factory object.
214
     *
215
     * @param NoteFactoryInterface|null $factory
216
     *
217
     * @return NoteFactoryInterface
218
     */
219
    public static function note(NoteFactoryInterface $factory = null): NoteFactoryInterface
220
    {
221
        if ($factory instanceof NoteFactoryInterface) {
222
            self::$note_factory = $factory;
223
        }
224
225
        return self::$note_factory;
226
    }
227
228
    /**
229
     * Store or retrieve a factory object.
230
     *
231
     * @param RepositoryFactoryInterface|null $factory
232
     *
233
     * @return RepositoryFactoryInterface
234
     */
235
    public static function repository(RepositoryFactoryInterface $factory = null): RepositoryFactoryInterface
236
    {
237
        if ($factory instanceof RepositoryFactoryInterface) {
238
            self::$repository_factory = $factory;
239
        }
240
241
        return self::$repository_factory;
242
    }
243
244
    /**
245
     * Store or retrieve a factory object.
246
     *
247
     * @param SourceFactoryInterface|null $factory
248
     *
249
     * @return SourceFactoryInterface
250
     */
251
    public static function source(SourceFactoryInterface $factory = null): SourceFactoryInterface
252
    {
253
        if ($factory instanceof SourceFactoryInterface) {
254
            self::$source_factory = $factory;
255
        }
256
257
        return self::$source_factory;
258
    }
259
260
    /**
261
     * Store or retrieve a factory object.
262
     *
263
     * @param SubmissionFactoryInterface|null $factory
264
     *
265
     * @return SubmissionFactoryInterface
266
     */
267
    public static function submission(SubmissionFactoryInterface $factory = null): SubmissionFactoryInterface
268
    {
269
        if ($factory instanceof SubmissionFactoryInterface) {
270
            self::$submission_factory = $factory;
271
        }
272
273
        return self::$submission_factory;
274
    }
275
276
    /**
277
     * Store or retrieve a factory object.
278
     *
279
     * @param SubmitterFactoryInterface|null $factory
280
     *
281
     * @return SubmitterFactoryInterface
282
     */
283
    public static function submitter(SubmitterFactoryInterface $factory = null): SubmitterFactoryInterface
284
    {
285
        if ($factory instanceof SubmitterFactoryInterface) {
286
            self::$submitter_factory = $factory;
287
        }
288
289
        return self::$submitter_factory;
290
    }
291
292
    /**
293
     * Store or retrieve a factory object.
294
     *
295
     * @param XrefFactoryInterface|null $factory
296
     *
297
     * @return XrefFactoryInterface
298
     */
299
    public static function xref(XrefFactoryInterface $factory = null): XrefFactoryInterface
300
    {
301
        if ($factory instanceof XrefFactoryInterface) {
302
            self::$xref_factory = $factory;
303
        }
304
305
        return self::$xref_factory;
306
    }
307
}
308