Passed
Push — master ( 654721...0d1553 )
by Greg
04:53
created

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