Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace core\router\parameters;
18
 
19
use core\param;
20
use core\router\schema\example;
21
use core\router\schema\referenced_object;
22
 
23
/**
24
 * A header to accept an optional language for the requested content.
25
 *
26
 * @package    core
27
 * @copyright  2024 Andrew Lyons <andrew@nicols.co.uk>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class header_language extends \core\router\schema\parameters\header_object implements referenced_object {
31
    /**
32
     * Create a new path_component parameter.
33
     *
34
     * @param string $name The name of the parameter to use for the component name
35
     * @param mixed ...$extra Additional arguments
36
     */
37
    public function __construct(
38
        string $name = 'language',
39
        ...$extra,
40
    ) {
41
        global $CFG;
42
 
43
        $extra['name'] = $name;
44
        $extra['type'] = param::LANG;
45
        $extra['description'] = 'The language of the requested response.';
46
 
47
        // Generally speaking, the default language should be the site default.
48
        // This is a value which is usually stored in DB, so we have a fallback for when the full
49
        // Moodle configuration has not been loaded.
50
        $extra['default'] = $CFG->lang ?? 'en';
51
 
52
        $extra['examples'] = [
53
            new example(
54
                name: 'Site default',
55
                value: null,
56
            ),
57
            new example(
58
                name: 'English',
59
                value: 'en',
60
            ),
61
            new example(
62
                name: 'Deutsch (kids)',
63
                value: 'de_kids',
64
            ),
65
        ];
66
 
67
        parent::__construct(...$extra);
68
    }
69
}