Skip to content

Commit 12fedc7

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

23 files changed

+61
-44
lines changed

phpmyfaq/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
echo sprintf('Error: %s at line %d at %s', $exception->getMessage(), $exception->getLine(), $exception->getFile());
5656
}
5757

58-
$routes = include PMF_SRC_DIR . '/public-routes.php';
59-
6058
$app = new Application($container);
59+
$app->setRoutingContext('public');
6160
try {
62-
$app->run($routes);
61+
// Auto-loads routes from attributes (falls back to public-routes.php during migration)
62+
$app->run();
6363
} catch (Exception $exception) {
6464
echo sprintf('Error: %s at line %d at %s', $exception->getMessage(), $exception->getLine(), $exception->getFile());
6565
}

phpmyfaq/src/phpMyFAQ/Controller/Frontend/AttachmentController.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace phpMyFAQ\Controller\Frontend;
2222

23+
use phpMyFAQ\Attachment\AbstractAttachment;
2324
use phpMyFAQ\Attachment\AttachmentException;
2425
use phpMyFAQ\Attachment\AttachmentService;
2526
use phpMyFAQ\Core\Exception;
@@ -35,7 +36,12 @@ final class AttachmentController extends AbstractFrontController
3536
* @throws Exception
3637
* @throws \Exception
3738
*/
38-
#[Route(path: '/attachment/{attachmentId}', name: 'public.attachment')]
39+
#[Route(
40+
path: '/attachment/{attachmentId}',
41+
name: 'public.attachment',
42+
requirements: ['attachmentId' => '\d+'],
43+
methods: ['GET'],
44+
)]
3945
public function index(Request $request): Response
4046
{
4147
$id = Filter::filterVar($request->attributes->get('attachmentId'), FILTER_VALIDATE_INT);
@@ -59,7 +65,7 @@ public function index(Request $request): Response
5965
}
6066

