commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
ReferenceFieldModel.php
1 <?php
2 
3 declare(strict_types=1);
10 
17 use stdClass;
18 
22 final class ReferenceFieldModel extends JsonObjectModel implements ReferenceField
23 {
24  public const DISCRIMINATOR_VALUE = 'Reference';
29  protected $type;
30 
35  protected $value;
36 
37 
41  public function __construct(
42  ?KeyReference $value = null,
43  ?string $type = null
44  ) {
45  $this->value = $value;
46  $this->type = $type ?? self::DISCRIMINATOR_VALUE;
47  }
48 
55  public function getType()
56  {
57  if (is_null($this->type)) {
59  $data = $this->raw(self::FIELD_TYPE);
60  if (is_null($data)) {
61  return null;
62  }
63  $this->type = (string) $data;
64  }
65 
66  return $this->type;
67  }
68 
75  public function getValue()
76  {
77  if (is_null($this->value)) {
79  $data = $this->raw(self::FIELD_VALUE);
80  if (is_null($data)) {
81  return null;
82  }
83 
84  $this->value = KeyReferenceModel::of($data);
85  }
86 
87  return $this->value;
88  }
89 
90 
94  public function setValue(?KeyReference $value): void
95  {
96  $this->value = $value;
97  }
98 }
__construct(?KeyReference $value=null, ?string $type=null)