-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
namespace Packaged\Context\Cookie; | ||
|
||
use Packaged\Context\ContextAware; | ||
use Packaged\Context\ContextAwareTrait; | ||
use Packaged\Context\WithContext; | ||
use Packaged\Context\WithContextTrait; | ||
|
||
abstract class ContextCookie implements ContextAware, WithContext | ||
{ | ||
use ContextAwareTrait; | ||
use WithContextTrait; | ||
|
||
/** | ||
* @var string|null | ||
*/ | ||
private $_rawValue; | ||
|
||
abstract public function name(): string; | ||
|
||
abstract public function ttl(): int; | ||
|
||
public function exists(bool $checkQueued = true) | ||
{ | ||
return $this->getContext()->cookies()->has($this->name(), $checkQueued); | ||
} | ||
|
||
public function read(bool $checkQueued = true) | ||
{ | ||
return $this->_setRawValue($this->getContext()->cookies()->read($this->name(), $checkQueued)); | ||
} | ||
|
||
protected function _getRawValue(): ?string | ||
{ | ||
return $this->_rawValue; | ||
} | ||
|
||
protected function _setRawValue(string $value) | ||
{ | ||
$this->_rawValue = $value; | ||
return $this; | ||
} | ||
|
||
public function store() | ||
{ | ||
$this->getContext()->cookies()->store($this->name(), $this->_getRawValue(), $this->ttl()); | ||
return $this; | ||
} | ||
} |