Skip to content

Commit 51249eb

Browse files
committed
Create HttpCookiesTrait.php
1 parent e4622dc commit 51249eb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

src/Traits/HttpCookiesTrait.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Трейт списка http cookies.
4+
* @package evas-php\evas-http
5+
* @author Egor Vasyakin <[email protected]>
6+
*/
7+
namespace Evas\Http\Traits;
8+
9+
use Evas\Http\Cookie;
10+
11+
trait HttpCookiesTrait
12+
{
13+
/** @var array маппинг свойств cookie */
14+
protected $cookies = [];
15+
16+
/**
17+
* Установка свойств cookie.
18+
* @param array маппинг свойств cookie
19+
* @return self
20+
*/
21+
public function withCookies(array $cookies): object
22+
{
23+
$this->cookies = $cookies;
24+
return $this;
25+
}
26+
27+
/**
28+
* Установка свойства cookie.
29+
* @param string имя свойства cookie
30+
* @param mixed значение
31+
* @return self
32+
*/
33+
public function withCookie(string $name, $value): object
34+
{
35+
$this->cookies[$name] = $value;
36+
return $this;
37+
}
38+
39+
/**
40+
* Получение всех свойств cookie.
41+
* @return array
42+
*/
43+
public function getCookies(): array
44+
{
45+
return $this->cookies;
46+
}
47+
48+
/**
49+
* Получение свойства cookie.
50+
* @param string имя свойства cookie
51+
* @return mixed|null значение
52+
*/
53+
public function getCookie(string $name)
54+
{
55+
return $this->cookies[$name] ?? null;
56+
}
57+
58+
/**
59+
* Проверка наличия свойства cookie.
60+
* @param string имя свойства cookie
61+
* @return bool
62+
*/
63+
public function hasCookie(string $name): bool
64+
{
65+
return isset($this->cookies[$name]) ? true : false;
66+
}
67+
}

0 commit comments

Comments
 (0)