commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
lib
commercetools-base
src
Base
MapperFactory.php
1
<?php
2
3
declare(strict_types=1);
10
namespace
Commercetools\Base
;
11
12
use DateTime;
13
use DateTimeImmutable;
14
15
class
MapperFactory
16
{
17
public
const
TIME_FORMAT
=
"H:i:s.u"
;
18
public
const
DATE_FORMAT
=
"Y-m-d"
;
19
public
const
DATETIME_FORMAT
=
"Y-m-d?H:i:s.uT"
;
20
24
public
static
function
stringMapper
()
25
{
26
return
28
function
($data): ?
string
{
29
if
(is_null($data)) {
30
return
null
;
31
}
32
return
(
string
)$data;
33
};
34
}
35
39
public
static
function
numberMapper
()
40
{
41
return
43
function
($data): ?
float
{
44
if
(is_null($data)) {
45
return
null
;
46
}
47
return
(
float
)$data;
48
};
49
}
50
54
public
static
function
integerMapper
()
55
{
56
return
58
function
($data): ?
int
{
59
if
(is_null($data)) {
60
return
null
;
61
}
62
return
(
int
)$data;
63
};
64
}
65
69
public
static
function
dateTimeMapper
(
string
$format = self::DATETIME_FORMAT)
70
{
71
return
73
function
($data) use ($format): ?DateTimeImmutable {
74
if
(is_null($data)) {
75
return
null
;
76
}
77
$date = DateTimeImmutable::createFromFormat($format, $data);
78
if
($date ===
false
) {
79
return
null
;
80
}
81
return
$date;
82
};
83
}
84
}
Commercetools\Base\MapperFactory
Definition:
MapperFactory.php:16
Commercetools\Base\MapperFactory\DATETIME_FORMAT
const DATETIME_FORMAT
Definition:
MapperFactory.php:19
Commercetools\Base\MapperFactory\TIME_FORMAT
const TIME_FORMAT
Definition:
MapperFactory.php:17
Commercetools\Base\MapperFactory\dateTimeMapper
static dateTimeMapper(string $format=self::DATETIME_FORMAT)
Definition:
MapperFactory.php:69
Commercetools\Base\MapperFactory\DATE_FORMAT
const DATE_FORMAT
Definition:
MapperFactory.php:18
Commercetools\Base\MapperFactory\stringMapper
static stringMapper()
Definition:
MapperFactory.php:24
Commercetools\Base\MapperFactory\integerMapper
static integerMapper()
Definition:
MapperFactory.php:54
Commercetools\Base\MapperFactory\numberMapper
static numberMapper()
Definition:
MapperFactory.php:39
Commercetools\Base
Definition:
MapperArraySequence.php:10
Generated by
1.9.1