1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2022 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\ResponseFactoryInterface; 38use Fisharebest\Webtrees\Contracts\RouteFactoryInterface; 39use Fisharebest\Webtrees\Contracts\SharedNoteFactoryInterface; 40use Fisharebest\Webtrees\Contracts\SlugFactoryInterface; 41use Fisharebest\Webtrees\Contracts\SourceFactoryInterface; 42use Fisharebest\Webtrees\Contracts\SubmissionFactoryInterface; 43use Fisharebest\Webtrees\Contracts\SubmitterFactoryInterface; 44use Fisharebest\Webtrees\Contracts\SurnameTraditionFactoryInterface; 45use Fisharebest\Webtrees\Contracts\TimestampFactoryInterface; 46use Fisharebest\Webtrees\Contracts\IdFactoryInterface; 47use Fisharebest\Webtrees\Contracts\XrefFactoryInterface; 48 49/** 50 * Provide access to factory objects and those that represent external entities (filesystems, caches) 51 */ 52class Registry 53{ 54 private static CacheFactoryInterface $cache_factory; 55 56 private static CalendarDateFactoryInterface $calendar_date_factory; 57 58 private static ElementFactoryInterface $element_factory; 59 60 private static EncodingFactoryInterface $encoding_factory; 61 62 private static FamilyFactoryInterface $family_factory; 63 64 private static FilesystemFactoryInterface $filesystem_factory; 65 66 private static GedcomRecordFactoryInterface $gedcom_record_factory; 67 68 private static HeaderFactoryInterface $header_factory; 69 70 private static IdFactoryInterface $id_factory; 71 72 private static ImageFactoryInterface $image_factory; 73 74 private static IndividualFactoryInterface $individual_factory; 75 76 private static LocationFactoryInterface $location_factory; 77 78 private static MarkdownFactoryInterface $markdown_factory; 79 80 private static MediaFactoryInterface $media_factory; 81 82 private static NoteFactoryInterface $note_factory; 83 84 private static RepositoryFactoryInterface $repository_factory; 85 86 private static ResponseFactoryInterface $response_factory; 87 88 private static RouteFactoryInterface $route_factory; 89 90 private static SharedNoteFactoryInterface $shared_note_factory; 91 92 private static SlugFactoryInterface $slug_factory; 93 94 private static SourceFactoryInterface $source_factory; 95 96 private static SubmissionFactoryInterface $submission_factory; 97 98 private static SubmitterFactoryInterface $submitter_factory; 99 100 private static SurnameTraditionFactoryInterface $surname_tradition_factory; 101 102 private static TimestampFactoryInterface $timestamp_factory; 103 104 private static XrefFactoryInterface $xref_factory; 105 106 /** 107 * Store or retrieve a factory object. 108 * 109 * @param CacheFactoryInterface|null $factory 110 * 111 * @return CacheFactoryInterface 112 */ 113 public static function cache(CacheFactoryInterface $factory = null): CacheFactoryInterface 114 { 115 if ($factory instanceof CacheFactoryInterface) { 116 self::$cache_factory = $factory; 117 } 118 119 return self::$cache_factory; 120 } 121 122 /** 123 * Store or retrieve a factory object. 124 * 125 * @param CalendarDateFactoryInterface|null $factory 126 * 127 * @return CalendarDateFactoryInterface 128 */ 129 public static function calendarDateFactory(CalendarDateFactoryInterface $factory = null): CalendarDateFactoryInterface 130 { 131 if ($factory instanceof CalendarDateFactoryInterface) { 132 self::$calendar_date_factory = $factory; 133 } 134 135 return self::$calendar_date_factory; 136 } 137 138 /** 139 * Store or retrieve a factory object. 140 * 141 * @param ElementFactoryInterface|null $factory 142 * 143 * @return ElementFactoryInterface 144 */ 145 public static function elementFactory(ElementFactoryInterface $factory = null): ElementFactoryInterface 146 { 147 if ($factory instanceof ElementFactoryInterface) { 148 self::$element_factory = $factory; 149 } 150 151 return self::$element_factory; 152 } 153 154 /** 155 * Store or retrieve a factory object. 156 * 157 * @param EncodingFactoryInterface|null $factory 158 * 159 * @return EncodingFactoryInterface 160 */ 161 public static function encodingFactory(EncodingFactoryInterface $factory = null): EncodingFactoryInterface 162 { 163 if ($factory instanceof EncodingFactoryInterface) { 164 self::$encoding_factory = $factory; 165 } 166 167 return self::$encoding_factory; 168 } 169 170 /** 171 * Store or retrieve a factory object. 172 * 173 * @param FamilyFactoryInterface|null $factory 174 * 175 * @return FamilyFactoryInterface 176 */ 177 public static function familyFactory(FamilyFactoryInterface $factory = null): FamilyFactoryInterface 178 { 179 if ($factory instanceof FamilyFactoryInterface) { 180 self::$family_factory = $factory; 181 } 182 183 return self::$family_factory; 184 } 185 186 /** 187 * Store or retrieve a factory object. 188 * 189 * @param FilesystemFactoryInterface|null $factory 190 * 191 * @return FilesystemFactoryInterface 192 */ 193 public static function filesystem(FilesystemFactoryInterface $factory = null): FilesystemFactoryInterface 194 { 195 if ($factory instanceof FilesystemFactoryInterface) { 196 self::$filesystem_factory = $factory; 197 } 198 199 return self::$filesystem_factory; 200 } 201 202 /** 203 * Store or retrieve a factory object. 204 * 205 * @param GedcomRecordFactoryInterface|null $factory 206 * 207 * @return GedcomRecordFactoryInterface 208 */ 209 public static function gedcomRecordFactory(GedcomRecordFactoryInterface $factory = null): GedcomRecordFactoryInterface 210 { 211 if ($factory instanceof GedcomRecordFactoryInterface) { 212 self::$gedcom_record_factory = $factory; 213 } 214 215 return self::$gedcom_record_factory; 216 } 217 218 /** 219 * Store or retrieve a factory object. 220 * 221 * @param HeaderFactoryInterface|null $factory 222 * 223 * @return HeaderFactoryInterface 224 */ 225 public static function headerFactory(HeaderFactoryInterface $factory = null): HeaderFactoryInterface 226 { 227 if ($factory instanceof HeaderFactoryInterface) { 228 self::$header_factory = $factory; 229 } 230 231 return self::$header_factory; 232 } 233 234 /** 235 * Store or retrieve a factory object. 236 * 237 * @param IdFactoryInterface|null $factory 238 * 239 * @return IdFactoryInterface 240 */ 241 public static function idFactory(IdFactoryInterface $factory = null): IdFactoryInterface 242 { 243 if ($factory instanceof IdFactoryInterface) { 244 self::$id_factory = $factory; 245 } 246 247 return self::$id_factory; 248 } 249 250 /** 251 * Store or retrieve a factory object. 252 * 253 * @param ImageFactoryInterface|null $factory 254 * 255 * @return ImageFactoryInterface 256 */ 257 public static function imageFactory(ImageFactoryInterface $factory = null): ImageFactoryInterface 258 { 259 if ($factory instanceof ImageFactoryInterface) { 260 self::$image_factory = $factory; 261 } 262 263 return self::$image_factory; 264 } 265 266 /** 267 * Store or retrieve a factory object. 268 * 269 * @param IndividualFactoryInterface|null $factory 270 * 271 * @return IndividualFactoryInterface 272 */ 273 public static function individualFactory(IndividualFactoryInterface $factory = null): IndividualFactoryInterface 274 { 275 if ($factory instanceof IndividualFactoryInterface) { 276 self::$individual_factory = $factory; 277 } 278 279 return self::$individual_factory; 280 } 281 282 /** 283 * Store or retrieve a factory object. 284 * 285 * @param LocationFactoryInterface|null $factory 286 * 287 * @return LocationFactoryInterface 288 */ 289 public static function locationFactory(LocationFactoryInterface $factory = null): LocationFactoryInterface 290 { 291 if ($factory instanceof LocationFactoryInterface) { 292 self::$location_factory = $factory; 293 } 294 295 return self::$location_factory; 296 } 297 298 /** 299 * Store or retrieve a factory object. 300 * 301 * @param MarkdownFactoryInterface|null $factory 302 * 303 * @return MarkdownFactoryInterface 304 */ 305 public static function markdownFactory(MarkdownFactoryInterface $factory = null): MarkdownFactoryInterface 306 { 307 if ($factory instanceof MarkdownFactoryInterface) { 308 self::$markdown_factory = $factory; 309 } 310 311 return self::$markdown_factory; 312 } 313 314 /** 315 * Store or retrieve a factory object. 316 * 317 * @param MediaFactoryInterface|null $factory 318 * 319 * @return MediaFactoryInterface 320 */ 321 public static function mediaFactory(MediaFactoryInterface $factory = null): MediaFactoryInterface 322 { 323 if ($factory instanceof MediaFactoryInterface) { 324 self::$media_factory = $factory; 325 } 326 327 return self::$media_factory; 328 } 329 330 /** 331 * Store or retrieve a factory object. 332 * 333 * @param NoteFactoryInterface|null $factory 334 * 335 * @return NoteFactoryInterface 336 */ 337 public static function noteFactory(NoteFactoryInterface $factory = null): NoteFactoryInterface 338 { 339 if ($factory instanceof NoteFactoryInterface) { 340 self::$note_factory = $factory; 341 } 342 343 return self::$note_factory; 344 } 345 346 /** 347 * Store or retrieve a factory object. 348 * 349 * @param RepositoryFactoryInterface|null $factory 350 * 351 * @return RepositoryFactoryInterface 352 */ 353 public static function repositoryFactory(RepositoryFactoryInterface $factory = null): RepositoryFactoryInterface 354 { 355 if ($factory instanceof RepositoryFactoryInterface) { 356 self::$repository_factory = $factory; 357 } 358 359 return self::$repository_factory; 360 } 361 362 /** 363 * Store or retrieve a factory object. 364 * 365 * @param ResponseFactoryInterface|null $factory 366 * 367 * @return ResponseFactoryInterface 368 */ 369 public static function responseFactory(ResponseFactoryInterface $factory = null): ResponseFactoryInterface 370 { 371 if ($factory instanceof ResponseFactoryInterface) { 372 self::$response_factory = $factory; 373 } 374 375 return self::$response_factory; 376 } 377 378 /** 379 * Store or retrieve a factory object. 380 * 381 * @param RouteFactoryInterface|null $factory 382 * 383 * @return RouteFactoryInterface 384 */ 385 public static function routeFactory(RouteFactoryInterface $factory = null): RouteFactoryInterface 386 { 387 if ($factory instanceof RouteFactoryInterface) { 388 self::$route_factory = $factory; 389 } 390 391 return self::$route_factory; 392 } 393 394 /** 395 * Store or retrieve a factory object. 396 * 397 * @param SharedNoteFactoryInterface|null $factory 398 * 399 * @return SharedNoteFactoryInterface 400 */ 401 public static function sharedNoteFactory(SharedNoteFactoryInterface $factory = null): SharedNoteFactoryInterface 402 { 403 if ($factory instanceof SharedNoteFactoryInterface) { 404 self::$shared_note_factory = $factory; 405 } 406 407 return self::$shared_note_factory; 408 } 409 410 /** 411 * Store or retrieve a factory object. 412 * 413 * @param SlugFactoryInterface|null $factory 414 * 415 * @return SlugFactoryInterface 416 */ 417 public static function slugFactory(SlugFactoryInterface $factory = null): SlugFactoryInterface 418 { 419 if ($factory instanceof SlugFactoryInterface) { 420 self::$slug_factory = $factory; 421 } 422 423 return self::$slug_factory; 424 } 425 426 /** 427 * Store or retrieve a factory object. 428 * 429 * @param SourceFactoryInterface|null $factory 430 * 431 * @return SourceFactoryInterface 432 */ 433 public static function sourceFactory(SourceFactoryInterface $factory = null): SourceFactoryInterface 434 { 435 if ($factory instanceof SourceFactoryInterface) { 436 self::$source_factory = $factory; 437 } 438 439 return self::$source_factory; 440 } 441 442 /** 443 * Store or retrieve a factory object. 444 * 445 * @param SubmissionFactoryInterface|null $factory 446 * 447 * @return SubmissionFactoryInterface 448 */ 449 public static function submissionFactory(SubmissionFactoryInterface $factory = null): SubmissionFactoryInterface 450 { 451 if ($factory instanceof SubmissionFactoryInterface) { 452 self::$submission_factory = $factory; 453 } 454 455 return self::$submission_factory; 456 } 457 458 /** 459 * Store or retrieve a factory object. 460 * 461 * @param SubmitterFactoryInterface|null $factory 462 * 463 * @return SubmitterFactoryInterface 464 */ 465 public static function submitterFactory(SubmitterFactoryInterface $factory = null): SubmitterFactoryInterface 466 { 467 if ($factory instanceof SubmitterFactoryInterface) { 468 self::$submitter_factory = $factory; 469 } 470 471 return self::$submitter_factory; 472 } 473 474 /** 475 * Store or retrieve a factory object. 476 * 477 * @param SurnameTraditionFactoryInterface|null $factory 478 * 479 * @return SurnameTraditionFactoryInterface 480 */ 481 public static function surnameTraditionFactory(SurnameTraditionFactoryInterface $factory = null): SurnameTraditionFactoryInterface 482 { 483 if ($factory instanceof SurnameTraditionFactoryInterface) { 484 self::$surname_tradition_factory = $factory; 485 } 486 487 return self::$surname_tradition_factory; 488 } 489 490 /** 491 * Store or retrieve a factory object. 492 * 493 * @param TimestampFactoryInterface|null $factory 494 * 495 * @return TimestampFactoryInterface 496 */ 497 public static function timestampFactory(TimestampFactoryInterface $factory = null): TimestampFactoryInterface 498 { 499 if ($factory instanceof TimestampFactoryInterface) { 500 self::$timestamp_factory = $factory; 501 } 502 503 return self::$timestamp_factory; 504 } 505 506 /** 507 * Store or retrieve a factory object. 508 * 509 * @param XrefFactoryInterface|null $factory 510 * 511 * @return XrefFactoryInterface 512 */ 513 public static function xrefFactory(XrefFactoryInterface $factory = null): XrefFactoryInterface 514 { 515 if ($factory instanceof XrefFactoryInterface) { 516 self::$xref_factory = $factory; 517 } 518 519 return self::$xref_factory; 520 } 521} 522