|
@@ -3,52 +3,40 @@
|
3
|
3
|
namespace Luticate\Utils;
|
4
|
4
|
|
5
|
5
|
class LuBusiness {
|
6
|
|
- /**
|
7
|
|
- * @var array
|
8
|
|
- */
|
9
|
|
- private $parameters = [];
|
10
|
6
|
|
11
|
7
|
/**
|
12
|
8
|
* @var LuDataAccess
|
13
|
9
|
*/
|
14
|
10
|
protected $dataAccess = null;
|
15
|
11
|
|
16
|
|
- /**
|
17
|
|
- * @param array $parametersSource
|
18
|
|
- */
|
19
|
|
- public function __construct(array $parametersSource)
|
20
|
|
- {
|
21
|
|
- $this->parameters = $parametersSource;
|
22
|
|
- }
|
23
|
|
-
|
24
|
12
|
/**
|
25
|
13
|
* @param string $name
|
26
|
14
|
* @param mixed $default
|
27
|
15
|
* @return mixed
|
28
|
16
|
*/
|
29
|
|
- protected function getParam($name, $default = null)
|
|
17
|
+ public static function getParam($name, $default = null)
|
30
|
18
|
{
|
31
|
|
- return array_key_exists($name, $this->parameters) ? $this->parameters[$name] : $default;
|
|
19
|
+ return array_key_exists($name, LuController::$parameters) ? LuController::$parameters[$name] : $default;
|
32
|
20
|
}
|
33
|
21
|
|
34
|
22
|
/**
|
35
|
23
|
* @param string $name
|
36
|
24
|
* @param mixed $value
|
37
|
25
|
*/
|
38
|
|
- public function setParam($name, $value)
|
|
26
|
+ public static function setParam($name, $value)
|
39
|
27
|
{
|
40
|
|
- $this->parameters[$name] = $value;
|
|
28
|
+ LuController::$parameters[$name] = $value;
|
41
|
29
|
}
|
42
|
30
|
|
43
|
31
|
/**
|
44
|
32
|
* @param string[] $params
|
45
|
33
|
* @return bool
|
46
|
34
|
*/
|
47
|
|
- public function hasParam(array $params)
|
|
35
|
+ public static function hasParam(array $params)
|
48
|
36
|
{
|
49
|
37
|
foreach ($params as $p)
|
50
|
38
|
{
|
51
|
|
- if (!array_key_exists($p, $this->parameters))
|
|
39
|
+ if (!array_key_exists($p, LuController::$parameters))
|
52
|
40
|
return false;
|
53
|
41
|
}
|
54
|
42
|
return true;
|
|
@@ -59,9 +47,9 @@ class LuBusiness {
|
59
|
47
|
* @param mixed $validate
|
60
|
48
|
* @return string
|
61
|
49
|
*/
|
62
|
|
- public function checkParam($param, $validate = null)
|
|
50
|
+ public static function checkParam($param, $validate = null)
|
63
|
51
|
{
|
64
|
|
- $value = $this->getParam($param);
|
|
52
|
+ $value = self::getParam($param);
|
65
|
53
|
if (is_null($value) || trim($value) == '')
|
66
|
54
|
abort(400, 'Missing parameter: ' . $param);
|
67
|
55
|
if ($validate != null) {
|
|
@@ -80,7 +68,7 @@ class LuBusiness {
|
80
|
68
|
/**
|
81
|
69
|
* @param string
|
82
|
70
|
*/
|
83
|
|
- public function unauthorized($reason = 'Unauthorized')
|
|
71
|
+ public static function unauthorized($reason = 'Unauthorized')
|
84
|
72
|
{
|
85
|
73
|
abort(401, $reason);
|
86
|
74
|
}
|
|
@@ -88,7 +76,7 @@ class LuBusiness {
|
88
|
76
|
/**
|
89
|
77
|
* @param string
|
90
|
78
|
*/
|
91
|
|
- public function notFound($reason = 'Resource not found')
|
|
79
|
+ public static function notFound($reason = 'Resource not found')
|
92
|
80
|
{
|
93
|
81
|
abort(404, $reason);
|
94
|
82
|
}
|
|
@@ -98,9 +86,9 @@ class LuBusiness {
|
98
|
86
|
* @param $values string[]
|
99
|
87
|
* @return string
|
100
|
88
|
*/
|
101
|
|
- public function getParamInArray($param, $values)
|
|
89
|
+ public static function getParamInArray($param, $values)
|
102
|
90
|
{
|
103
|
|
- $value = $this->getParam($param);
|
|
91
|
+ $value = self::getParam($param);
|
104
|
92
|
if (is_null($value) || !in_array($value, $values))
|
105
|
93
|
$value = $values[0];
|
106
|
94
|
return $value;
|
|
@@ -111,14 +99,21 @@ class LuBusiness {
|
111
|
99
|
* @param $default int
|
112
|
100
|
* @return int
|
113
|
101
|
*/
|
114
|
|
- public function getParamInt($param, $default = 0)
|
|
102
|
+ public static function getParamInt($param, $default = 0)
|
115
|
103
|
{
|
116
|
|
- $value = $this->getParam($param);
|
|
104
|
+ $value = self::getParam($param);
|
117
|
105
|
if (!is_null($value) && is_numeric($value))
|
118
|
106
|
return (int)$value;
|
119
|
107
|
return $default;
|
120
|
108
|
}
|
121
|
109
|
|
|
110
|
+ public static function __callStatic($name, $arguments)
|
|
111
|
+ {
|
|
112
|
+ $class = get_called_class();
|
|
113
|
+ $me = new $class();
|
|
114
|
+ return call_user_func_array(array($me, $name), $arguments);
|
|
115
|
+ }
|
|
116
|
+
|
122
|
117
|
/**
|
123
|
118
|
* @param $page int
|
124
|
119
|
* @param $perPage int
|
|
@@ -151,31 +146,4 @@ class LuBusiness {
|
151
|
146
|
{
|
152
|
147
|
$this->dataAccess->deleteById($id);
|
153
|
148
|
}
|
154
|
|
-
|
155
|
|
- /**
|
156
|
|
- * @param $data LuDbo
|
157
|
|
- * @return int
|
158
|
|
- */
|
159
|
|
- public function addId($data)
|
160
|
|
- {
|
161
|
|
- return $this->dataAccess->addId($data);
|
162
|
|
- }
|
163
|
|
-
|
164
|
|
- /**
|
165
|
|
- * @param $data LuDbo
|
166
|
|
- */
|
167
|
|
- public function add($data)
|
168
|
|
- {
|
169
|
|
- $this->dataAccess->add($data);
|
170
|
|
- }
|
171
|
|
-
|
172
|
|
- /**
|
173
|
|
- * @param $id int
|
174
|
|
- * @param $data LuDbo
|
175
|
|
- * @return LuDbo|null
|
176
|
|
- */
|
177
|
|
- public function editById($id, $data)
|
178
|
|
- {
|
179
|
|
- return $this->dataAccess->editById($id, $data);
|
180
|
|
- }
|
181
|
149
|
}
|