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

NameableFieldTypeRegistry.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Repository\Helper;
8
9 use eZ\Publish\SPI\FieldType\Nameable as SPIFieldTypeNameable;
10 use eZ\Publish\Core\Base\Exceptions\NotFound\FieldTypeNotFoundException;
11 use RuntimeException;
12
18 class NameableFieldTypeRegistry
19 {
21 protected $fieldTypes;
22
26 public function __construct(array $fieldTypes = [])
27 {
28 $this->fieldTypes = $fieldTypes;
29 }
30
36 public function getFieldTypes()
37 {
38 // First make sure all items are correct type (call closures)
39 foreach ($this->fieldTypes as $identifier => $value) {
40 if (!$value instanceof SPIFieldTypeNameable) {
41 $this->getFieldType($identifier);
42 }
43 }
44
45 return $this->fieldTypes;
46 }
47
57 public function getFieldType($identifier)
58 {
59 if (!isset($this->fieldTypes[$identifier])) {
60 throw new FieldTypeNotFoundException($identifier);
61 }
62
63 if ($this->fieldTypes[$identifier] instanceof SPIFieldTypeNameable) {
64 return $this->fieldTypes[$identifier];
65 } elseif (is_callable($this->fieldTypes[$identifier])) {
67 $closure = $this->fieldTypes[$identifier];
68 $this->fieldTypes[$identifier] = $closure();
69 }
70
71 if (!$this->fieldTypes[$identifier] instanceof SPIFieldTypeNameable) {
72 throw new RuntimeException("\$fieldTypes[$identifier] must be instance of SPI\\FieldType\\Nameable or callable");
73 }
74
75 return $this->fieldTypes[$identifier];
76 }
77
85 public function hasFieldType($identifier)
86 {
87 return isset($this->fieldTypes[$identifier]);
88 }
89 }
eZ\Publish\Core\Base\Exceptions\NotFound\FieldTypeNotFoundException
FieldType Not Found Exception.
Definition: FieldTypeNotFoundException.php:19
eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry
Registry for SPI FieldTypes.
Definition: NameableFieldTypeRegistry.php:19
eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry\$fieldTypes
$fieldTypes
Definition: NameableFieldTypeRegistry.php:21
eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry\getFieldTypes
getFieldTypes()
Returns a list of all SPI FieldTypes.
Definition: NameableFieldTypeRegistry.php:36
eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry\hasFieldType
hasFieldType($identifier)
Returns if there is a SPI FieldType registered under $identifier.
Definition: NameableFieldTypeRegistry.php:85
eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry\__construct
__construct(array $fieldTypes=[])
Definition: NameableFieldTypeRegistry.php:26
eZ\Publish\SPI\FieldType\Nameable
The field type interface which all field types have to implement to be able to generate content name ...
Definition: Nameable.php:36
eZ\Publish\Core\Repository\Helper
Definition: ContentTypeDomainMapper.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.