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;
18
 
19
/**
20
 * Login metadata requirements for routes.
21
 *
22
 * @package    core
23
 * @copyright  Andrew Lyons <andrew@nicols.co.uk>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
class require_login {
27
    /**
28
     * Create a new instance of the metadata class.
29
     *
30
     * @param bool $requirelogin Whether login is required
31
     * @param bool $requirecourselogin Whether a course login is required
32
     * @param mixed $courseattributename The name of the route attribute that the course object can be found in
33
     * @param bool $autologinguest Whether to automatically log in as guest
34
     * @throws \InvalidArgumentException
35
     */
36
    public function __construct(
37
        /** @var bool Whether login is required */
38
        public bool $requirelogin = false,
39
        /** @var bool Whether a course login is required */
40
        public bool $requirecourselogin = false,
41
        /** @var bool The name of the route attribute that the course object can be found in */
42
        protected ?string $courseattributename = null,
43
        /** @var bool Whether to automatically log in as guest */
44
        public bool $autologinguest = true,
45
    ) {
46
        if ($requirelogin && $requirecourselogin) {
47
            throw new \InvalidArgumentException('Cannot require login and course login at the same time');
48
        }
49
    }
50
 
51
    /**
52
     * Get the course attribute name.
53
     *
54
     * @return string
55
     */
56
    public function get_course_attribute_name(): string {
57
        return $this->courseattributename;
58
    }
59
 
60
    /**
61
     * Whether course login is required.
62
     *
63
     * @return bool
64
     */
65
    public function should_require_course_login(): bool {
66
        return $this->requirecourselogin;
67
    }
68
 
69
    /**
70
     * Whether login is required.
71
     *
72
     * @return bool
73
     */
74
    public function should_require_login(): bool {
75
        return $this->requirelogin;
76
    }
77
 
78
    /**
79
     * Whether automatic guest login is enabled.
80
     *
81
     * @return bool
82
     */
83
    public function should_autologin_guest(): bool {
84
        return $this->autologinguest;
85
    }
86
}