Skip to content

Commit 933a2ad

Browse files
committed
feat(routing): added missing route attributes (#3877)
1 parent e8e3f5f commit 933a2ad

37 files changed

+91
-37
lines changed

phpmyfaq/api/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@
6161
echo $e->getMessage();
6262
}
6363

64-
$routes = include PMF_SRC_DIR . '/api-routes.php';
65-
6664
$app = new Application($container);
6765
$app->setApiContext(true);
66+
$app->setRoutingContext('api');
6867
try {
69-
$app->run($routes);
68+
// Autoload routes from attributes (falls back to api-routes.php during migration)
69+
$app->run();
7070
} catch (Exception $exception) {
7171
echo $exception->getMessage();
7272
}

phpmyfaq/setup/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use Composer\Autoload\ClassLoader;
2727
use phpMyFAQ\Application;
28-
use phpMyFAQ\Controller\Frontend\Api\SetupController;
28+
use phpMyFAQ\Controller\Frontend\SetupController;
2929
use phpMyFAQ\Environment;
3030
use phpMyFAQ\Strings;
3131
use phpMyFAQ\Translation;

phpmyfaq/src/admin-routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
use phpMyFAQ\Controller\Administration\InstanceController;
3636
use phpMyFAQ\Controller\Administration\NewsController;
3737
use phpMyFAQ\Controller\Administration\OpenQuestionsController;
38-
use phpMyFAQ\Controller\Administration\PageController;
3938
use phpMyFAQ\Controller\Administration\OpenSearchController;
4039
use phpMyFAQ\Controller\Administration\OrphanedFaqsController;
40+
use phpMyFAQ\Controller\Administration\PageController;
4141
use phpMyFAQ\Controller\Administration\PasswordChangeController;
4242
use phpMyFAQ\Controller\Administration\PluginController;
4343
use phpMyFAQ\Controller\Administration\RatingController;

phpmyfaq/src/api-routes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
'controller' => [FaqController::class, 'update'],
9090
'methods' => 'PUT',
9191
],
92-
'api.faq-by-id' => [
92+
'api.faq.by-id' => [
9393
'path' => "v{$apiVersion}/faq/{categoryId}/{faqId}",
9494
'controller' => [FaqController::class, 'getById'],
9595
'methods' => 'GET',

phpmyfaq/src/phpMyFAQ/Controller/Api/BackupController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Symfony\Component\HttpFoundation\Request;
3333
use Symfony\Component\HttpFoundation\Response;
3434
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
35+
use Symfony\Component\Routing\Attribute\Route;
3536

3637
final class BackupController extends AbstractController
3738
{
@@ -82,6 +83,7 @@ public function __construct()
8283
response: 401,
8384
description: 'If the user is not authenticated and/or does not have sufficient permissions.',
8485
)]
86+
#[Route(path: 'v3.2/backup/{type}', name: 'api.backup', methods: ['GET'])]
8587
public function download(Request $request): Response
8688
{
8789
$this->userHasPermission(PermissionType::BACKUP);

phpmyfaq/src/phpMyFAQ/Controller/Api/CategoryController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@
1919

2020
namespace phpMyFAQ\Controller\Api;
2121

22+
use JsonException;
2223
use OpenApi\Attributes as OA;
2324
use phpMyFAQ\Category;
2425
use phpMyFAQ\Category\Order;
2526
use phpMyFAQ\Category\Permission as CategoryPermission;
26-
use phpMyFAQ\Core\Exception;
2727
use phpMyFAQ\Entity\CategoryEntity;
2828
use phpMyFAQ\Filter;
2929
use phpMyFAQ\Language;
3030
use phpMyFAQ\User\CurrentUser;
3131
use Symfony\Component\HttpFoundation\JsonResponse;
3232
use Symfony\Component\HttpFoundation\Request;
3333
use Symfony\Component\HttpFoundation\Response;
34+
use Symfony\Component\Routing\Attribute\Route;
3435

3536
final class CategoryController extends AbstractApiController
3637
{
@@ -124,6 +125,7 @@ enum: ['id', 'name', 'parent_id', 'active'],
124125
}
125126
}'),
126127
)]
128+
#[Route(path: 'v3.2/categories', name: 'api.categories.list', methods: ['GET'])]
127129
public function list(): JsonResponse
128130
{
129131
/** @var Language $language */
@@ -168,7 +170,8 @@ public function list(): JsonResponse
168170
}
169171

