commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
LabelModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use stdClass;
16 
20 final class LabelModel extends JsonObjectModel implements Label
21 {
22 
23  public const DISCRIMINATOR_VALUE = '';
28  protected $type;
29 
34  private static $discriminatorClasses = [
35  'AssociateRoleLabel' => AssociateRoleLabelModel::class,
36  'BusinessUnitLabel' => BusinessUnitLabelModel::class,
37  'CustomObjectLabel' => CustomObjectLabelModel::class,
38  'CustomerLabel' => CustomerLabelModel::class,
39  'LocalizedLabel' => LocalizedLabelModel::class,
40  'OrderLabel' => OrderLabelModel::class,
41  'PaymentLabel' => PaymentLabelModel::class,
42  'ProductLabel' => ProductLabelModel::class,
43  'QuoteLabel' => QuoteLabelModel::class,
44  'QuoteRequestLabel' => QuoteRequestLabelModel::class,
45  'ReviewLabel' => ReviewLabelModel::class,
46  'StagedQuoteLabel' => StagedQuoteLabelModel::class,
47  'StringLabel' => StringLabelModel::class,
48  ];
49 
53  public function __construct(
54  ?string $type = null
55  ) {
56  $this->type = $type;
57 
58  }
59 
64  public function getType()
65  {
66  if (is_null($this->type)) {
68  $data = $this->raw(self::FIELD_TYPE);
69  if (is_null($data)) {
70  return null;
71  }
72  $this->type = (string) $data;
73  }
74 
75  return $this->type;
76  }
77 
78 
79 
80 
81 
86  public static function resolveDiscriminatorClass($value): string
87  {
88  $fieldName = Label::DISCRIMINATOR_FIELD;
89  if (is_object($value) && isset($value->$fieldName)) {
91  $discriminatorValue = $value->$fieldName;
92  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
93  return self::$discriminatorClasses[$discriminatorValue];
94  }
95  }
96  if (is_array($value) && isset($value[$fieldName])) {
98  $discriminatorValue = $value[$fieldName];
99  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
100  return self::$discriminatorClasses[$discriminatorValue];
101  }
102  }
103 
105  $type = LabelModel::class;
106  return $type;
107  }
108 }