commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
lib
commercetools-import
src
Models
Productvariants
DateTimeAttributeModel.php
1
<?php
2
3
declare(strict_types=1);
9
namespace
Commercetools\Import\Models\Productvariants
;
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
DateTimeAttributeModel
extends
JsonObjectModel
implements
DateTimeAttribute
22
{
23
public
const
DISCRIMINATOR_VALUE
=
'datetime'
;
28
protected
$name
;
29
34
protected
$type
;
35
40
protected
$value
;
41
42
46
public
function
__construct
(
47
?
string
$name
=
null
,
48
?DateTimeImmutable
$value
=
null
,
49
?
string
$type
=
null
50
) {
51
$this->name =
$name
;
52
$this->value =
$value
;
53
$this->type =
$type
??
self::DISCRIMINATOR_VALUE
;
54
}
55
64
public
function
getName
()
65
{
66
if
(is_null($this->name)) {
68
$data = $this->
raw
(self::FIELD_NAME);
69
if
(is_null($data)) {
70
return
null
;
71
}
72
$this->name = (string) $data;
73
}
74
75
return
$this->name
;
76
}
77
82
public
function
getType
()
83
{
84
if
(is_null($this->type)) {
86
$data = $this->
raw
(self::FIELD_TYPE);
87
if
(is_null($data)) {
88
return
null
;
89
}
90
$this->type = (string) $data;
91
}
92
93
return
$this->type
;
94
}
95
100
public
function
getValue
()
101
{
102
if
(is_null($this->value)) {
104
$data = $this->
raw
(self::FIELD_VALUE);
105
if
(is_null($data)) {
106
return
null
;
107
}
108
$data = DateTimeImmutable::createFromFormat(
MapperFactory::DATETIME_FORMAT
, $data);
109
if
(
false
=== $data) {
110
return
null
;
111
}
112
$this->value = $data;
113
}
114
115
return
$this->value
;
116
}
117
118
122
public
function
setName
(?
string
$name
): void
123
{
124
$this->name =
$name
;
125
}
126
130
public
function
setValue
(?DateTimeImmutable
$value
): void
131
{
132
$this->value =
$value
;
133
}
134
135
136
#[\ReturnTypeWillChange]
137
public
function
jsonSerialize
()
138
{
139
$data = $this->
toArray
();
140
if
(isset($data[
DateTimeAttribute::FIELD_VALUE
]) && $data[
DateTimeAttribute::FIELD_VALUE
] instanceof \DateTimeImmutable) {
141
$data[
DateTimeAttribute::FIELD_VALUE
] = $data[
DateTimeAttribute::FIELD_VALUE
]->setTimeZone(
new
\DateTimeZone(
'UTC'
))->format(
'c'
);
142
}
143
return
(
object
) $data;
144
}
145
}
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\DATETIME_FORMAT
const DATETIME_FORMAT
Definition:
MapperFactory.php:19
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel
Definition:
DateTimeAttributeModel.php:22
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\jsonSerialize
jsonSerialize()
Definition:
DateTimeAttributeModel.php:137
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\getType
getType()
Definition:
DateTimeAttributeModel.php:82
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\$type
$type
Definition:
DateTimeAttributeModel.php:34
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\$value
$value
Definition:
DateTimeAttributeModel.php:40
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\setValue
setValue(?DateTimeImmutable $value)
Definition:
DateTimeAttributeModel.php:130
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\__construct
__construct(?string $name=null, ?DateTimeImmutable $value=null, ?string $type=null)
Definition:
DateTimeAttributeModel.php:46
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\getName
getName()
Definition:
DateTimeAttributeModel.php:64
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\$name
$name
Definition:
DateTimeAttributeModel.php:28
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\getValue
getValue()
Definition:
DateTimeAttributeModel.php:100
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\DISCRIMINATOR_VALUE
const DISCRIMINATOR_VALUE
Definition:
DateTimeAttributeModel.php:23
Commercetools\Import\Models\Productvariants\DateTimeAttributeModel\setName
setName(?string $name)
Definition:
DateTimeAttributeModel.php:122
Commercetools\Base\JsonObject
Definition:
JsonObject.php:15
Commercetools\Import\Models\Productvariants\DateTimeAttribute
Definition:
DateTimeAttribute.php:16
Commercetools\Import\Models\Productvariants\DateTimeAttribute\FIELD_VALUE
const FIELD_VALUE
Definition:
DateTimeAttribute.php:17
Commercetools\Import\Models\Productvariants
Definition:
Attribute.php:9
Generated by
1.9.1