Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea -... Línea 17...
-
 
17
namespace core\attribute;
-
 
18
 
17
namespace core\attribute;
19
use core\exception\coding_exception;
18
 
20
 
19
/**
21
/**
20
 * Attribute to describe a deprecated item.
22
 * Attribute to describe a deprecated item.
21
 *
23
 *
22
 * @package    core
24
 * @package    core
23
 * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
25
 * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
27
 */
-
 
28
#[\Attribute]
26
#[\Attribute]
29
class deprecated {
27
class deprecated {
30
 
28
    /**
31
    /**
29
     * A deprecated item.
32
     * A deprecated item.
-
 
33
     *
30
     *
34
     * This attribute can be applied to any function, class, method, constant, property, enum, etc. Note that at least one of
31
     * This attribute can be applied to any function, class, method, constant, property, enum, etc.
35
     * $replacement, $since or $reason parameters must be non-null
32
     *
36
     *
33
     * Note: The mere presence of the attribute does not do anything. It must be checked by some part of the code.
37
     * Note: The mere presence of the attribute does not do anything. It must be checked by some part of the code.
34
     *
38
     *
Línea 38... Línea 42...
38
     * @param null|string $mdl Link to the Moodle Tracker issue for more information
42
     * @param null|string $mdl Link to the Moodle Tracker issue for more information
39
     * @param bool $final Whether this is a final deprecation
43
     * @param bool $final Whether this is a final deprecation
40
     * @param bool $emit Whether to emit a deprecation warning
44
     * @param bool $emit Whether to emit a deprecation warning
41
     */
45
     */
42
    public function __construct(
46
    public function __construct(
43
        public readonly ?string $replacement,
47
        public readonly ?string $replacement = null,
44
        public readonly ?string $since = null,
48
        public readonly ?string $since = null,
45
        public readonly ?string $reason = null,
49
        public readonly ?string $reason = null,
46
        public readonly ?string $mdl = null,
50
        public readonly ?string $mdl = null,
47
        public readonly bool $final = false,
51
        public readonly bool $final = false,
48
        public readonly bool $emit = true,
52
        public readonly bool $emit = true,
49
    ) {
53
    ) {
50
        if ($replacement === null && $reason === null && $mdl === null) {
54
        if ($replacement === null && $reason === null && $mdl === null) {
51
            throw new \coding_exception(
55
            throw new coding_exception(
52
                'A deprecated item which is not deprecated must provide a reason, or an issue number.',
56
                'A deprecated item must provide either a replacement, reason, or an issue number.',
53
            );
57
            );
54
        }
58
        }
55
    }
59
    }
56
}
60
}