added findClassNameEndpoint method, replaced getEndpointAlias()

This commit is contained in:
Sander Hagenaars 2019-07-04 09:27:39 +02:00
parent d27156e890
commit 7eb95693f7

View File

@ -186,15 +186,10 @@ class RestfulServer extends Controller
*/ */
public function index(HTTPRequest $request) public function index(HTTPRequest $request)
{ {
$endpoint = $request->param('ClassName'); $className = $this->unsanitiseClassName($this->findClassNameEndpoint($request->param('ClassName')));
$className = $this->unsanitiseClassName($endpoint);
$id = $request->param('ID') ?: null; $id = $request->param('ID') ?: null;
$relation = $request->param('Relation') ?: null; $relation = $request->param('Relation') ?: null;
if ($alias = $this->getEndpointAlias($endpoint)) {
$className = $alias;
}
// Check input formats // Check input formats
if (!class_exists($className)) { if (!class_exists($className)) {
return $this->notFound(); return $this->notFound();
@ -905,13 +900,15 @@ class RestfulServer extends Controller
} }
/** /**
* Checks if given $endpoint maps to an object in endpoint_aliases, else simply return $endpoint as is
*
* @param $endpoint * @param $endpoint
* @return null | string * @return null | string
*/ */
protected function getEndpointAlias($endpoint) protected function findClassNameEndpoint($endpoint)
{ {
$aliases = self::config()->get('endpoint_aliases'); $aliases = self::config()->get('endpoint_aliases');
return $aliases[$endpoint] ?? null; return $aliases[$endpoint] ?? $endpoint;
} }
} }