diff --git a/module/Rest/config/routes.config.php b/module/Rest/config/routes.config.php index 28b7cf5f..e2ee8f75 100644 --- a/module/Rest/config/routes.config.php +++ b/module/Rest/config/routes.config.php @@ -7,12 +7,7 @@ use Shlinkio\Shlink\Rest\Action; return [ 'routes' => [ - [ - 'name' => Action\AuthenticateAction::class, - 'path' => '/authenticate', - 'middleware' => Action\AuthenticateAction::class, - 'allowed_methods' => [RequestMethod::METHOD_POST], - ], + Action\AuthenticateAction::getRouteDef(), // Short codes [ @@ -27,64 +22,19 @@ return [ // 'middleware' => Action\CreateShortcodeAction::class, // 'allowed_methods' => [RequestMethod::METHOD_GET], // ], - [ - 'name' => Action\EditShortCodeAction::class, - 'path' => '/short-codes/{shortCode}', - 'middleware' => Action\EditShortCodeAction::class, - 'allowed_methods' => [RequestMethod::METHOD_PUT], - ], - [ - 'name' => Action\ResolveUrlAction::class, - 'path' => '/short-codes/{shortCode}', - 'middleware' => Action\ResolveUrlAction::class, - 'allowed_methods' => [RequestMethod::METHOD_GET], - ], - [ - 'name' => Action\ListShortcodesAction::class, - 'path' => '/short-codes', - 'middleware' => Action\ListShortcodesAction::class, - 'allowed_methods' => [RequestMethod::METHOD_GET], - ], - [ - 'name' => Action\EditShortcodeTagsAction::class, - 'path' => '/short-codes/{shortCode}/tags', - 'middleware' => Action\EditShortcodeTagsAction::class, - 'allowed_methods' => [RequestMethod::METHOD_PUT], - ], + Action\EditShortCodeAction::getRouteDef(), + Action\ResolveUrlAction::getRouteDef(), + Action\ListShortcodesAction::getRouteDef(), + Action\EditShortcodeTagsAction::getRouteDef(), // Visits - [ - 'name' => Action\GetVisitsAction::class, - 'path' => '/short-codes/{shortCode}/visits', - 'middleware' => Action\GetVisitsAction::class, - 'allowed_methods' => [RequestMethod::METHOD_GET], - ], + Action\GetVisitsAction::getRouteDef(), // Tags - [ - 'name' => Action\Tag\ListTagsAction::class, - 'path' => '/tags', - 'middleware' => Action\Tag\ListTagsAction::class, - 'allowed_methods' => [RequestMethod::METHOD_GET], - ], - [ - 'name' => Action\Tag\DeleteTagsAction::class, - 'path' => '/tags', - 'middleware' => Action\Tag\DeleteTagsAction::class, - 'allowed_methods' => [RequestMethod::METHOD_DELETE], - ], - [ - 'name' => Action\Tag\CreateTagsAction::class, - 'path' => '/tags', - 'middleware' => Action\Tag\CreateTagsAction::class, - 'allowed_methods' => [RequestMethod::METHOD_POST], - ], - [ - 'name' => Action\Tag\UpdateTagAction::class, - 'path' => '/tags', - 'middleware' => Action\Tag\UpdateTagAction::class, - 'allowed_methods' => [RequestMethod::METHOD_PUT], - ], + Action\Tag\ListTagsAction::getRouteDef(), + Action\Tag\DeleteTagsAction::getRouteDef(), + Action\Tag\CreateTagsAction::getRouteDef(), + Action\Tag\UpdateTagAction::getRouteDef(), ], ]; diff --git a/module/Rest/src/Action/AbstractRestAction.php b/module/Rest/src/Action/AbstractRestAction.php index 1879ef12..caf4f459 100644 --- a/module/Rest/src/Action/AbstractRestAction.php +++ b/module/Rest/src/Action/AbstractRestAction.php @@ -12,7 +12,7 @@ use Psr\Log\NullLogger; abstract class AbstractRestAction implements RequestHandlerInterface, RequestMethodInterface, StatusCodeInterface { protected const ROUTE_PATH = ''; - protected const ALLOWED_METHODS = []; + protected const ROUTE_ALLOWED_METHODS = []; /** * @var LoggerInterface @@ -30,7 +30,7 @@ abstract class AbstractRestAction implements RequestHandlerInterface, RequestMet 'name' => static::class, 'middleware' => \array_merge($prevMiddleware, [static::class], $postMiddleware), 'path' => static::ROUTE_PATH, - 'allowed_methods' => static::ALLOWED_METHODS, + 'allowed_methods' => static::ROUTE_ALLOWED_METHODS, ]; } } diff --git a/module/Rest/src/Action/AuthenticateAction.php b/module/Rest/src/Action/AuthenticateAction.php index 22dcee43..3a4d2fba 100644 --- a/module/Rest/src/Action/AuthenticateAction.php +++ b/module/Rest/src/Action/AuthenticateAction.php @@ -15,6 +15,9 @@ use Zend\I18n\Translator\TranslatorInterface; class AuthenticateAction extends AbstractRestAction { + protected const ROUTE_PATH = '/authenticate'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST]; + /** * @var TranslatorInterface */ diff --git a/module/Rest/src/Action/EditShortCodeAction.php b/module/Rest/src/Action/EditShortCodeAction.php index 3e9be062..a3a2357f 100644 --- a/module/Rest/src/Action/EditShortCodeAction.php +++ b/module/Rest/src/Action/EditShortCodeAction.php @@ -16,6 +16,9 @@ use Zend\I18n\Translator\TranslatorInterface; class EditShortCodeAction extends AbstractRestAction { + protected const ROUTE_PATH = '/short-codes/{shortCode}'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; + /** * @var ShortUrlServiceInterface */ diff --git a/module/Rest/src/Action/EditShortcodeTagsAction.php b/module/Rest/src/Action/EditShortcodeTagsAction.php index c226605a..0e677032 100644 --- a/module/Rest/src/Action/EditShortcodeTagsAction.php +++ b/module/Rest/src/Action/EditShortcodeTagsAction.php @@ -14,6 +14,9 @@ use Zend\I18n\Translator\TranslatorInterface; class EditShortcodeTagsAction extends AbstractRestAction { + protected const ROUTE_PATH = '/short-codes/{shortCode}/tags'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; + /** * @var ShortUrlServiceInterface */ diff --git a/module/Rest/src/Action/GetVisitsAction.php b/module/Rest/src/Action/GetVisitsAction.php index 0892da85..062e1d7e 100644 --- a/module/Rest/src/Action/GetVisitsAction.php +++ b/module/Rest/src/Action/GetVisitsAction.php @@ -15,6 +15,9 @@ use Zend\I18n\Translator\TranslatorInterface; class GetVisitsAction extends AbstractRestAction { + protected const ROUTE_PATH = '/short-codes/{shortCode}/visits'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; + /** * @var VisitsTrackerInterface */ diff --git a/module/Rest/src/Action/ListShortcodesAction.php b/module/Rest/src/Action/ListShortcodesAction.php index fe071a28..a725c5f5 100644 --- a/module/Rest/src/Action/ListShortcodesAction.php +++ b/module/Rest/src/Action/ListShortcodesAction.php @@ -16,6 +16,9 @@ class ListShortcodesAction extends AbstractRestAction { use PaginatorUtilsTrait; + protected const ROUTE_PATH = '/short-codes'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; + /** * @var ShortUrlServiceInterface */ diff --git a/module/Rest/src/Action/ResolveUrlAction.php b/module/Rest/src/Action/ResolveUrlAction.php index 54109049..34bcd651 100644 --- a/module/Rest/src/Action/ResolveUrlAction.php +++ b/module/Rest/src/Action/ResolveUrlAction.php @@ -15,6 +15,9 @@ use Zend\I18n\Translator\TranslatorInterface; class ResolveUrlAction extends AbstractRestAction { + protected const ROUTE_PATH = '/short-codes/{shortCode}'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; + /** * @var UrlShortenerInterface */ diff --git a/module/Rest/src/Action/Tag/CreateTagsAction.php b/module/Rest/src/Action/Tag/CreateTagsAction.php index 6f93b46f..9e963467 100644 --- a/module/Rest/src/Action/Tag/CreateTagsAction.php +++ b/module/Rest/src/Action/Tag/CreateTagsAction.php @@ -12,6 +12,9 @@ use Zend\Diactoros\Response\JsonResponse; class CreateTagsAction extends AbstractRestAction { + protected const ROUTE_PATH = '/tags'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_POST]; + /** * @var TagServiceInterface */ diff --git a/module/Rest/src/Action/Tag/DeleteTagsAction.php b/module/Rest/src/Action/Tag/DeleteTagsAction.php index e7ae7b48..4c1f4371 100644 --- a/module/Rest/src/Action/Tag/DeleteTagsAction.php +++ b/module/Rest/src/Action/Tag/DeleteTagsAction.php @@ -12,6 +12,9 @@ use Zend\Diactoros\Response\EmptyResponse; class DeleteTagsAction extends AbstractRestAction { + protected const ROUTE_PATH = '/tags'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_DELETE]; + /** * @var TagServiceInterface */ diff --git a/module/Rest/src/Action/Tag/ListTagsAction.php b/module/Rest/src/Action/Tag/ListTagsAction.php index 79c6a79e..02fb968c 100644 --- a/module/Rest/src/Action/Tag/ListTagsAction.php +++ b/module/Rest/src/Action/Tag/ListTagsAction.php @@ -12,6 +12,9 @@ use Zend\Diactoros\Response\JsonResponse; class ListTagsAction extends AbstractRestAction { + protected const ROUTE_PATH = '/tags'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_GET]; + /** * @var TagServiceInterface */ diff --git a/module/Rest/src/Action/Tag/UpdateTagAction.php b/module/Rest/src/Action/Tag/UpdateTagAction.php index d2e9b871..02f32abb 100644 --- a/module/Rest/src/Action/Tag/UpdateTagAction.php +++ b/module/Rest/src/Action/Tag/UpdateTagAction.php @@ -16,6 +16,9 @@ use Zend\I18n\Translator\TranslatorInterface; class UpdateTagAction extends AbstractRestAction { + protected const ROUTE_PATH = '/tags'; + protected const ROUTE_ALLOWED_METHODS = [self::METHOD_PUT]; + /** * @var TagServiceInterface */