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