MDL-45170 files: check other draftfile areas when processing
[moodle.git] / competency / classes / persistent.php
blob6e1223dfdd147909c4625d1eca378a9888040642
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.
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/>.
17 /**
18 * Abstract class for core_competency objects saved to the DB.
20 * @package core_competency
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace core_competency;
25 defined('MOODLE_INTERNAL') || die();
27 // We need to alias the invalid_persistent_exception, because the persistent classes from
28 // core_competency used to throw a \core_competency\invalid_persistent_exception. They now
29 // fully inherit from \core\persistent which throws a core exception. Using class_alias
30 // ensures that previous try/catch statements still work. Also note that we always need
31 // need to alias, we cannot do it passively in the classloader because try/catch statements
32 // do not trigger a class loading. Note that for this trick to work, all the classes
33 // which were extending \core_competency\persistent still need to extend it or the alias
34 // won't be effective.
35 class_alias('core\\invalid_persistent_exception', 'core_competency\\invalid_persistent_exception');
37 /**
38 * Abstract class for core_competency objects saved to the DB.
40 * This is a legacy class which all core_competency persistent classes created prior
41 * to 3.3 must extend.
43 * @copyright 2015 Damyon Wiese
44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
46 abstract class persistent extends \core\persistent {
47 /**
48 * Magic method to capture getters and setters.
49 * This is only available for competency persistents for backwards compatibility.
50 * It is recommended to use get('propertyname') and set('propertyname', 'value') directly.
52 * @param string $method Callee.
53 * @param array $arguments List of arguments.
54 * @return mixed
56 final public function __call($method, $arguments) {
57 debugging('Use of magic setters and getters is deprecated. Use get() and set().', DEBUG_DEVELOPER);
58 if (strpos($method, 'get_') === 0) {
59 return $this->get(substr($method, 4));
60 } else if (strpos($method, 'set_') === 0) {
61 return $this->set(substr($method, 4), $arguments[0]);
63 throw new \coding_exception('Unexpected method call: ' . $method);