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\renderer_factory;
18
 
19
use core\exception\coding_exception;
20
use core\output\renderer_base;
21
use moodle_page;
22
 
23
/**
24
 * This is the default renderer factory for Moodle.
25
 *
26
 * It simply returns an instance of the appropriate standard renderer class.
27
 *
28
 * @copyright 2009 Tim Hunt
29
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @since Moodle 2.0
31
 * @package core
32
 * @category output
33
 */
34
class standard_renderer_factory extends renderer_factory_base {
35
    /**
36
     * Implement the subclass method
37
     *
38
     * @param moodle_page $page the page the renderer is outputting content for.
39
     * @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
40
     * @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
41
     * @param string $target one of rendering target constants
42
     * @return renderer_base an object implementing the requested renderer interface.
43
     */
44
    public function get_renderer(moodle_page $page, $component, $subtype = null, $target = null) {
45
        $classnames = $this->standard_renderer_classnames($component, $subtype);
46
        $classname = '';
47
 
48
        [$target, $suffix] = $this->get_target_suffix($target);
49
        // First look for a version with a suffix.
50
        foreach ($classnames as $classnamedetails) {
51
            if ($classnamedetails['validwithoutprefix']) {
52
                $newclassname = $classnamedetails['classname'] . $suffix;
53
                if (class_exists($newclassname)) {
54
                    $classname = $newclassname;
55
                    break;
56
                } else {
57
                    $newclassname = $classnamedetails['classname'];
58
                    if (class_exists($newclassname)) {
59
                        $classname = $newclassname;
60
                        break;
61
                    }
62
                }
63
            }
64
        }
65
        // Now look for a non-suffixed version.
66
        if (empty($classname)) {
67
            foreach ($classnames as $classnamedetails) {
68
                if ($classnamedetails['validwithoutprefix']) {
69
                    $newclassname = $classnamedetails['classname'];
70
                    if (class_exists($newclassname)) {
71
                        $classname = $newclassname;
72
                        break;
73
                    }
74
                }
75
            }
76
        }
77
 
78
        if (empty($classname)) {
79
            // Standard renderer must always exist.
80
            throw new coding_exception('Request for an unknown renderer class. Searched for: ' . var_export($classnames, true));
81
        }
82
 
83
        return new $classname($page, $target);
84
    }
85
}
86
 
87
// Alias this class to the old name.
88
// This file will be autoloaded by the legacyclasses autoload system.
89
// In future all uses of this class will be corrected and the legacy references will be removed.
90
class_alias(standard_renderer_factory::class, \standard_renderer_factory::class);