commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
KeyReferenceModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use stdClass;
16 
20 final class KeyReferenceModel extends JsonObjectModel implements KeyReference
21 {
22  public const DISCRIMINATOR_VALUE = '';
27  protected $key;
28 
33  protected $typeId;
34 
39  private static $discriminatorClasses = [
40  'cart' => CartKeyReferenceModel::class,
41  'cart-discount' => CartDiscountKeyReferenceModel::class,
42  'category' => CategoryKeyReferenceModel::class,
43  'channel' => ChannelKeyReferenceModel::class,
44  'customer' => CustomerKeyReferenceModel::class,
45  'customer-group' => CustomerGroupKeyReferenceModel::class,
46  'discount-code' => DiscountCodeKeyReferenceModel::class,
47  'key-value-document' => CustomObjectKeyReferenceModel::class,
48  'order' => OrderKeyReferenceModel::class,
49  'payment' => PaymentKeyReferenceModel::class,
50  'price' => PriceKeyReferenceModel::class,
51  'product' => ProductKeyReferenceModel::class,
52  'product-discount' => ProductDiscountKeyReferenceModel::class,
53  'product-type' => ProductTypeKeyReferenceModel::class,
54  'product-variant' => ProductVariantKeyReferenceModel::class,
55  'shipping-method' => ShippingMethodKeyReferenceModel::class,
56  'state' => StateKeyReferenceModel::class,
57  'store' => StoreKeyReferenceModel::class,
58  'tax-category' => TaxCategoryKeyReferenceModel::class,
59  'type' => TypeKeyReferenceModel::class,
60  ];
61 
65  public function __construct(
66  ?string $key = null,
67  ?string $typeId = null
68  ) {
69  $this->key = $key;
70  $this->typeId = $typeId;
71  }
72 
77  public function getKey()
78  {
79  if (is_null($this->key)) {
81  $data = $this->raw(self::FIELD_KEY);
82  if (is_null($data)) {
83  return null;
84  }
85  $this->key = (string) $data;
86  }
87 
88  return $this->key;
89  }
90 
97  public function getTypeId()
98  {
99  if (is_null($this->typeId)) {
101  $data = $this->raw(self::FIELD_TYPE_ID);
102  if (is_null($data)) {
103  return null;
104  }
105  $this->typeId = (string) $data;
106  }
107 
108  return $this->typeId;
109  }
110 
111 
115  public function setKey(?string $key): void
116  {
117  $this->key = $key;
118  }
119 
120 
121 
126  public static function resolveDiscriminatorClass($value): string
127  {
129  if (is_object($value) && isset($value->$fieldName)) {
131  $discriminatorValue = $value->$fieldName;
132  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
133  return self::$discriminatorClasses[$discriminatorValue];
134  }
135  }
136  if (is_array($value) && isset($value[$fieldName])) {
138  $discriminatorValue = $value[$fieldName];
139  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
140  return self::$discriminatorClasses[$discriminatorValue];
141  }
142  }
143 
145  $type = KeyReferenceModel::class;
146  return $type;
147  }
148 }
__construct(?string $key=null, ?string $typeId=null)