Passed
Push — master ( c9a927...3e5f5a )
by Greg
05:29
created

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