1
|
|
|
<?php namespace Limoncello\Application\Packages\Cookies; |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2015-2017 [email protected] |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use Limoncello\Contracts\Settings\SettingsInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @package Limoncello\Application |
23
|
|
|
*/ |
24
|
|
|
class CookieSettings implements SettingsInterface |
25
|
|
|
{ |
26
|
|
|
/** Settings key */ |
27
|
|
|
const KEY_DEFAULT_PATH = 0; |
28
|
|
|
|
29
|
|
|
/** Settings key */ |
30
|
|
|
const KEY_DEFAULT_DOMAIN = self::KEY_DEFAULT_PATH + 1; |
31
|
|
|
|
32
|
|
|
/** Settings key */ |
33
|
|
|
const KEY_DEFAULT_IS_SEND_ONLY_OVER_SECURE_CONNECTION = self::KEY_DEFAULT_DOMAIN + 1; |
34
|
|
|
|
35
|
|
|
/** Settings key */ |
36
|
|
|
const KEY_DEFAULT_IS_ACCESSIBLE_ONLY_THROUGH_HTTP = self::KEY_DEFAULT_IS_SEND_ONLY_OVER_SECURE_CONNECTION + 1; |
37
|
|
|
|
38
|
|
|
/** Settings key */ |
39
|
|
|
const KEY_DEFAULT_IS_RAW = self::KEY_DEFAULT_IS_ACCESSIBLE_ONLY_THROUGH_HTTP + 1; |
40
|
|
|
|
41
|
|
|
/** Settings key */ |
42
|
|
|
const KEY_LAST = self::KEY_DEFAULT_IS_RAW; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
|
|
final public function get(): array |
48
|
|
|
{ |
49
|
|
|
$defaults = $this->getSettings(); |
50
|
|
|
|
51
|
|
|
$path = $defaults[static::KEY_DEFAULT_PATH] ?? null; |
52
|
|
|
assert(is_string($path), 'Invalid default path.'); |
53
|
|
|
|
54
|
|
|
$domain = $defaults[static::KEY_DEFAULT_DOMAIN] ?? null; |
55
|
|
|
assert(is_string($domain), 'Invalid default domain.'); |
56
|
|
|
|
57
|
|
|
$isSecure = $defaults[static::KEY_DEFAULT_IS_SEND_ONLY_OVER_SECURE_CONNECTION] ?? null; |
58
|
|
|
assert(is_bool($isSecure), 'Invalid `secure` value.'); |
59
|
|
|
|
60
|
|
|
$isHttpOnly = $defaults[static::KEY_DEFAULT_IS_ACCESSIBLE_ONLY_THROUGH_HTTP] ?? null; |
61
|
|
|
assert(is_bool($isHttpOnly), 'Invalid `httpOnly` value.'); |
62
|
|
|
|
63
|
|
|
$isRaw = $defaults[static::KEY_DEFAULT_IS_RAW] ?? null; |
64
|
|
|
assert(is_bool($isRaw), 'Invalid Send Raw Cookies value.'); |
65
|
|
|
|
66
|
|
|
return $defaults; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function getSettings(): array |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
static::KEY_DEFAULT_PATH => '', |
76
|
|
|
static::KEY_DEFAULT_DOMAIN => '', |
77
|
|
|
static::KEY_DEFAULT_IS_SEND_ONLY_OVER_SECURE_CONNECTION => false, |
78
|
|
|
static::KEY_DEFAULT_IS_ACCESSIBLE_ONLY_THROUGH_HTTP => true, |
79
|
|
|
static::KEY_DEFAULT_IS_RAW => false, |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|