vendor/ezsystems/ezplatform-kernel/eZ/Publish/Core/FieldType/FieldTypeRegistry.php line 17

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace eZ\Publish\Core\FieldType;
  7. use eZ\Publish\SPI\FieldType\FieldType as SPIFieldType;
  8. use eZ\Publish\Core\Base\Exceptions\NotFound\FieldTypeNotFoundException;
  9. /**
  10.  * Registry for SPI FieldTypes.
  11.  *
  12.  * @internal Meant for internal use by Repository.
  13.  */
  14. class FieldTypeRegistry
  15. {
  16.     /** @var \eZ\Publish\SPI\FieldType\FieldType[] Hash of SPI FieldTypes where key is identifier */
  17.     protected $fieldTypes;
  18.     /** @var string[] */
  19.     private $concreteFieldTypesIdentifiers;
  20.     /**
  21.      * @param \eZ\Publish\SPI\FieldType\FieldType[] $fieldTypes Hash of SPI FieldTypes where key is identifier
  22.      */
  23.     public function __construct(array $fieldTypes = [])
  24.     {
  25.         $this->fieldTypes $fieldTypes;
  26.     }
  27.     /**
  28.      * Returns a list of all SPI FieldTypes.
  29.      *
  30.      * @return \eZ\Publish\SPI\FieldType\FieldType[]
  31.      */
  32.     public function getFieldTypes(): array
  33.     {
  34.         return $this->fieldTypes;
  35.     }
  36.     /**
  37.      * Return a SPI FieldType object.
  38.      *
  39.      * @throws \eZ\Publish\Core\Base\Exceptions\NotFound\FieldTypeNotFoundException If $identifier was not found
  40.      *
  41.      * @param string $identifier
  42.      *
  43.      * @return \eZ\Publish\SPI\FieldType\FieldType
  44.      */
  45.     public function getFieldType($identifier): SPIFieldType
  46.     {
  47.         if (!isset($this->fieldTypes[$identifier])) {
  48.             throw new FieldTypeNotFoundException($identifier);
  49.         }
  50.         return $this->fieldTypes[$identifier];
  51.     }
  52.     public function registerFieldType(string $identifierSPIFieldType $fieldType): void
  53.     {
  54.         $this->fieldTypes[$identifier] = $fieldType;
  55.     }
  56.     /**
  57.      * Returns if there is a SPI FieldType registered under $identifier.
  58.      *
  59.      * @param string $identifier
  60.      *
  61.      * @return bool
  62.      */
  63.     public function hasFieldType($identifier): bool
  64.     {
  65.         return isset($this->fieldTypes[$identifier]);
  66.     }
  67.     /**
  68.      * Registers $fieldTypeIdentifier as "concrete" FieldType (i.e. not using NullFieldType).
  69.      */
  70.     public function registerConcreteFieldTypeIdentifier(string $fieldTypeIdentifier): void
  71.     {
  72.         $this->concreteFieldTypesIdentifiers[] = $fieldTypeIdentifier;
  73.     }
  74.     /**
  75.      * @return string[]
  76.      */
  77.     public function getConcreteFieldTypesIdentifiers(): array
  78.     {
  79.         return $this->concreteFieldTypesIdentifiers;
  80.     }
  81. }