-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathLanguageListController.php
More file actions
70 lines (62 loc) · 2.36 KB
/
Copy pathLanguageListController.php
File metadata and controls
70 lines (62 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Rest\Server\Controller\Language;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
use ApiPlatform\OpenApi\Model;
use Ibexa\Contracts\Core\Repository\LanguageService;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values\LanguageList;
use Symfony\Component\HttpFoundation\Response;
use Traversable;
#[Get(
uriTemplate: '/languages',
extraProperties: [OpenApiFactory::OVERRIDE_OPENAPI_RESPONSES => false],
openapi: new Model\Operation(
operationId: 'ibexa.rest.languages.list',
summary: 'Language list',
description: 'Lists languages',
tags: [
'Language',
],
responses: [
Response::HTTP_OK => [
'description' => 'If set, the list is returned in XML or JSON format.',
'content' => [
'application/vnd.ibexa.api.LanguageList+json' => [
'schema' => [
'$ref' => '#/components/schemas/LanguageListWrapper',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/languages/GET/LanguageList.json.example',
],
'application/vnd.ibexa.api.LanguageList+xml' => [
'schema' => [
'$ref' => '#/components/schemas/LanguageList',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/languages/GET/LanguageList.xml.example',
],
],
],
],
),
)]
final class LanguageListController extends RestController
{
private LanguageService $languageService;
public function __construct(LanguageService $languageService)
{
$this->languageService = $languageService;
}
public function listLanguages(): LanguageList
{
$languages = $this->languageService->loadLanguages();
if ($languages instanceof Traversable) {
$languages = iterator_to_array($languages);
}
return new LanguageList($languages);
}
}