@@ -37,30 +37,12 @@ class ResourceRegistrar
37
37
*/
38
38
protected $ router ;
39
39
40
- /**
41
- * @type array
42
- */
43
- protected $ resourceDefaults ;
44
-
45
- /**
46
- * @type array
47
- */
48
- protected $ rootUrlMethods = ['index ' , 'create ' ];
49
-
50
40
/**
51
41
* @param Registrar $router
52
42
*/
53
43
public function __construct (Registrar $ router )
54
44
{
55
45
$ this ->router = $ router ;
56
-
57
- $ this ->resourceDefaults = [
58
- 'index ' => 'get ' ,
59
- 'create ' => 'post ' ,
60
- 'read ' => 'get ' ,
61
- 'update ' => 'patch ' ,
62
- 'delete ' => 'delete ' ,
63
- ];
64
46
}
65
47
66
48
/**
@@ -76,7 +58,7 @@ public function resource($name, $controller, array $options = [])
76
58
$ hasOne = isset ($ options [static ::HAS_ONE ]) ? (array ) $ options [static ::HAS_ONE ] : [];
77
59
$ hasMany = isset ($ options [static ::HAS_MANY ]) ? (array ) $ options [static ::HAS_MANY ] : [];
78
60
79
- $ this ->registerResource ($ rootUrl , $ objectUrl , $ controller, $ options )
61
+ $ this ->registerResource ($ rootUrl , $ objectUrl , $ controller )
80
62
->registerHasOne ($ objectUrl , $ controller , $ hasOne )
81
63
->registerHasMany ($ objectUrl , $ controller , $ hasMany );
82
64
}
@@ -85,19 +67,15 @@ public function resource($name, $controller, array $options = [])
85
67
* @param $rootUrl
86
68
* @param $objectUrl
87
69
* @param $controller
88
- * @param $options
89
70
* @return $this
90
71
*/
91
- private function registerResource ($ rootUrl , $ objectUrl , $ controller, $ options )
72
+ private function registerResource ($ rootUrl , $ objectUrl , $ controller )
92
73
{
93
- foreach ($ this ->getResourceMethods ($ options ) as $ method ) {
94
- $ url = in_array ($ method ,
95
- $ this ->rootUrlMethods ) ? $ rootUrl : $ objectUrl ;
96
- call_user_func_array (
97
- [$ this ->router , $ this ->resourceDefaults [$ method ],],
98
- [$ url , $ controller . '@ ' . $ method ,]
99
- );
100
- }
74
+ $ this ->router ->get ($ rootUrl , $ controller . '@index ' );
75
+ $ this ->router ->post ($ rootUrl , $ controller . '@create ' );
76
+ $ this ->router ->get ($ objectUrl , $ controller . '@read ' );
77
+ $ this ->router ->patch ($ objectUrl , $ controller . '@update ' );
78
+ $ this ->router ->delete ($ objectUrl , $ controller . '@delete ' );
101
79
102
80
return $ this ;
103
81
}
@@ -144,21 +122,4 @@ private function registerHasMany($objectUrl, $controller, array $relations)
144
122
145
123
return $ this ;
146
124
}
147
-
148
- /**
149
- * Get the applicable resource methods.
150
- *
151
- * @param $options
152
- * @return array
153
- */
154
- protected function getResourceMethods ($ options )
155
- {
156
- $ defaults = array_keys ($ this ->resourceDefaults );
157
- if (isset ($ options ['only ' ])) {
158
- return array_intersect ($ defaults , (array ) $ options ['only ' ]);
159
- } elseif (isset ($ options ['except ' ])) {
160
- return array_diff ($ defaults , (array ) $ options ['except ' ]);
161
- }
162
- return $ defaults ;
163
- }
164
125
}
0 commit comments