Skip to content

Commit

Permalink
添加sameSite属性
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrychen committed Apr 21, 2020
1 parent db4c3b4 commit c9a8300
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/http-message/src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Cookie
* Default cookie properties
*/
public const DEFAULTS = [
'value' => '',
'domain' => '',
'path' => '',
'expires' => 0,
'secure' => false,
'value' => '',
'domain' => '',
'path' => '',
'expires' => 0,
'secure' => false,
'httpOnly' => false,
'hostOnly' => false,
'sameSite' => ''
Expand All @@ -33,7 +33,7 @@ class Cookie
/**
* SameSite Values
*/
public const SAME_SITE_VALUES = ['Strict','Lax','None'];
public const SAME_SITE_VALUES = ['Strict', 'Lax', 'None'];

/**
* @var string
Expand Down Expand Up @@ -63,7 +63,7 @@ class Cookie
/**
* @var bool
*/
private $secure = false;
private $secure = false;

/**
* @var bool
Expand All @@ -80,13 +80,10 @@ class Cookie
*/
private $sameSite = '';


/**
* @param array $config
*
* @return self
* @throws \ReflectionException
* @throws \Swoft\Bean\Exception\ContainerException
*/
public static function new(array $config = []): self
{
Expand All @@ -105,11 +102,11 @@ public static function new(array $config = []): self
public function toArray(): array
{
return [
'value' => $this->value,
'domain' => $this->domain,
'path' => $this->path,
'expires' => $this->expires,
'secure' => $this->secure,
'value' => $this->value,
'domain' => $this->domain,
'path' => $this->path,
'expires' => $this->expires,
'secure' => $this->secure,
'httpOnly' => $this->httpOnly,
'hostOnly' => $this->hostOnly,
'sameSite' => $this->sameSite,
Expand Down Expand Up @@ -151,7 +148,6 @@ public function toString(): string
$result .= '; HttpOnly';
}


return $result;
}

Expand All @@ -168,7 +164,7 @@ public function __toString(): string
*/
public function delete(): void
{
$this->value = '';
$this->value = '';
$this->expires = -60;
}

Expand Down Expand Up @@ -339,9 +335,9 @@ public function getSameSite(): string
*/
public function setSameSite(string $sameSite): Cookie
{
if (in_array($sameSite,static::SAME_SITE_VALUES)){
if (in_array($sameSite, static::SAME_SITE_VALUES)) {
$this->sameSite = $sameSite;
}else{
} else {
$this->sameSite = '';
}

Expand Down

0 comments on commit c9a8300

Please sign in to comment.