commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CustomFieldModel.php
1<?php
2
3declare(strict_types=1);
10
15use stdClass;
16
20final class CustomFieldModel extends JsonObjectModel implements CustomField
21{
22 public const DISCRIMINATOR_VALUE = '';
27 protected $type;
28
33 private static $discriminatorClasses = [
34 'Boolean' => BooleanFieldModel::class,
35 'BooleanSet' => BooleanSetFieldModel::class,
36 'Date' => DateFieldModel::class,
37 'DateSet' => DateSetFieldModel::class,
38 'DateTime' => DateTimeFieldModel::class,
39 'DateTimeSet' => DateTimeSetFieldModel::class,
40 'Enum' => EnumFieldModel::class,
41 'EnumSet' => EnumSetFieldModel::class,
42 'LocalizedEnum' => LocalizedEnumFieldModel::class,
43 'LocalizedEnumSet' => LocalizedEnumSetFieldModel::class,
44 'LocalizedString' => LocalizedStringFieldModel::class,
45 'LocalizedStringSet' => LocalizedStringSetFieldModel::class,
46 'Money' => MoneyFieldModel::class,
47 'MoneySet' => MoneySetFieldModel::class,
48 'Number' => NumberFieldModel::class,
49 'NumberSet' => NumberSetFieldModel::class,
50 'Reference' => ReferenceFieldModel::class,
51 'ReferenceSet' => ReferenceSetFieldModel::class,
52 'String' => StringFieldModel::class,
53 'StringSet' => StringSetFieldModel::class,
54 'Time' => TimeFieldModel::class,
55 'TimeSet' => TimeSetFieldModel::class,
56 ];
57
61 public function __construct(
62 ?string $type = null
63 ) {
64 $this->type = $type;
65 }
66
73 public function getType()
74 {
75 if (is_null($this->type)) {
77 $data = $this->raw(self::FIELD_TYPE);
78 if (is_null($data)) {
79 return null;
80 }
81 $this->type = (string) $data;
82 }
83
84 return $this->type;
85 }
86
87
88
89
90
95 public static function resolveDiscriminatorClass($value): string
96 {
98 if (is_object($value) && isset($value->$fieldName)) {
100 $discriminatorValue = $value->$fieldName;
101 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
102 return self::$discriminatorClasses[$discriminatorValue];
103 }
104 }
105 if (is_array($value) && isset($value[$fieldName])) {
107 $discriminatorValue = $value[$fieldName];
108 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
109 return self::$discriminatorClasses[$discriminatorValue];
110 }
111 }
112
114 $type = CustomFieldModel::class;
115 return $type;
116 }
117}