1: <?php
2:
3: namespace Deimos\Cookie;
4:
5: use Deimos\Cookie\Extensions\Flash;
6:
7: class Cookie extends Extension
8: {
9:
10: use Flash;
11:
12: 13: 14: 15: 16: 17:
18: protected function decrypt($value, $options)
19: {
20: $secure = $this->secure($options);
21:
22: return $secure->decrypt($value);
23: }
24:
25: 26: 27: 28: 29: 30: 31: 32: 33:
34: public function get($name, $default = null, array $options = [])
35: {
36: $options = $this->options($options);
37: $value = $this->helper()->arr()->get($this->storage(), $name, $default);
38:
39: return $value === null || $value === $default ? $default : $this->decrypt($value, $options);
40: }
41:
42: 43: 44: 45: 46: 47: 48: 49: 50:
51: public function getRequired($name, array $options = [])
52: {
53: $options = $this->options($options);
54: $value = $this->helper()->arr()->getRequired($this->storage(), $name);
55:
56: return $this->decrypt($value, $options);
57: }
58:
59: 60: 61: 62: 63: 64: 65: 66: 67:
68: public function __get($name)
69: {
70: return $this->get($name);
71: }
72:
73: 74: 75: 76: 77: 78: 79:
80: public function set($name, $value, array $options = [])
81: {
82: $options = $this->options($options);
83: $value = parent::set($name, $value, $options);
84:
85: return setcookie(
86: $this->normalize($name),
87: $value,
88: $options[self::OPTION_EXPIRE],
89: $options[self::OPTION_PATH],
90: $options[self::OPTION_DOMAIN],
91: false,
92: $options[self::OPTION_HTTP_ONLY]
93: );
94: }
95:
96: 97: 98: 99: 100: 101: 102:
103: public function remove($name)
104: {
105: parent::remove($name);
106:
107: return $this->set($name, null, [
108: self::OPTION_EXPIRE => 0
109: ]);
110: }
111:
112: 113: 114: 115: 116: 117:
118: public function __set($name, $value)
119: {
120: $this->set($name, $value);
121: }
122:
123: 124: 125: 126: 127: 128: 129:
130: public function __isset($name)
131: {
132: return $this->helper()->arr()->keyExists($this->storage(), $name);
133: }
134:
135: 136: 137:
138: protected function storage()
139: {
140: return $this->object() ?: [];
141: }
142:
143: }