commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
TypedMoneyModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use stdClass;
16 
20 final class TypedMoneyModel extends JsonObjectModel implements TypedMoney
21 {
22  public const DISCRIMINATOR_VALUE = '';
27  protected $type;
28 
33  protected $fractionDigits;
34 
39  protected $centAmount;
40 
45  protected $currencyCode;
46 
51  private static $discriminatorClasses = [
52  'centPrecision' => MoneyModel::class,
53  'highPrecision' => HighPrecisionMoneyModel::class,
54  ];
55 
59  public function __construct(
60  ?int $fractionDigits = null,
61  ?int $centAmount = null,
62  ?string $currencyCode = null,
63  ?string $type = null
64  ) {
65  $this->fractionDigits = $fractionDigits;
66  $this->centAmount = $centAmount;
67  $this->currencyCode = $currencyCode;
68  $this->type = $type;
69  }
70 
75  public function getType()
76  {
77  if (is_null($this->type)) {
79  $data = $this->raw(self::FIELD_TYPE);
80  if (is_null($data)) {
81  return null;
82  }
83  $this->type = (string) $data;
84  }
85 
86  return $this->type;
87  }
88 
93  public function getFractionDigits()
94  {
95  if (is_null($this->fractionDigits)) {
97  $data = $this->raw(self::FIELD_FRACTION_DIGITS);
98  if (is_null($data)) {
99  return null;
100  }
101  $this->fractionDigits = (int) $data;
102  }
103 
104  return $this->fractionDigits;
105  }
106 
111  public function getCentAmount()
112  {
113  if (is_null($this->centAmount)) {
115  $data = $this->raw(self::FIELD_CENT_AMOUNT);
116  if (is_null($data)) {
117  return null;
118  }
119  $this->centAmount = (int) $data;
120  }
121 
122  return $this->centAmount;
123  }
124 
131  public function getCurrencyCode()
132  {
133  if (is_null($this->currencyCode)) {
135  $data = $this->raw(self::FIELD_CURRENCY_CODE);
136  if (is_null($data)) {
137  return null;
138  }
139  $this->currencyCode = (string) $data;
140  }
141 
142  return $this->currencyCode;
143  }
144 
145 
149  public function setFractionDigits(?int $fractionDigits): void
150  {
151  $this->fractionDigits = $fractionDigits;
152  }
153 
157  public function setCentAmount(?int $centAmount): void
158  {
159  $this->centAmount = $centAmount;
160  }
161 
165  public function setCurrencyCode(?string $currencyCode): void
166  {
167  $this->currencyCode = $currencyCode;
168  }
169 
170 
171 
176  public static function resolveDiscriminatorClass($value): string
177  {
178  $fieldName = TypedMoney::DISCRIMINATOR_FIELD;
179  if (is_object($value) && isset($value->$fieldName)) {
181  $discriminatorValue = $value->$fieldName;
182  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
183  return self::$discriminatorClasses[$discriminatorValue];
184  }
185  }
186  if (is_array($value) && isset($value[$fieldName])) {
188  $discriminatorValue = $value[$fieldName];
189  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
190  return self::$discriminatorClasses[$discriminatorValue];
191  }
192  }
193 
195  $type = TypedMoneyModel::class;
196  return $type;
197  }
198 }
__construct(?int $fractionDigits=null, ?int $centAmount=null, ?string $currencyCode=null, ?string $type=null)