diff --git a/core/classes/Endpoints/EndpointBase.php b/core/classes/Endpoints/EndpointBase.php index 1614f5b2a4..356bcf7788 100644 --- a/core/classes/Endpoints/EndpointBase.php +++ b/core/classes/Endpoints/EndpointBase.php @@ -87,4 +87,14 @@ final public function getAuthType(): string * @return bool */ abstract public function isAuthorised(Nameless2API $api): bool; + + /** + * Allow auth methods to add custom params to endpoint. + * + * @return array Custom endpoint params + */ + public function customParams(): array + { + return []; + } } diff --git a/core/classes/Endpoints/Endpoints.php b/core/classes/Endpoints/Endpoints.php index f61c2e13dc..5caa43d41d 100644 --- a/core/classes/Endpoints/Endpoints.php +++ b/core/classes/Endpoints/Endpoints.php @@ -63,15 +63,15 @@ public function handle(string $route, string $method, Nameless2API $api): void } $reflection = new ReflectionMethod($endpoint, 'execute'); - if ($reflection->getNumberOfParameters() !== (count($vars) + 1)) { - throw new InvalidArgumentException("Endpoint's 'execute()' method must take " . (count($vars) + 1) . ' arguments. Endpoint: ' . $endpoint->getRoute()); + if ($reflection->getNumberOfParameters() !== (count($endpoint->customParams()) + count($vars) + 1)) { + throw new InvalidArgumentException("Endpoint's 'execute()' method must take " . (count($endpoint->customParams()) + count($vars) + 1) . ' arguments. Endpoint: ' . $endpoint->getRoute()); } $endpoint->execute( $api, - ...array_map(function ($type, $value) use ($api) { + ...array_merge($endpoint->customParams(), array_map(function ($type, $value) use ($api) { return $this::transform($api, $type, $value); - }, array_keys($vars), $vars) + }, array_keys($vars), $vars)) ); return;