Passed
Push — master ( dec352...b4a2f8 )
by Greg
05:56
created

Factory::submission()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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