|
@@ -6,7 +6,18 @@ use Luticate\Utils\DataAccess\LuDataAccess;
|
6
|
6
|
use Luticate\Utils\Dbo\LuDbo;
|
7
|
7
|
|
8
|
8
|
abstract class LuBusiness {
|
|
9
|
+ protected static $_resourceName = null;
|
|
10
|
+ protected static $_resourceNameUnPluralize = true;
|
9
|
11
|
|
|
12
|
+ /**
|
|
13
|
+ * @param string $reason
|
|
14
|
+ * @throws LuBusinessException
|
|
15
|
+ */
|
|
16
|
+ public static function badInput($reason = 'Invalid user input')
|
|
17
|
+ {
|
|
18
|
+ throw new LuBusinessException($reason, 400);
|
|
19
|
+ }
|
|
20
|
+
|
10
|
21
|
/**
|
11
|
22
|
* @param string $reason
|
12
|
23
|
* @throws LuBusinessException
|
|
@@ -20,18 +31,18 @@ abstract class LuBusiness {
|
20
|
31
|
* @param string $reason
|
21
|
32
|
* @throws LuBusinessException
|
22
|
33
|
*/
|
23
|
|
- public static function notFound($reason = 'Resource not found')
|
|
34
|
+ public static function forbidden($reason = 'Forbidden')
|
24
|
35
|
{
|
25
|
|
- throw new LuBusinessException($reason, 404);
|
|
36
|
+ throw new LuBusinessException($reason, 403);
|
26
|
37
|
}
|
27
|
38
|
|
28
|
39
|
/**
|
29
|
40
|
* @param string $reason
|
30
|
41
|
* @throws LuBusinessException
|
31
|
42
|
*/
|
32
|
|
- public static function badInput($reason = 'Invalid user input')
|
|
43
|
+ public static function notFound($reason = 'Resource not found')
|
33
|
44
|
{
|
34
|
|
- throw new LuBusinessException($reason, 400);
|
|
45
|
+ throw new LuBusinessException($reason, 404);
|
35
|
46
|
}
|
36
|
47
|
|
37
|
48
|
/**
|
|
@@ -79,8 +90,26 @@ abstract class LuBusiness {
|
79
|
90
|
|
80
|
91
|
public static function getResourceName()
|
81
|
92
|
{
|
82
|
|
- $match = [];
|
83
|
|
- preg_match('/([^\\\\]*)Business$/', get_called_class(), $match);
|
84
|
|
- return $match[1];
|
|
93
|
+ $res = static::$_resourceName;
|
|
94
|
+ if ($res == null) {
|
|
95
|
+ $match = [];
|
|
96
|
+ $className = get_called_class();
|
|
97
|
+ preg_match('/([^\\\\]*)Business$/', get_called_class(), $match);
|
|
98
|
+ if (count($match) < 2) {
|
|
99
|
+ $res = $className;
|
|
100
|
+ }
|
|
101
|
+ else {
|
|
102
|
+ $res = $match[1];
|
|
103
|
+ }
|
|
104
|
+ if (static::$_resourceNameUnPluralize) {
|
|
105
|
+ if (LuStringUtils::endsWith($res, "ies")) {
|
|
106
|
+ $res = substr($res, 0, strlen($res) - 3) . "y";
|
|
107
|
+ }
|
|
108
|
+ else if (LuStringUtils::endsWith($res, "s")) {
|
|
109
|
+ $res = substr($res, 0, strlen($res) - 1);
|
|
110
|
+ }
|
|
111
|
+ }
|
|
112
|
+ }
|
|
113
|
+ return $res;
|
85
|
114
|
}
|
86
|
115
|
}
|