This repository was archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathSettings.php
More file actions
138 lines (120 loc) · 2.87 KB
/
Settings.php
File metadata and controls
138 lines (120 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php namespace ostark\upper\models;
use Craft;
use craft\base\Model;
use yii\helpers\Inflector;
/**
* Upper Settings Model
*
* This is a model used to define the plugin's settings.
*
* Models are containers for data. Just about every time information is passed
* between services, controllers, and templates in Craft, it’s passed via a model.
*
* https://craftcms.com/docs/plugins/models
*
* @author Oliver Stark
* @package Upper
* @since 1.0.0
*/
class Settings extends Model
{
// Public Properties
// =========================================================================
/**
* Some field model attribute
*
* @var string
*/
public $driver;
/**
* Some field model attribute
*
* @var array
*/
public $drivers;
/**
* Some field model attribute
*
* @var int
*/
public $defaultMaxAge = null;
/**
* @var bool
*/
public $useLocalTags = true;
/**
* Key prefix
*
* @var string
*/
public $keyPrefix = '';
/**
* Max kilobytes of the X-Cachetag header
*
* @var int
*/
public $maxBytesForCacheTagHeader = null;
// Public Methods
// =========================================================================
/**
* Returns the validation rules for attributes.
*
* Validation rules are used by [[validate()]] to check if attribute values are valid.
* Child classes may override this method to declare different validation rules.
*
* More info: http://www.yiiframework.com/doc-2.0/guide-input-validation.html
*
* @return array
*/
public function rules()
{
return [
[['driver', 'drivers','keyPrefix'], 'required'],
];
}
/**
* @return string
*/
public function getTagHeaderName()
{
return $this->drivers[$this->driver]['tagHeaderName'];
}
/**
* @return string
*/
public function getHeaderTagDelimiter()
{
return $this->drivers[$this->driver]['tagHeaderDelimiter'] ?? ' ';
}
/**
* Get key prefix.
* To prevent key collision if you use the same
* cache server for several Craft installations.
*
* @return string
*/
public function getKeyPrefix()
{
if (!$this->keyPrefix) {
return '';
}
$clean = Inflector::slug($this->keyPrefix);
return substr($clean, 0, 8);
}
/**
* @return array
*/
public function getNoCacheElements()
{
return ['craft\elements\User', 'craft\elements\MatrixBlock', 'verbb\supertable\elements\SuperTableBlockElement'];
}
/**
* @param string $class
*
* @return bool
*/
public function isCachableElement(string $class)
{
return in_array($class, $this->getNoCacheElements()) ? false : true;
}
}