You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
740 B
PHP
37 lines
740 B
PHP
<?php
|
|
|
|
namespace BitCommunism\Http\Context;
|
|
|
|
|
|
use Dflydev\FigCookies\Cookie;
|
|
use Dflydev\FigCookies\Cookies;
|
|
|
|
trait RequestTraits
|
|
{
|
|
/**
|
|
* @var Cookies
|
|
*/
|
|
protected $cookies;
|
|
|
|
public function getCookies(): Cookies {
|
|
if ($this->cookies === null) {
|
|
$this->cookies = Cookies::fromRequest($this->getRequest());
|
|
}
|
|
|
|
return $this->cookies;
|
|
}
|
|
|
|
public function getCookie($name): ?Cookie {
|
|
return $this->getCookies()->get($name);
|
|
}
|
|
|
|
public function getCookieValue(string $name, string $default = ""): string {
|
|
$cookie = $this->getCookie($name);
|
|
|
|
if ($cookie !== null) {
|
|
return $cookie->getValue();
|
|
}
|
|
|
|
return $default;
|
|
}
|
|
} |