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