commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
ImportRequestModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use stdClass;
16 
20 final class ImportRequestModel extends JsonObjectModel implements ImportRequest
21 {
22  public const DISCRIMINATOR_VALUE = '';
27  protected $type;
28 
33  private static $discriminatorClasses = [
34  'category' => CategoryImportRequestModel::class,
35  'customer' => CustomerImportRequestModel::class,
36  'discount-code' => DiscountCodeImportRequestModel::class,
37  'inventory' => InventoryImportRequestModel::class,
38  'order' => OrderImportRequestModel::class,
39  'order-patch' => OrderPatchImportRequestModel::class,
40  'price' => PriceImportRequestModel::class,
41  'product' => ProductImportRequestModel::class,
42  'product-draft' => ProductDraftImportRequestModel::class,
43  'product-type' => ProductTypeImportRequestModel::class,
44  'product-variant' => ProductVariantImportRequestModel::class,
45  'product-variant-patch' => ProductVariantPatchRequestModel::class,
46  'standalone-price' => StandalonePriceImportRequestModel::class,
47  'type' => TypeImportRequestModel::class,
48  ];
49 
53  public function __construct(
54  ?string $type = null
55  ) {
56  $this->type = $type;
57  }
58 
65  public function getType()
66  {
67  if (is_null($this->type)) {
69  $data = $this->raw(self::FIELD_TYPE);
70  if (is_null($data)) {
71  return null;
72  }
73  $this->type = (string) $data;
74  }
75 
76  return $this->type;
77  }
78 
79 
80 
81 
82 
87  public static function resolveDiscriminatorClass($value): string
88  {
90  if (is_object($value) && isset($value->$fieldName)) {
92  $discriminatorValue = $value->$fieldName;
93  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
94  return self::$discriminatorClasses[$discriminatorValue];
95  }
96  }
97  if (is_array($value) && isset($value[$fieldName])) {
99  $discriminatorValue = $value[$fieldName];
100  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
101  return self::$discriminatorClasses[$discriminatorValue];
102  }
103  }
104 
106  $type = ImportRequestModel::class;
107  return $type;
108  }
109 }