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