6167
if (
62-
$attachment instanceof \phpMyFAQ\Attachment\AbstractAttachment
68+
$attachment instanceof AbstractAttachment
6369
&& $attachment->getRecordId() > 0
6470
&& $attachmentService->canDownloadAttachment($attachment)
6571
) {

phpmyfaq/src/phpMyFAQ/Controller/Frontend/AuthenticationController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class AuthenticationController extends AbstractFrontController
3535
* @throws Exception
3636
* @throws LoaderError
3737
* @throws \Exception
38-
*/ #[Route(path: '/login', name: 'public.auth.login')]
38+
*/ #[Route(path: '/login', name: 'public.auth.login', methods: ['GET'])]
3939
public function login(Request $request): Response
4040
{
4141
$faqSession = $this->container->get('phpmyfaq.user.session');
@@ -81,7 +81,7 @@ public function login(Request $request): Response
8181
* @throws LoaderError
8282
* @throws \Exception
8383
*/
84-
#[Route(path: '/forgot-password', name: 'public.auth.forgot-password')]
84+
#[Route(path: '/forgot-password', name: 'public.forgot-password', methods: ['GET', 'POST'])]
8585
public function forgotPassword(Request $request): Response
8686
{
8787
$faqSession = $this->container->get('phpmyfaq.user.session');
@@ -99,7 +99,7 @@ public function forgotPassword(Request $request): Response
9999
/**
100100
* @throws \Exception
101101
*/
102-
#[Route(path: '/logout', name: 'public.auth.logout')]
102+
#[Route(path: '/logout', name: 'public.auth.logout', methods: ['GET'])]
103103
public function logout(Request $request): RedirectResponse
104104
{
105105
$session = $this->container->get('session');
@@ -199,7 +199,7 @@ public function authenticate(Request $request): RedirectResponse
199199
* @throws LoaderError
200200
* @throws \Exception
201201
*/
202-
#[Route(path: '/token', name: 'public.auth.token')]
202+
#[Route(path: '/token', name: 'public.auth.token', methods: ['GET'])]
203203
public function token(Request $request): Response
204204
{
205205
if ($this->currentUser->isLoggedIn()) {
@@ -231,7 +231,7 @@ public function token(Request $request): Response
231231
*
232232
* @throws \Exception
233233
*/
234-
#[Route(path: '/check', name: 'public.twofactor.check', methods: ['POST'])]
234+
#[Route(path: '/check', name: 'public.auth.check', methods: ['POST'])]
235235
public function check(Request $request): RedirectResponse
236236
{
237237
if ($this->currentUser->isLoggedIn()) {

phpmyfaq/src/phpMyFAQ/Controller/Frontend/ContactController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class ContactController extends AbstractFrontController
3131
* Handles both GET and POST requests for the contact form
3232
* @throws Exception
3333
*/
34-
#[Route(path: '/contact.html', name: 'public.contact')]
34+
#[Route(path: '/contact.html', name: 'public.contact', methods: ['GET'])]
3535
public function index(Request $request): Response
3636
{
3737
$faqSession = $this->container->get('phpmyfaq.user.session');

phpmyfaq/src/phpMyFAQ/Controller/Frontend/CookiePolicyController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class CookiePolicyController extends AbstractFrontController
3030
* Displays the cookie policy page - either a custom page or redirects to configured URL.
3131
* @throws Exception
3232
*/
33-
#[Route(path: '/cookies.html', name: 'public.cookies')]
33+
#[Route(path: '/cookies.html', name: 'public.cookies', methods: ['GET'])]
3434
public function index(Request $request): Response
3535
{
3636
return $this->handleStaticPageRedirect('main.cookiePolicyURL');

phpmyfaq/src/phpMyFAQ/Controller/Frontend/CustomPageController.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020
namespace phpMyFAQ\Controller\Frontend;
2121

2222
use phpMyFAQ\Core\Exception;
23-
use phpMyFAQ\CustomPage;
2423
use phpMyFAQ\Entity\SeoEntity;
2524
use phpMyFAQ\Enums\SeoType;
2625
use phpMyFAQ\Seo;
2726
use phpMyFAQ\Strings;
2827
use Symfony\Component\HttpFoundation\Request;
2928
use Symfony\Component\HttpFoundation\Response;
3029
use Symfony\Component\Routing\Attribute\Route;
30+
use Twig\Error\LoaderError;
3131

3232
final class CustomPageController extends AbstractFrontController
3333
{
3434
/**
3535
* Displays a custom page by its slug
3636
*
37-
* @throws Exception
37+
* @throws Exception|LoaderError*@throws \Exception
38+
*
3839
*/
39-
#[Route(path: '/page/{slug}.html', name: 'public.page', requirements: ['slug' => '[a-z0-9\-_]+'])]
40+
#[Route(path: '/page/{slug}.html', name: 'public.page', requirements: ['slug' => '[a-z0-9\-_]+'], methods: ['GET'])]
4041
public function show(Request $request): Response
4142
{
4243
$slug = $request->attributes->get('slug');
@@ -73,7 +74,7 @@ public function show(Request $request): Response
7374
$metaTitle = $seoEntity->getTitle() ?: $pageEntity->getPageTitle();
7475
$metaDescription = $seoEntity->getDescription() ?: '';
7576
} catch (Exception $e) {
76-
// SEO data not found, use page defaults
77+
// SEO data aren't found, use page defaults
7778
$metaTitle = $pageEntity->getPageTitle();
7879
$metaDescription = '';
7980
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class GlossaryController extends AbstractFrontController
3333
* @throws Exception
3434
* @throws LoaderError
3535
* @throws \Exception
36-
*/ #[Route(path: '/glossary.html', name: 'public.glossary')]
36+
*/ #[Route(path: '/glossary.html', name: 'public.glossary', methods: ['GET'])]
3737
public function index(Request $request): Response
3838
{
3939
$faqSession = $this->container->get('phpmyfaq.user.session');

phpmyfaq/src/phpMyFAQ/Controller/Frontend/ImprintController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class ImprintController extends AbstractFrontController
3030
* Displays the imprint page - either a custom page or redirects to configured URL.
3131
* @throws Exception
3232
*/
33-
#[Route(path: '/imprint.html', name: 'public.imprint')]
33+
#[Route(path: '/imprint.html', name: 'public.imprint', methods: ['GET'])]
3434
public function index(Request $request): Response
3535
{
3636
return $this->handleStaticPageRedirect('main.imprintURL');

phpmyfaq/src/phpMyFAQ/Controller/Frontend/NewsController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,15 @@ final class NewsController extends AbstractFrontController
4242
* @throws Exception
4343
* @throws \Exception
4444
*/
45-
#[Route(path: '/news/{newsId}/{newsLang}/{slug}.html', name: 'public.news', requirements: [
46-
'newsId' => '\d+',
47-
'newsLang' => '[a-z\-_]+',
48-
])]
45+
#[Route(
46+
path: '/news/{newsId}/{newsLang}/{slug}.html',
47+
name: 'public.news',
48+
requirements: [
49+
'newsId' => '\d+',
50+
'newsLang' => '[a-z\-_]+',
51+
],
52+
methods: ['GET'],
53+
)]
4954
public function index(Request $request): Response
5055
{
5156
$newsId = Filter::filterVar($request->attributes->get('newsId'), FILTER_VALIDATE_INT);

phpmyfaq/src/phpMyFAQ/Controller/Frontend/OverviewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class OverviewController extends AbstractFrontController
3636
* @throws Exception
3737
* @throws LoaderError
3838
* @throws \Exception
39-
*/ #[Route(path: '/overview.html', name: 'public.overview')]
39+
*/ #[Route(path: '/overview.html', name: 'public.overview', methods: ['GET'])]
4040
public function index(Request $request): Response
4141
{
4242
$faqSession = $this->container->get('phpmyfaq.user.session');

0 commit comments

Comments
 (0)