8000 Remove logic for "only" and "except" · sablesoft/laravel-json-api@da1fd4e · GitHub
[go: up one dir, main page]

Skip to content

Commit da1fd4e

Browse files
committed
Remove logic for "only" and "except"
1 parent bd745d1 commit da1fd4e

File tree

1 file changed

+7
-46
lines changed

1 file changed

+7
-46
lines changed

src/Routing/ResourceRegistrar.php

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,12 @@ class ResourceRegistrar
3737
*/
3838
protected $router;
3939

40-
/**
41-
* @type array
42-
*/
43-
protected $resourceDefaults;
44-
45-
/**
46-
* @type array
47-
*/
48-
protected $rootUrlMethods = ['index', 'create'];
49-
5040
/**
5141
* @param Registrar $router
5242
*/
5343
public function __construct(Registrar $router)
5444
{
5545
$this->router = $router;
56-
57-
$this->resourceDefaults = [
58-
'index' => 'get',
59-
'create' => 'post',
60-
'read' => 'get',
61-
'update' => 'patch',
62-
'delete' => 'delete',
63-
];
6446
}
6547

6648
/**
@@ -76,7 +58,7 @@ public function resource($name, $controller, array $options = [])
7658
$hasOne = isset($options[static::HAS_ONE]) ? (array) $options[static::HAS_ONE] : [];
7759
$hasMany = isset($options[static::HAS_MANY]) ? (array) $options[static::HAS_MANY] : [];
7860

79-
$this->registerResource($rootUrl, $objectUrl, $controller, $options)
61+
$this->registerResource($rootUrl, $objectUrl, $controller)
8062
->registerHasOne($objectUrl, $controller, $hasOne)
8163
->registerHasMany($objectUrl, $controller, $hasMany);
8264
}
@@ -85,19 +67,15 @@ public function resource($name, $controller, array $options = [])
8567
* @param $rootUrl
8668
* @param $objectUrl
8769
* @param $controller
88-
* @param $options
8970
* @return $this
9071
*/
91-
private function registerResource($rootUrl, $objectUrl, $controller, $options)
72+
private function registerResource($rootUrl, $objectUrl, $controller)
9273
{
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');
10179

10280
return $this;
10381
}
@@ -144,21 +122,4 @@ private function registerHasMany($objectUrl, $controller, array $relations)
144122

145123
return $this;
146124
}
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-
}
164125
}

0 commit comments

Comments
 (0)
0