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
App
Http
Context.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Framework\App\Http
;
7
8
use
Magento\Framework\App\ObjectManager
;
9
use
Magento\Framework\Serialize\Serializer\Json
;
10
14
class
Context
15
{
19
const
CONTEXT_CURRENCY
=
'current_currency'
;
20
26
protected
$data
= [];
27
31
protected
$default
= [];
32
36
private
$serializer;
37
43
public
function
__construct
(array
$data
= [], array
$default
= [],
Json
$serializer =
null
)
44
{
45
$this->data =
$data
;
46
$this->
default
=
$default
;
47
$this->serializer = $serializer ?:
ObjectManager::getInstance
()->get(Json::class);
48
}
49
58
public
function
setValue
(
$name
,
$value
,
$default
)
59
{
60
if
(
$default
!==
null
) {
61
$this->
default
[
$name
] =
$default
;
62
}
63
$this->data[
$name
] =
$value
;
64
return
$this;
65
}
66
73
public
function
unsValue
(
$name
)
74
{
75
unset($this->data[
$name
]);
76
return
$this;
77
}
78
85
public
function
getValue
(
$name
)
86
{
87
return
$this->data[
$name
] ?? ($this->
default
[
$name
] ??
null
);
88
}
89
95
public
function
getData
()
96
{
97
$data
= [];
98
foreach
($this->data as
$name
=>
$value
) {
99
if
(
$value
&&
$value
!= $this->
default
[
$name
]) {
100
$data
[
$name
] =
$value
;
101
}
102
}
103
return
$data
;
104
}
105
111
public
function
getVaryString
()
112
{
113
$data
= $this->
getData
();
114
if
(!empty(
$data
)) {
115
ksort(
$data
);
116
return
sha1($this->serializer->serialize(
$data
));
117
}
118
return
null
;
119
}
120
126
public
function
toArray
()
127
{
128
return
[
129
'data'
=>
$this->data
,
130
'default'
=>
$this->default
131
];
132
}
133
}
Magento\Framework\Serialize\Serializer\Json
Definition:
Json.php:16
Magento\Framework\App\ObjectManager\getInstance
static getInstance()
Definition:
ObjectManager.php:33
Magento\Framework\App\Http\Context\setValue
setValue($name, $value, $default)
Definition:
Context.php:58
Magento\Framework\App\Http\Context\getVaryString
getVaryString()
Definition:
Context.php:111
Magento\Framework\App\Http\Context\__construct
__construct(array $data=[], array $default=[], Json $serializer=null)
Definition:
Context.php:43
Magento\Framework\App\Http\Context\CONTEXT_CURRENCY
const CONTEXT_CURRENCY
Definition:
Context.php:19
Magento\Framework\App\ObjectManager
Definition:
ConfigCache.php:8
Magento\Framework\App\Http\Context\getData
getData()
Definition:
Context.php:95
$value
$value
Definition:
gender.phtml:16
Magento\Framework\App\Http\Context\unsValue
unsValue($name)
Definition:
Context.php:73
Magento\Framework\App\Http\Context\toArray
toArray()
Definition:
Context.php:126
Magento\Framework\App\Http\Context\$data
$data
Definition:
Context.php:26
Magento\Framework\App\Http\Context\$default
$default
Definition:
Context.php:31
Magento\Framework\App\Http\Context
Definition:
Context.php:14
Magento\Framework\App\Http
Definition:
Context.php:6
Magento\Framework\App\Http\Context\getValue
getValue($name)
Definition:
Context.php:85
$name
if(!isset($_GET['name'])) $name
Definition:
log.php:14