Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
httpcookies.php
1
<?php
2
10
namespace
Bitrix\Main\Web
;
11
12
use
Bitrix\Main\ArgumentTypeException
;
13
14
class
HttpCookies
extends
\Bitrix\Main\Type\Dictionary
15
{
17
protected
$values
= [];
18
22
public
function
__construct
(array
$values
=
null
)
23
{
24
if
(
$values
!==
null
)
25
{
26
foreach
(
$values
as $key => $value)
27
{
28
if
(!($value instanceof Http\
Cookie
))
29
{
30
$value =
new
Http\Cookie
($key, $value);
31
}
32
$this[$key] = $value;
33
}
34
}
35
}
36
41
public
function
implode
(): string
42
{
43
$str =
''
;
44
foreach
($this->values as $cookie)
45
{
46
$str .= ($str ==
''
?
''
:
'; '
) . rawurlencode($cookie->getName()) .
'='
. rawurlencode($cookie->getValue());
47
}
48
return
$str;
49
}
50
51
public
function
addFromString
(
string
$str): void
52
{
53
if
(($pos = strpos($str,
';'
)) !==
false
&& $pos > 0)
54
{
55
$cookie = trim(substr($str, 0, $pos));
56
}
57
else
58
{
59
$cookie = trim($str);
60
}
61
$arCookie = explode(
'='
, $cookie, 2);
62
63
$name = rawurldecode($arCookie[0]);
64
$value = rawurldecode($arCookie[1]);
65
66
// TODO: a cookie has more attributes
67
$this[$name] =
new
Http\Cookie
($name, $value);
68
}
69
70
public
function
toArray
()
71
{
72
$cookies = [];
73
foreach
($this->values as $cookie)
74
{
75
$cookies[$cookie->getName()] = $cookie->getValue();
76
}
77
return
$cookies;
78
}
79
80
#[\ReturnTypeWillChange]
81
public
function
offsetSet
($offset, $value)
82
{
83
if
(!($value instanceof Http\
Cookie
))
84
{
85
throw
new
ArgumentTypeException
(
'value'
, Http\Cookie::class);
86
}
87
parent::offsetSet($offset, $value);
88
}
89
}
Bitrix\Main\ArgumentTypeException
Definition
exception.php:114
Bitrix\Main\Type\Dictionary
Definition
dictionary.php:6
Bitrix\Main\Web\Cookie
Definition
cookie.php:8
Bitrix\Main\Web\HttpCookies
Definition
httpcookies.php:15
Bitrix\Main\Web\HttpCookies\implode
implode()
Definition
httpcookies.php:41
Bitrix\Main\Web\HttpCookies\__construct
__construct(array $values=null)
Definition
httpcookies.php:22
Bitrix\Main\Web\HttpCookies\toArray
toArray()
Definition
httpcookies.php:70
Bitrix\Main\Web\HttpCookies\addFromString
addFromString(string $str)
Definition
httpcookies.php:51
Bitrix\Main\Web\HttpCookies\offsetSet
offsetSet($offset, $value)
Definition
httpcookies.php:81
Bitrix\Main\Web\HttpCookies\$values
$values
Definition
httpcookies.php:17
Bitrix\Main\Web
Definition
cookie.php:3
modules
main
lib
web
httpcookies.php
Создано системой
1.10.0