1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) Flipbox Digital Limited |
5
|
|
|
* @license https://flipboxfactory.com/software/restful/license |
6
|
|
|
* @link https://www.flipboxfactory.com/software/restful/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace flipbox\craft\restful\models; |
10
|
|
|
|
11
|
|
|
use Craft; |
12
|
|
|
use craft\base\Model; |
13
|
|
|
use yii\rbac\CheckAccessInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Flipbox Factory <[email protected]> |
17
|
|
|
* @since 1.0.0 |
18
|
|
|
*/ |
19
|
|
|
class Settings extends Model |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
public $pageSizeParam = 'limit'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $pageParam = 'page'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
public $pageSizeLimit = [0, 1, 50, 100, 200, 500, 1000]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
public $defaultPageSize = 50; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private $authMethods = []; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var null|CheckAccessInterface |
48
|
|
|
*/ |
49
|
|
|
private $accessChecker; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var array |
53
|
|
|
*/ |
54
|
|
|
private $cors = []; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param array $cors |
58
|
|
|
* @return $this |
59
|
|
|
*/ |
60
|
|
|
public function setCORS(array $cors = []) |
61
|
|
|
{ |
62
|
|
|
$this->cors = $cors; |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
public function getCORS(): array |
70
|
|
|
{ |
71
|
|
|
return $this->cors; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function getAuthMethods(): array |
78
|
|
|
{ |
79
|
|
|
return $this->authMethods; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param array $authMethods |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function setAuthMethods(array $authMethods = []) |
87
|
|
|
{ |
88
|
|
|
$this->authMethods = $authMethods; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return null|CheckAccessInterface |
94
|
|
|
*/ |
95
|
|
|
public function getAccessChecker() |
96
|
|
|
{ |
97
|
|
|
return $this->accessChecker ?: Craft::$app->getAuthManager(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param CheckAccessInterface|null $authManager |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
|
|
public function setAccessChecker(CheckAccessInterface $authManager = null) |
105
|
|
|
{ |
106
|
|
|
$this->accessChecker = $authManager; |
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @inheritdoc |
112
|
|
|
*/ |
113
|
|
|
public function attributes() |
114
|
|
|
{ |
115
|
|
|
return array_merge( |
116
|
|
|
parent::attributes(), |
117
|
|
|
[ |
118
|
|
|
'authMethods', |
119
|
|
|
'cors' |
120
|
|
|
] |
121
|
|
|
); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|