FieldFactory.php 651 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Files\Template;
  8. use OCP\Files\Template\Fields\CheckBoxField;
  9. use OCP\Files\Template\Fields\RichTextField;
  10. /**
  11. * @since 30.0.0
  12. */
  13. class FieldFactory {
  14. /**
  15. * @since 30.0.0
  16. */
  17. public static function createField(
  18. string $index,
  19. FieldType $type,
  20. ): Field {
  21. return match ($type) {
  22. FieldType::RichText => new RichTextField($index, $type),
  23. FieldType::CheckBox => new CheckBoxField($index, $type),
  24. default => throw new InvalidFieldTypeException(),
  25. };
  26. }
  27. }