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

IntegerConverter.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
8
9 use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
10 use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue;
11 use eZ\Publish\SPI\Persistence\Content\FieldValue;
12 use eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition;
13 use eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition;
14
15 class IntegerConverter implements Converter
16 {
17 const FLOAT_VALIDATOR_IDENTIFIER = 'IntegerValueValidator';
18
19 const HAS_MIN_VALUE = 1;
20 const HAS_MAX_VALUE = 2;
21
31 public static function create()
32 {
33 return new self();
34 }
35
42 public function toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
43 {
44 $storageFieldValue->dataInt = $value->data;
45 $storageFieldValue->sortKeyInt = (int)$value->sortKey;
46 }
47
54 public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
55 {
56 $fieldValue->data = $value->dataInt;
57 $fieldValue->sortKey = $value->sortKeyInt;
58 }
59
66 public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
67 {
68 if (isset($fieldDef->fieldTypeConstraints->validators[self::FLOAT_VALIDATOR_IDENTIFIER]['minIntegerValue'])) {
69 $storageDef->dataInt1 = $fieldDef->fieldTypeConstraints->validators[self::FLOAT_VALIDATOR_IDENTIFIER]['minIntegerValue'];
70 }
71 if (isset($fieldDef->fieldTypeConstraints->validators[self::FLOAT_VALIDATOR_IDENTIFIER]['maxIntegerValue'])) {
72 $storageDef->dataInt2 = $fieldDef->fieldTypeConstraints->validators[self::FLOAT_VALIDATOR_IDENTIFIER]['maxIntegerValue'];
73 }
74
75 if ($storageDef->dataInt1 === false || $storageDef->dataInt2 === false) {
76 @trigger_error(
77 "The IntegerValueValidator constraint value 'false' is deprecated, and will be removed in 7.0. Use 'null' instead.",
78 E_USER_DEPRECATED
79 );
80 $storageDef->dataInt1 = $storageDef->dataInt1 === false ? null : $storageDef->dataInt1;
81 $storageDef->dataInt2 = $storageDef->dataInt2 === false ? null : $storageDef->dataInt2;
82 }
83
84 // Defining dataInt4 which holds the validator state (min value/max value/minMax value)
85 $storageDef->dataInt4 = $this->getStorageDefValidatorState($storageDef->dataInt1, $storageDef->dataInt2);
86 $storageDef->dataInt3 = $fieldDef->defaultValue->data;
87 }
88
95 public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
96 {
97 $validatorParameters = ['minIntegerValue' => null, 'maxIntegerValue' => null];
98 if ($storageDef->dataInt4 & self::HAS_MIN_VALUE) {
99 $validatorParameters['minIntegerValue'] = $storageDef->dataInt1;
100 }
101
102 if ($storageDef->dataInt4 & self::HAS_MAX_VALUE) {
103 $validatorParameters['maxIntegerValue'] = $storageDef->dataInt2;
104 }
105 $fieldDef->fieldTypeConstraints->validators[self::FLOAT_VALIDATOR_IDENTIFIER] = $validatorParameters;
106 $fieldDef->defaultValue->data = $storageDef->dataInt3;
107 $fieldDef->defaultValue->sortKey = ($storageDef->dataInt3 === null ? 0 : $storageDef->dataInt3);
108 }
109
119 public function getIndexColumn()
120 {
121 return 'sort_key_int';
122 }
123
135 private function getStorageDefValidatorState($minValue, $maxValue)
136 {
137 $state = 0;
138
139 if ($minValue !== null) {
140 $state |= self::HAS_MIN_VALUE;
141 }
142
143 if ($maxValue !== null) {
144 $state |= self::HAS_MAX_VALUE;
145 }
146
147 return $state;
148 }
149 }
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter
Definition: IntegerConverter.php:16
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\HAS_MAX_VALUE
const HAS_MAX_VALUE
Definition: IntegerConverter.php:20
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\getIndexColumn
getIndexColumn()
Returns the name of the index column in the attribute table.
Definition: IntegerConverter.php:119
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\create
static create()
Factory for current class.
Definition: IntegerConverter.php:31
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\FLOAT_VALIDATOR_IDENTIFIER
const FLOAT_VALIDATOR_IDENTIFIER
Definition: IntegerConverter.php:17
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\getStorageDefValidatorState
getStorageDefValidatorState($minValue, $maxValue)
Returns validator state for storage definition.
Definition: IntegerConverter.php:135
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\toStorageValue
toStorageValue(FieldValue $value, StorageFieldValue $storageFieldValue)
Converts data from $value to $storageFieldValue.
Definition: IntegerConverter.php:42
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\toFieldDefinition
toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefinition $fieldDef)
Converts field definition data in $storageDef into $fieldDef.
Definition: IntegerConverter.php:95
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\toStorageFieldDefinition
toStorageFieldDefinition(FieldDefinition $fieldDef, StorageFieldDefinition $storageDef)
Converts field definition data in $fieldDef into $storageFieldDef.
Definition: IntegerConverter.php:66
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\toFieldValue
toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
Converts data from $value to $fieldValue.
Definition: IntegerConverter.php:54
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\IntegerConverter\HAS_MIN_VALUE
const HAS_MIN_VALUE
Definition: IntegerConverter.php:19
eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldDefinition
Definition: StorageFieldDefinition.php:12
eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue
Definition: StorageFieldValue.php:12
eZ\Publish\SPI\Persistence\Content\FieldValue
Definition: FieldValue.php:12
eZ\Publish\SPI\Persistence\Content\Type\FieldDefinition
Definition: SPI/Persistence/Content/Type/FieldDefinition.php:18
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter
Converter for field values in legacy storage.
Definition: Persistence/Legacy/Content/FieldValue/Converter.php:18
eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter
Definition: AuthorConverter.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.