Added pattern matcher for backend name.

This commit is contained in:
abdulmohsen
2024-04-19 22:54:32 +03:00
parent aee685e88d
commit fe967a64b5
4 changed files with 9 additions and 3 deletions

View File

@@ -32,6 +32,9 @@ return (function () {
'api' => [
'prefix' => '/v1/api',
'key' => env('WS_API_KEY', null),
'pattern_match' => [
'backend' => '[a-zA-Z0-9_-]+',
],
],
'database' => [
'version' => 'v01',

View File

@@ -52,7 +52,7 @@ final class Index
return api_response(HTTP_STATUS::HTTP_OK, $response);
}
#[Get(self::URL . '/{id:[a-zA-Z0-9_-]+}[/]', name: 'backends.view')]
#[Get(self::URL . '/{id:backend}[/]', name: 'backends.view')]
public function backendsView(iRequest $request, array $args = []): iResponse
{
if (null === ($id = ag($args, 'id'))) {

View File

@@ -23,10 +23,10 @@ final class GenerateAccessToken
{
}
#[Post(self::URL . '/{backend:\w+}[/]', name: 'backends.plex.accesstoken')]
#[Post(self::URL . '/{id:backend}[/]', name: 'backends.plex.accesstoken')]
public function gAccesstoken(iRequest $request, array $args = []): iResponse
{
$backend = ag($args, 'backend');
$backend = ag($args, 'id');
$data = DataUtil::fromArray($request->getParsedBody());

View File

@@ -510,6 +510,9 @@ final class Initializer
private function defaultAPIServer(iRequest $realRequest): ResponseInterface
{
$router = new APIRouter();
foreach (Config::get('api.pattern_match', []) as $_key => $_value) {
$router->addPatternMatcher($_key, $_value);
}
$strategy = new RouterStrategy();
$strategy->setContainer(Container::getContainer());
$router->setStrategy($strategy);