170172
/**
171-
* @throws Exception|\JsonException
173+
* @throws JsonException
174+
* @throws \Exception
172175
*/
173176
#[OA\Post(path: '/api/v3.2/category', operationId: 'createCategory', tags: ['Endpoints with Authentication'])]
174177
#[OA\Header(
@@ -244,6 +247,7 @@ public function list(): JsonResponse
244247
),
245248
)]
246249
#[OA\Response(response: 401, description: 'If the user is not authenticated.')]
250+
#[Route(path: 'v3.2/category', name: 'api.category.create', methods: ['POST'])]
247251
public function create(Request $request): JsonResponse
248252
{
249253
$this->hasValidToken();

phpmyfaq/src/phpMyFAQ/Controller/Api/CommentController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use phpMyFAQ\Filter;
2727
use Symfony\Component\HttpFoundation\JsonResponse;
2828
use Symfony\Component\HttpFoundation\Request;
29-
use Symfony\Component\HttpFoundation\Response;
29+
use Symfony\Component\Routing\Attribute\Route;
3030

3131
final class CommentController extends AbstractApiController
3232
{
@@ -128,6 +128,7 @@ enum: ['id_comment', 'id', 'usr', 'email', 'datum'],
128128
}
129129
}',
130130
))]
131+
#[Route(path: 'v3.2/comments/{recordId}', name: 'api.comments', methods: ['GET'])]
131132
public function list(Request $request): JsonResponse
132133
{
133134
$recordId = (int) Filter::filterVar($request->attributes->get(key: 'recordId'), FILTER_VALIDATE_INT);

phpmyfaq/src/phpMyFAQ/Controller/Api/FaqController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Component\HttpFoundation\JsonResponse;
3131
use Symfony\Component\HttpFoundation\Request;
3232
use Symfony\Component\HttpFoundation\Response;
33+
use Symfony\Component\Routing\Attribute\Route;
3334

3435
final class FaqController extends AbstractApiController
3536
{
@@ -71,6 +72,7 @@ final class FaqController extends AbstractApiController
7172
]',
7273
))]
7374
#[OA\Response(response: 404, description: 'If the category has no FAQs.', content: new OA\JsonContent(example: []))]
75+
#[Route(path: 'v3.2/faqs/{categoryId}', name: 'api.faqs.by-category-id', methods: ['GET'])]
7476
public function getByCategoryId(Request $request): JsonResponse
7577
{
7678
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -143,6 +145,7 @@ public function getByCategoryId(Request $request): JsonResponse
143145
description: 'If there are no FAQs for the given FAQ ID.',
144146
content: new OA\JsonContent(example: []),
145147
)]
148+
#[Route(path: 'v3.2/faq/{categoryId}/{faqId}', name: 'api.faq.by-id', methods: ['GET'])]
146149
public function getById(Request $request): JsonResponse
147150
{
148151
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -208,6 +211,7 @@ public function getById(Request $request): JsonResponse
208211
]',
209212
))]
210213
#[OA\Response(response: 404, description: 'If the tag ID has no FAQs.', content: new OA\JsonContent(example: []))]
214+
#[Route(path: 'v3.2/faqs/tags/{tagId}', name: 'api.faqs.by-tag-id', methods: ['GET'])]
211215
public function getByTagId(Request $request): JsonResponse
212216
{
213217
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -259,6 +263,7 @@ public function getByTagId(Request $request): JsonResponse
259263
description: "If there's not a single popular FAQ.",
260264
content: new OA\JsonContent(example: []),
261265
)]
266+
#[Route(path: 'v3.2/faqs/popular', name: 'api.faqs.popular', methods: ['GET'])]
262267
public function getPopular(): JsonResponse
263268
{
264269
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -307,6 +312,7 @@ public function getPopular(): JsonResponse
307312
description: "If there's not one latest FAQ.",
308313
content: new OA\JsonContent(example: []),
309314
)]
315+
#[Route(path: 'v3.2/faqs/latest', name: 'api.faqs.latest', methods: ['GET'])]
310316
public function getLatest(): JsonResponse
311317
{
312318
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -354,6 +360,7 @@ public function getLatest(): JsonResponse
354360
description: "If there's not a single trending FAQ.",
355361
content: new OA\JsonContent(example: []),
356362
)]
363+
#[Route(path: 'v3.2/faqs/trending', name: 'api.faqs.trending', methods: ['GET'])]
357364
public function getTrending(): JsonResponse
358365
{
359366
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -406,6 +413,7 @@ public function getTrending(): JsonResponse
406413
description: "If there's not one sticky FAQ.",
407414
content: new OA\JsonContent(example: []),
408415
)]
416+
#[Route(path: 'v3.2/faqs/sticky', name: 'api.faqs.sticky', methods: ['GET'])]
409417
public function getSticky(): JsonResponse
410418
{
411419
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -522,6 +530,7 @@ enum: ['id', 'title', 'author', 'updated', 'created'],
522530
}
523531
}',
524532
))]
533+
#[Route(path: 'v3.2/faqs', name: 'api.faqs.list', methods: ['GET'])]
525534
public function list(): JsonResponse
526535
{
527536
[$currentUser, $currentGroups] = CurrentUser::getCurrentUserGroupId($this->currentUser);
@@ -658,6 +667,7 @@ public function list(): JsonResponse
658667
content: new OA\JsonContent(example: '{ "stored": false, "error": "The given category name was not found" }'),
659668
)]
660669
#[OA\Response(response: 401, description: 'If the user is not authenticated.')]
670+
#[Route(path: 'v3.2/faq/create', name: 'api.faq.create', methods: ['POST'])]
661671
public function create(Request $request): JsonResponse
662672
{
663673
$this->hasValidToken();
@@ -693,7 +703,7 @@ public function create(Request $request): JsonResponse
693703
$isActive = Filter::filterVar($data->{'is-active'}, FILTER_VALIDATE_BOOLEAN);
694704
$isSticky = Filter::filterVar($data->{'is-sticky'}, FILTER_VALIDATE_BOOLEAN);
695705

696-
// Check if category name can be mapped
706+
// Check if the category name can be mapped
697707
if (!is_null($categoryName)) {
698708
$categoryIdFound = $category->getCategoryIdFromName($categoryName);
699709
if ($categoryIdFound === false) {
@@ -816,6 +826,7 @@ public function create(Request $request): JsonResponse
816826
),
817827
)]
818828
#[OA\Response(response: 401, description: 'If the user is not authenticated.')]
829+
#[Route(path: 'v3.2/faq/update', name: 'api.faq.update', methods: ['PUT'])]
819830
public function update(Request $request): JsonResponse
820831
{
821832
$this->hasValidToken();

phpmyfaq/src/phpMyFAQ/Controller/Api/GlossaryController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\HttpFoundation\JsonResponse;
2525
use Symfony\Component\HttpFoundation\Request;
2626
use Symfony\Component\HttpFoundation\Response;
27+
use Symfony\Component\Routing\Attribute\Route;
2728

2829
final class GlossaryController extends AbstractApiController
2930
{
@@ -111,6 +112,7 @@ final class GlossaryController extends AbstractApiController
111112
}
112113
}',
113114
))]
115+
#[Route(path: 'v3.2/glossary', name: 'api.glossary.list', methods: ['GET'])]
114116
public function list(Request $request): JsonResponse
115117
{
116118
$glossary = $this->container->get(id: 'phpmyfaq.glossary');

phpmyfaq/src/phpMyFAQ/Controller/Api/GroupController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ final class GroupController extends AbstractApiController
108108
}',
109109
))]
110110
#[OA\Response(response: 401, description: 'If the user is not authenticated.')]
111+
#[Route(path: 'v3.2/groups', name: 'api.groups', methods: ['GET'])]
111112
public function list(): JsonResponse
112113
{
113114
$this->userIsAuthenticated();

0 commit comments

Comments
 (0)