1 | <?php |
||
10 | class FieldHandlerManager |
||
11 | { |
||
12 | /** @var FieldValueImporterInterface[][] */ |
||
13 | protected $fieldTypeMap; |
||
14 | protected $fieldTypeService; |
||
15 | |||
16 | 79 | public function __construct(FieldTypeService $fieldTypeService) |
|
20 | |||
21 | /** |
||
22 | * @param FieldValueImporterInterface $fieldHandler |
||
23 | * @param string $fieldTypeIdentifier |
||
24 | * @param string $contentTypeIdentifier |
||
25 | * @throws \Exception |
||
26 | */ |
||
27 | 79 | public function addFieldHandler($fieldHandler, $fieldTypeIdentifier, $contentTypeIdentifier = null) |
|
39 | |||
40 | /** |
||
41 | * @param string $fieldTypeIdentifier |
||
42 | * @param string $contentTypeIdentifier |
||
43 | * @return bool |
||
44 | */ |
||
45 | 20 | public function managesField($fieldTypeIdentifier, $contentTypeIdentifier) |
|
50 | |||
51 | /** |
||
52 | * Returns true when a fieldHandler allows string refs to be pre-resolved for the field value it gets as hash. |
||
53 | * "pre-resolved" means: resolved before the field-handler-specific propcessing kicks in |
||
54 | * |
||
55 | * @param string $fieldTypeIdentifier |
||
56 | * @param string $contentTypeIdentifier |
||
57 | */ |
||
58 | 1 | public function doPreResolveStringReferences($fieldTypeIdentifier, $contentTypeIdentifier) |
|
72 | |||
73 | /** |
||
74 | * @param string $fieldTypeIdentifier |
||
75 | * @param string $contentTypeIdentifier |
||
76 | * @param mixed $hashValue |
||
77 | * @param array $context |
||
78 | * @return mixed |
||
79 | */ |
||
80 | 5 | public function hashToFieldValue($fieldTypeIdentifier, $contentTypeIdentifier, $hashValue, array $context = array()) |
|
94 | |||
95 | /** |
||
96 | * @param string $fieldTypeIdentifier |
||
97 | * @param string $contentTypeIdentifier |
||
98 | * @param \eZ\Publish\SPI\FieldType\Value $value |
||
99 | * @param array $context |
||
100 | * @return mixed |
||
101 | */ |
||
102 | 6 | public function fieldValueToHash($fieldTypeIdentifier, $contentTypeIdentifier, $value, array $context = array()) |
|
103 | { |
||
104 | 6 | if ($this->managesField($fieldTypeIdentifier, $contentTypeIdentifier)) { |
|
105 | $fieldHandler = $this->getFieldHandler($fieldTypeIdentifier, $contentTypeIdentifier); |
||
106 | if ($fieldHandler instanceof FieldValueConverterInterface) { |
||
107 | return $fieldHandler->fieldValueToHash($value, $context); |
||
108 | } |
||
109 | } |
||
110 | |||
111 | 6 | $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier); |
|
112 | 6 | return $fieldType->toHash($value); |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * @param string $fieldTypeIdentifier |
||
117 | * @param string $contentTypeIdentifier |
||
118 | * @return bool |
||
119 | */ |
||
120 | 7 | public function managesFieldDefinition($fieldTypeIdentifier, $contentTypeIdentifier) |
|
129 | |||
130 | /** |
||
131 | * @param string $fieldTypeIdentifier |
||
132 | * @param string $contentTypeIdentifier |
||
133 | * @param mixed $fieldSettingsHash |
||
134 | * @param array $context |
||
135 | * @return mixed |
||
136 | */ |
||
137 | 1 | public function hashToFieldSettings($fieldTypeIdentifier, $contentTypeIdentifier, $fieldSettingsHash, array $context = array()) |
|
145 | |||
146 | /** |
||
147 | * @param string $fieldTypeIdentifier |
||
148 | * @param string $contentTypeIdentifier |
||
149 | * @param mixed $fieldSettings |
||
150 | * @param array $context |
||
151 | * @return mixed |
||
152 | */ |
||
153 | 5 | public function fieldSettingsToHash($fieldTypeIdentifier, $contentTypeIdentifier, $fieldSettings, array $context = array()) |
|
161 | |||
162 | /** |
||
163 | * @param string $fieldTypeIdentifier |
||
164 | * @param string $contentTypeIdentifier |
||
165 | * @return FieldValueImporterInterface |
||
166 | * @throws \Exception |
||
167 | */ |
||
168 | 7 | protected function getFieldHandler($fieldTypeIdentifier, $contentTypeIdentifier) { |
|
177 | } |
||
178 |