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\output;
18
 
19
use moodle_page;
20
 
21
/**
22
 * Class renderer helper.
23
 *
24
 * This class is created to access output renderers from a
25
 * dependency injection container. $PAGE and $OUTPUT globals
26
 * haven't got a constant value, so we can't use them in
27
 * services or factories.
28
 *
29
 * this class wraps all the globals logic and provides a
30
 * way to access the renderers.
31
 *
32
 * @package    core
33
 * @copyright  2025 Ferran Recio <ferran@moodle.com>
34
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class renderer_helper {
37
    /**
38
     * Get the renderer for a particular part of Moodle.
39
     *
40
     * @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
41
     * @param string|null $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
42
     * @return renderer_base
43
     */
44
    public function get_renderer(string $component, ?string $subtype = null): renderer_base {
45
        global $PAGE;
46
        return $PAGE->get_renderer($component);
47
    }
48
 
49
    /**
50
     * Get the core renderer.
51
     *
52
     * This method is a shortcut to get the core renderer with the correct
53
     * return type declaration. This way the IDE can provide better autocompletion.
54
     *
55
     * @return core_renderer
56
     */
57
    public function get_core_renderer(): core_renderer {
58
        global $PAGE;
59
        return $PAGE->get_renderer('core');
60
    }
61
 
62
    /**
63
     * Get the current page instance.
64
     *
65
     * @return moodle_page
66
     */
67
    public function get_page(): moodle_page {
68
        global $PAGE;
69
        return $PAGE;
70
    }
71
}