Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Persistence/FieldTypeRegistry.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence;
8
9 use eZ\Publish\Core\Base\Exceptions\NotFound\FieldTypeNotFoundException;
10 use eZ\Publish\SPI\FieldType\FieldType as FieldTypeInterface;
11 use RuntimeException;
12
16 class FieldTypeRegistry
17 {
24 protected $coreFieldTypeMap = [];
25
31 protected $fieldTypeMap = [];
32
43 public function __construct(array $fieldTypeMap)
44 {
45 $this->coreFieldTypeMap = $fieldTypeMap;
46 }
47
58 public function getFieldType($identifier)
59 {
60 if (!isset($this->fieldTypeMap[$identifier])) {
61 $this->fieldTypeMap[$identifier] = new FieldType($this->getCoreFieldType($identifier));
62 }
63
64 return $this->fieldTypeMap[$identifier];
65 }
66
77 public function register($identifier, $fieldType)
78 {
79 $this->coreFieldTypeMap[$identifier] = $fieldType;
80 }
81
92 protected function getCoreFieldType($identifier)
93 {
94 if (!isset($this->coreFieldTypeMap[$identifier])) {
95 throw new FieldTypeNotFoundException($identifier);
96 }
97
98 $fieldType = $this->coreFieldTypeMap[$identifier];
99
100 if (!$this->coreFieldTypeMap[$identifier] instanceof FieldTypeInterface) {
101 if (!is_callable($this->coreFieldTypeMap[$identifier])) {
102 throw new RuntimeException("FieldType '$identifier' is not callable or instance");
103 }
104
106 $fieldType = $fieldType();
107 }
108
109 return $fieldType;
110 }
111 }
eZ\Publish\Core\Base\Exceptions\NotFound\FieldTypeNotFoundException
FieldType Not Found Exception.
Definition: FieldTypeNotFoundException.php:19
eZ\Publish\Core\Persistence\FieldTypeRegistry
Registry for field types available to storage engines.
Definition: Persistence/FieldTypeRegistry.php:17
eZ\Publish\Core\Persistence\FieldTypeRegistry\$coreFieldTypeMap
$coreFieldTypeMap
Definition: Persistence/FieldTypeRegistry.php:24
eZ\Publish\Core\Persistence\FieldTypeRegistry\__construct
__construct(array $fieldTypeMap)
Creates FieldType registry.
Definition: Persistence/FieldTypeRegistry.php:43
eZ\Publish\Core\Persistence\FieldTypeRegistry\$fieldTypeMap
$fieldTypeMap
Definition: Persistence/FieldTypeRegistry.php:31
eZ\Publish\Core\Persistence\FieldTypeRegistry\getFieldType
getFieldType($identifier)
Returns the FieldType object for given $identifier.
Definition: Persistence/FieldTypeRegistry.php:58
eZ\Publish\Core\Persistence\FieldType
This class represents a FieldType available to SPI users.
Definition: Core/Persistence/FieldType.php:19
eZ\Publish\SPI\FieldType\FieldType
The field type interface which all field types have to implement.
Definition: SPI/FieldType/FieldType.php:30
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.