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