Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| LanguageController | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| index | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * The Language Controller for the REST API |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2023-2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2023-07-29 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Controller\Api; |
| 21 | |
| 22 | use OpenApi\Attributes as OA; |
| 23 | use phpMyFAQ\Controller\AbstractController; |
| 24 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 25 | use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; |
| 26 | use Symfony\Component\Routing\Attribute\Route; |
| 27 | |
| 28 | final class LanguageController extends AbstractController |
| 29 | { |
| 30 | public function __construct() |
| 31 | { |
| 32 | parent::__construct(); |
| 33 | |
| 34 | if (!$this->isApiEnabled()) { |
| 35 | throw new UnauthorizedHttpException(challenge: 'API is not enabled'); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | #[OA\Get(path: '/api/v4.0/language', operationId: 'getLanguage', tags: ['Public Endpoints'])] |
| 40 | #[OA\Response( |
| 41 | response: 200, |
| 42 | description: 'Returns the default language as language code.', |
| 43 | content: new OA\JsonContent(example: 'en'), |
| 44 | )] |
| 45 | #[Route(path: 'v4.0/language', name: 'api.language', methods: ['GET'])] |
| 46 | public function index(): JsonResponse |
| 47 | { |
| 48 | return new JsonResponse($this->configuration->getLanguage()->getLanguage()); |
| 49 | } |
| 50 | } |