commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
LabelModel.php
1<?php
2
3declare(strict_types=1);
10
15use stdClass;
16
20final 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 'ShippingMethodLabel' => ShippingMethodLabelModel::class,
47 'StagedQuoteLabel' => StagedQuoteLabelModel::class,
48 'StandalonePriceLabel' => StandalonePriceLabelModel::class,
49 'StringLabel' => StringLabelModel::class,
50 ];
51
55 public function __construct(
56 ?string $type = null
57 ) {
58 $this->type = $type;
59
60 }
61
66 public function getType()
67 {
68 if (is_null($this->type)) {
70 $data = $this->raw(self::FIELD_TYPE);
71 if (is_null($data)) {
72 return null;
73 }
74 $this->type = (string) $data;
75 }
76
77 return $this->type;
78 }
79
80
81
82
83
88 public static function resolveDiscriminatorClass($value): string
89 {
90 $fieldName = Label::DISCRIMINATOR_FIELD;
91 if (is_object($value) && isset($value->$fieldName)) {
93 $discriminatorValue = $value->$fieldName;
94 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
95 return self::$discriminatorClasses[$discriminatorValue];
96 }
97 }
98 if (is_array($value) && isset($value[$fieldName])) {
100 $discriminatorValue = $value[$fieldName];
101 if (isset(self::$discriminatorClasses[$discriminatorValue])) {
102 return self::$discriminatorClasses[$discriminatorValue];
103 }
104 }
105
107 $type = LabelModel::class;
108 return $type;
109 }
110}