commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
lib
commercetools-import
src
Models
Customfields
TimeFieldModel.php
1
<?php
2
3
declare(strict_types=1);
9
namespace
Commercetools\Import\Models\Customfields
;
10
11
use
Commercetools\Base\DateTimeImmutableCollection
;
12
use
Commercetools\Base\JsonObject
;
13
use
Commercetools\Base\JsonObjectModel
;
14
use
Commercetools\Base\MapperFactory
;
15
use DateTimeImmutable;
16
use stdClass;
17
21
final
class
TimeFieldModel
extends
JsonObjectModel
implements
TimeField
22
{
23
public
const
DISCRIMINATOR_VALUE
=
'Time'
;
28
protected
$type
;
29
34
protected
$value
;
35
36
40
public
function
__construct
(
41
?DateTimeImmutable
$value
=
null
,
42
?
string
$type
=
null
43
) {
44
$this->value =
$value
;
45
$this->type =
$type
??
self::DISCRIMINATOR_VALUE
;
46
}
47
54
public
function
getType
()
55
{
56
if
(is_null($this->type)) {
58
$data = $this->
raw
(self::FIELD_TYPE);
59
if
(is_null($data)) {
60
return
null
;
61
}
62
$this->type = (string) $data;
63
}
64
65
return
$this->type
;
66
}
67
72
public
function
getValue
()
73
{
74
if
(is_null($this->value)) {
76
$data = $this->
raw
(self::FIELD_VALUE);
77
if
(is_null($data)) {
78
return
null
;
79
}
80
$data = DateTimeImmutable::createFromFormat(
MapperFactory::TIME_FORMAT
, $data);
81
if
(
false
=== $data) {
82
return
null
;
83
}
84
$this->value = $data;
85
}
86
87
return
$this->value
;
88
}
89
90
94
public
function
setValue
(?DateTimeImmutable
$value
): void
95
{
96
$this->value =
$value
;
97
}
98
99
100
#[\ReturnTypeWillChange]
101
public
function
jsonSerialize
()
102
{
103
$data = $this->
toArray
();
104
if
(isset($data[
TimeField::FIELD_VALUE
]) && $data[
TimeField::FIELD_VALUE
] instanceof \DateTimeImmutable) {
105
$data[
TimeField::FIELD_VALUE
] = $data[
TimeField::FIELD_VALUE
]->format(
'H:i:s.u'
);
106
}
107
return
(
object
) $data;
108
}
109
}
Commercetools\Base\BaseJsonObject\raw
raw(string $field)
Definition:
BaseJsonObject.php:57
Commercetools\Base\DateTimeImmutableCollection
Definition:
DateTimeImmutableCollection.php:21
Commercetools\Base\JsonObjectModel
Definition:
JsonObjectModel.php:15
Commercetools\Base\JsonObjectModel\toArray
toArray()
Definition:
JsonObjectModel.php:32
Commercetools\Base\MapperFactory
Definition:
MapperFactory.php:16
Commercetools\Base\MapperFactory\TIME_FORMAT
const TIME_FORMAT
Definition:
MapperFactory.php:17
Commercetools\Import\Models\Customfields\TimeFieldModel
Definition:
TimeFieldModel.php:22
Commercetools\Import\Models\Customfields\TimeFieldModel\getType
getType()
Definition:
TimeFieldModel.php:54
Commercetools\Import\Models\Customfields\TimeFieldModel\getValue
getValue()
Definition:
TimeFieldModel.php:72
Commercetools\Import\Models\Customfields\TimeFieldModel\$type
$type
Definition:
TimeFieldModel.php:28
Commercetools\Import\Models\Customfields\TimeFieldModel\setValue
setValue(?DateTimeImmutable $value)
Definition:
TimeFieldModel.php:94
Commercetools\Import\Models\Customfields\TimeFieldModel\__construct
__construct(?DateTimeImmutable $value=null, ?string $type=null)
Definition:
TimeFieldModel.php:40
Commercetools\Import\Models\Customfields\TimeFieldModel\DISCRIMINATOR_VALUE
const DISCRIMINATOR_VALUE
Definition:
TimeFieldModel.php:23
Commercetools\Import\Models\Customfields\TimeFieldModel\$value
$value
Definition:
TimeFieldModel.php:34
Commercetools\Import\Models\Customfields\TimeFieldModel\jsonSerialize
jsonSerialize()
Definition:
TimeFieldModel.php:101
Commercetools\Base\JsonObject
Definition:
JsonObject.php:15
Commercetools\Import\Models\Customfields\TimeField
Definition:
TimeField.php:16
Commercetools\Import\Models\Customfields\TimeField\FIELD_VALUE
const FIELD_VALUE
Definition:
TimeField.php:17
Commercetools\Import\Models\Customfields
Definition:
BooleanField.php:9
Generated by
1.9.1