Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
framework
Reflection
TypeCaster.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Framework\Reflection
;
7
8
use
Magento\Framework\Serialize\Serializer\Json
;
9
13
class
TypeCaster
14
{
18
private
$serializer;
19
23
public
function
__construct
(
Json
$serializer)
24
{
25
$this->serializer =
$serializer
;
26
}
27
37
public
function
castValueToType
(
$value
,
$type
)
38
{
39
if
(
$value
===
null
) {
40
return
null
;
41
}
42
49
if
(is_array(
$value
) && !interface_exists(
$type
) && !
class_exists
(
$type
)) {
50
return
$this->serializer->serialize(
$value
);
51
}
52
53
if
(
$type
===
"int"
||
$type
===
"integer"
) {
54
return
(
int
)
$value
;
55
}
56
57
if
(
$type
===
"string"
) {
58
return
(
string
)
$value
;
59
}
60
61
if
(
$type
===
"bool"
||
$type
===
"boolean"
||
$type
===
"true"
||
$type
==
"false"
) {
62
return
(
bool
)
$value
;
63
}
64
65
if
(
$type
===
"float"
) {
66
return
(
float
)
$value
;
67
}
68
69
if
(
$type
===
"double"
) {
70
return
(
double
)
$value
;
71
}
72
73
return
$value
;
74
}
75
}
Magento\Framework\Serialize\Serializer\Json
Definition:
Json.php:16
Magento\Framework\Reflection\TypeCaster\castValueToType
castValueToType($value, $type)
Definition:
TypeCaster.php:37
Magento\Framework\Reflection
Definition:
AttributeTypeResolver.php:7
$serializer
$serializer
Definition:
quote_with_payment_saved.php:10
$type
$type
Definition:
item.phtml:13
$value
$value
Definition:
gender.phtml:16
Magento\Framework\Code\Generator\class_exists
class_exists($className)
Definition:
DefinedClassesTest.php:15
Magento\Framework\Reflection\TypeCaster\__construct
__construct(Json $serializer)
Definition:
TypeCaster.php:23
Magento\Framework\Reflection\TypeCaster
Definition:
TypeCaster.php:13