commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
GeoJsonModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
15 use stdClass;
16 
20 final class GeoJsonModel extends JsonObjectModel implements GeoJson
21 {
22  public const DISCRIMINATOR_VALUE = '';
27  protected $type;
28 
33  private static $discriminatorClasses = [
34  'Point' => GeoJsonPointModel::class,
35  ];
36 
40  public function __construct(
41  ?string $type = null
42  ) {
43  $this->type = $type;
44  }
45 
50  public function getType()
51  {
52  if (is_null($this->type)) {
54  $data = $this->raw(self::FIELD_TYPE);
55  if (is_null($data)) {
56  return null;
57  }
58  $this->type = (string) $data;
59  }
60 
61  return $this->type;
62  }
63 
64 
65 
66 
67 
72  public static function resolveDiscriminatorClass($value): string
73  {
74  $fieldName = GeoJson::DISCRIMINATOR_FIELD;
75  if (is_object($value) && isset($value->$fieldName)) {
77  $discriminatorValue = $value->$fieldName;
78  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
79  return self::$discriminatorClasses[$discriminatorValue];
80  }
81  }
82  if (is_array($value) && isset($value[$fieldName])) {
84  $discriminatorValue = $value[$fieldName];
85  if (isset(self::$discriminatorClasses[$discriminatorValue])) {
86  return self::$discriminatorClasses[$discriminatorValue];
87  }
88  }
89 
91  $type = GeoJsonModel::class;
92  return $type;
93  }
94 }