commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
CustomFieldAccessor.php
1<?php
2
3
5
28use DateTimeImmutable;
29use stdClass;
30
32{
36 private $value;
37
41 private function __construct($value)
42 {
43 $this->value = $value;
44 }
45
50 public function getValue()
51 {
55 $value = $this->value;
56 return $value;
57 }
58
62 public static function of()
63 {
64 return function ($value): CustomFieldAccessor {
65 return new self($value);
66 };
67 }
68
70 {
74 $value = $this->value;
75 return CustomFieldEnumValueModel::of($value);
76 }
77
79 {
83 $value = $this->value;
85 }
86
87 public function getValueAsString(): string
88 {
89 return (string)$this->value;
90 }
91
92 public function getValueAsInt(): int
93 {
94 return (int)$this->value;
95 }
96
97 public function getValueAsFloat(): float
98 {
99 return (float)$this->value;
100 }
101
102 public function getValueAsBool(): bool
103 {
104 return (bool)$this->value;
105 }
106
107 public function getValueAsDateTime(): ?DateTimeImmutable
108 {
109 $value = DateTimeImmutable::createFromFormat(MapperFactory::DATETIME_FORMAT, (string)$this->value);
110 return $value ? $value : null;
111 }
112
113 public function getValueAsTime(): ?DateTimeImmutable
114 {
115 $value = DateTimeImmutable::createFromFormat(MapperFactory::TIME_FORMAT, (string)$this->value);
116 return $value ? $value : null;
117 }
118
119 public function getValueAsDate(): ?DateTimeImmutable
120 {
121 $value = DateTimeImmutable::createFromFormat(MapperFactory::DATE_FORMAT, (string)$this->value);
122 return $value ? $value : null;
123 }
124
125 public function getValueAsMoney(): Money
126 {
130 $value = $this->value;
131 return MoneyModel::of($value);
132 }
133
135 {
139 $value = $this->value;
140 $refClass = ReferenceModel::resolveDiscriminatorClass($value);
141 return $refClass::of($value);
142 }
143
145 {
149 $value = $this->value;
150 return LocalizedStringModel::of($value);
151 }
152
154 {
158 $value = $this->value;
160 }
161
163 {
167 $value = $this->value;
169 }
170
171 public function getValueAsStringSet(): array
172 {
176 $value = $this->value;
177 return $value;
178 }
179
180 public function getValueAsIntSet(): array
181 {
185 $value = $this->value;
186 return array_map(function ($value) {
187 return (int)$value;
188 }, $value);
189 }
190
191 public function getValueAsFloatSet(): array
192 {
196 $value = $this->value;
197 return array_map(function ($value) {
198 return (float)$value;
199 }, $value);
200 }
201
202 public function getValueAsBoolSet(): array
203 {
207 $value = $this->value;
208 return $value;
209 }
210
212 {
216 $value = $this->value;
217 return DateTimeImmutableCollection::fromArray($value);
218 }
219
221 {
225 $value = $this->value;
226 return DateTimeImmutableCollection::fromArray($value);
227 }
228
230 {
234 $value = $this->value;
235 return DateTimeImmutableCollection::fromArray($value);
236 }
237
239 {
243 $value = $this->value;
244 return MoneyCollection::fromArray($value);
245 }
246
248 {
252 $value = $this->value;
253 return LocalizedStringCollection::fromArray($value);
254 }
255}
static fromArray(array $data)