PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/competency/classes/persistent.php

http://github.com/moodle/moodle
PHP | 66 lines | 15 code | 4 blank | 47 comment | 4 complexity | ef8f008f159b6ea8d0a2e800820389b6 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. * Abstract class for core_competency objects saved to the DB.
  18. *
  19. * @package core_competency
  20. * @copyright 2015 Damyon Wiese
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22. */
  23. namespace core_competency;
  24. defined('MOODLE_INTERNAL') || die();
  25. // We need to alias the invalid_persistent_exception, because the persistent classes from
  26. // core_competency used to throw a \core_competency\invalid_persistent_exception. They now
  27. // fully inherit from \core\persistent which throws a core exception. Using class_alias
  28. // ensures that previous try/catch statements still work. Also note that we always need
  29. // need to alias, we cannot do it passively in the classloader because try/catch statements
  30. // do not trigger a class loading. Note that for this trick to work, all the classes
  31. // which were extending \core_competency\persistent still need to extend it or the alias
  32. // won't be effective.
  33. class_alias('core\\invalid_persistent_exception', 'core_competency\\invalid_persistent_exception');
  34. /**
  35. * Abstract class for core_competency objects saved to the DB.
  36. *
  37. * This is a legacy class which all core_competency persistent classes created prior
  38. * to 3.3 must extend.
  39. *
  40. * @copyright 2015 Damyon Wiese
  41. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  42. */
  43. abstract class persistent extends \core\persistent {
  44. /**
  45. * Magic method to capture getters and setters.
  46. * This is only available for competency persistents for backwards compatibility.
  47. * It is recommended to use get('propertyname') and set('propertyname', 'value') directly.
  48. *
  49. * @param string $method Callee.
  50. * @param array $arguments List of arguments.
  51. * @return mixed
  52. */
  53. final public function __call($method, $arguments) {
  54. debugging('Use of magic setters and getters is deprecated. Use get() and set().', DEBUG_DEVELOPER);
  55. if (strpos($method, 'get_') === 0) {
  56. return $this->get(substr($method, 4));
  57. } else if (strpos($method, 'set_') === 0) {
  58. return $this->set(substr($method, 4), $arguments[0]);
  59. }
  60. throw new \coding_exception('Unexpected method call: ' . $method);
  61. }
  62. }