| 1 | <?php |
||
| 12 | trait Cookie { |
||
| 13 | /** |
||
| 14 | * Cookie array, similar to `$_COOKIE`, but also contains un-prefixed keys according to system configuration |
||
| 15 | * |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | public $cookie; |
||
| 19 | /** |
||
| 20 | * @param array $cookie Typically `$_COOKIE` |
||
| 21 | */ |
||
| 22 | 26 | function init_cookie ($cookie = []) { |
|
| 23 | 26 | $this->cookie = $cookie; |
|
| 24 | /** |
||
| 25 | * Fill un-prefixed keys according to system configuration |
||
| 26 | */ |
||
| 27 | 26 | $prefix = Config::instance()->core['cookie_prefix']; |
|
| 28 | 26 | $prefix_length = strlen($prefix); |
|
| 29 | 26 | if ($prefix_length) { |
|
| 30 | 2 | foreach ($cookie as $key => $value) { |
|
| 31 | 2 | if (strpos($key, $prefix) === 0) { |
|
| 32 | 2 | $this->cookie[substr($key, $prefix_length)] = $value; |
|
| 33 | } |
||
| 34 | } |
||
| 35 | } |
||
| 36 | 26 | } |
|
| 37 | /** |
||
| 38 | * Get cookie by name |
||
| 39 | * |
||
| 40 | * @param string $name |
||
| 41 | * |
||
| 42 | * @return null|string Cookie content if exists or `null` otherwise |
||
| 43 | */ |
||
| 44 | 34 | function cookie ($name) { |
|
| 47 | } |
||
| 48 |