MDL-57273 persistent: Dont allow set and get for helpers

Helper methods (ie custom methods on a persistent) should not be callable via set() or get() even
if they start with set_ or get_. They are not the same as custom getters and setters for real persistent
properties.
This commit is contained in:
Damyon Wiese 2017-01-24 15:25:54 +08:00
parent 0ce135f65d
commit 6b206c5309
3 changed files with 8 additions and 2 deletions

View File

@ -125,7 +125,7 @@ class competency_summary_exporter extends \core\external\exporter {
$result->scaleconfiguration = $scaleconfiguration;
$result->scaleid = $scaleid;
$level = $competency->get('level');
$level = $competency->get_level();
$taxonomy = $this->related['framework']->get_taxonomy($level);
$result->taxonomyterm = (string) (competency_framework::get_taxonomies_list()[$taxonomy]);

View File

@ -78,7 +78,7 @@ class evidence_exporter extends \core\external\persistent_exporter {
$other['actionuser'] = $actionuser;
}
$other['description'] = $this->persistent->get('description');
$other['description'] = $this->persistent->get_description();
$other['userdate'] = userdate($this->persistent->get('timecreated'));

View File

@ -112,6 +112,9 @@ abstract class persistent {
* @return $this
*/
final public function set($property, $value) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
$methodname = 'set_' . $property;
if (method_exists($this, $methodname)) {
$this->$methodname($value);
@ -133,6 +136,9 @@ abstract class persistent {
* @return mixed
*/
final public function get($property) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
$methodname = 'get_' . $property;
if (method_exists($this, $methodname)) {
return $this->$methodname();