commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
AttributeModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use stdClass;
16 
20 final class AttributeModel extends JsonObjectModel implements Attribute
21 {
22  public const DISCRIMINATOR_VALUE = '';
27  protected $name;
28 
33  protected $type;
34 
39  private static $discriminatorClasses = [
40  'boolean' => BooleanAttributeModel::class,
41  'boolean-set' => BooleanSetAttributeModel::class,
42  'date' => DateAttributeModel::class,
43  'date-set' => DateSetAttributeModel::class,
44  'datetime' => DateTimeAttributeModel::class,
45  'datetime-set' => DateTimeSetAttributeModel::class,
46  'enum' => EnumAttributeModel::class,
47  'enum-set' => EnumSetAttributeModel::class,
48  'lenum' => LocalizableEnumAttributeModel::class,
49  'lenum-set' => LocalizableEnumSetAttributeModel::class,
50  'ltext' => LocalizableTextAttributeModel::class,
51  'ltext-set' => LocalizableTextSetAttributeModel::class,
52  'money' => MoneyAttributeModel::class,
53  'money-set' => MoneySetAttributeModel::class,
54  'number' => NumberAttributeModel::class,
55  'number-set' => NumberSetAttributeModel::class,
56  'reference' => ReferenceAttributeModel::class,
57  'reference-set' => ReferenceSetAttributeModel::class,
58  'text' => TextAttributeModel::class,
59  'text-set' => TextSetAttributeModel::class,
60  'time' => TimeAttributeModel::class,
61  'time-set' => TimeSetAttributeModel::class,
62  ];
63 
67  public function __construct(
68  ?string $name = null,
69  ?string $type = null
70  ) {
71  $this->name = $name;
72  $this->type = $type;
73  }
74 
83  public function getName()
84  {
85  if (is_null($this->name)) {
87  $data = $this->raw(self::FIELD_NAME);
88  if (is_null($data)) {
89  return null;
90  }
91  $this->name = (string) $data;
92  }
93 
94  return $this->name;
95  }
96 
101  public function getType()
102  {
103  if (is_null($this->type)) {
105  $data = $this->raw(self::FIELD_TYPE);
106  if (is_null($data)) {
107  return null;
108  }
109  $this->type = (string) $data;
110  }
111 
112  return $this->type;
113  }
114 
115 
119  public function setName(?string $name): void
120  {
121  $this->name = $name;
122  }
123 
124 
125 
130  public static function resolveDiscriminatorClass($value): string
131  {
132  $fieldName = Attribute::DISCRIMINATOR_FIELD;
133  if (is_object($value) && isset($value->$fieldName)) {
135  $discriminatorValue = $value->$fieldName;
136  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
137  return self::$discriminatorClasses[$discriminatorValue];
138  }
139  }
140  if (is_array($value) && isset($value[$fieldName])) {
142  $discriminatorValue = $value[$fieldName];
143  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
144  return self::$discriminatorClasses[$discriminatorValue];
145  }
146  }
147 
149  $type = AttributeModel::class;
150  return $type;
151  }
152 }
__construct(?string $name=null, ?string $type=null)