From 86e0afcfaaee0608dae83c14e71d09dfa286ae4a Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Wed, 25 Aug 2010 01:14:25 +0000 Subject: [PATCH] backup MDL-23559 Moved UI validation routines from backup_setting to backup_setting_ui and fixed label validation problems --- backup/util/settings/backup_setting.class.php | 2 -- backup/util/settings/base_setting.class.php | 15 --------------- backup/util/ui/backup_ui_setting.class.php | 15 ++++++++++++--- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/backup/util/settings/backup_setting.class.php b/backup/util/settings/backup_setting.class.php index 8a86e4cac97..90de0e1a5bd 100644 --- a/backup/util/settings/backup_setting.class.php +++ b/backup/util/settings/backup_setting.class.php @@ -65,8 +65,6 @@ abstract class backup_setting extends base_setting implements checksumable { * @param array $options */ public function make_ui($type, $label, array $attributes = null, array $options = null) { - $type = $this->validate_ui_type($type); - $label = $this->validate_ui_label($label); $this->uisetting = backup_setting_ui::make($this, $type, $label, $attributes, $options); if (is_array($options) || is_object($options)) { $options = (array)$options; diff --git a/backup/util/settings/base_setting.class.php b/backup/util/settings/base_setting.class.php index 76e183e237a..b2cce66556d 100644 --- a/backup/util/settings/base_setting.class.php +++ b/backup/util/settings/base_setting.class.php @@ -435,21 +435,6 @@ abstract class base_setting { return $status; } - protected function validate_ui_type($type) { - if ($type !== self::UI_HTML_CHECKBOX && $type !== self::UI_HTML_RADIOBUTTON && - $type !== self::UI_HTML_DROPDOWN && $type !== self::UI_HTML_TEXTFIELD) { - throw new base_setting_exception('setting_invalid_ui_type'); - } - return $type; - } - - protected function validate_ui_label($label) { - if (empty($label) || $label !== clean_param($label, PARAM_TEXT)) { - throw new base_setting_exception('setting_invalid_ui_label'); - } - return $label; - } - protected function inform_dependencies($ctype, $oldv) { foreach ($this->dependencies as $dependency) { $dependency->process_change($ctype, $oldv); diff --git a/backup/util/ui/backup_ui_setting.class.php b/backup/util/ui/backup_ui_setting.class.php index 3bca0e2cd07..e3b41794044 100644 --- a/backup/util/ui/backup_ui_setting.class.php +++ b/backup/util/ui/backup_ui_setting.class.php @@ -115,6 +115,9 @@ class base_setting_ui { * @param string $label */ public function set_label($label) { + if (empty($label) || $label !== clean_param($label, PARAM_TEXT)) { + throw new base_setting_ui_exception('setting_invalid_ui_label'); + } $this->label = $label; } /** @@ -174,12 +177,15 @@ abstract class backup_setting_ui extends base_setting_ui { /** * Creates a new backup setting ui based on the setting it is given * + * Throws an exception if an invalid type is provided. + * * @param backup_setting $setting * @param int $type The backup_setting UI type. One of backup_setting::UI_*; * @param string $label The label to display with the setting ui * @param array $attributes Array of HTML attributes to apply to the element * @param array $options Array of options to apply to the setting ui object - * @return backup_setting_ui_text + * + * @return backup_setting_ui_text|backup_setting_ui_checkbox|backup_setting_ui_select|backup_setting_ui_radio */ final public static function make(backup_setting $setting, $type, $label, array $attributes = null, array $options=null) { // Base the decision we make on the type that was sent @@ -193,7 +199,7 @@ abstract class backup_setting_ui extends base_setting_ui { case backup_setting::UI_HTML_TEXTFIELD : return new backup_setting_ui_text($setting, $label, $attributes, $options); default: - return false; + throw new backup_setting_ui_exception('setting_invalid_ui_type'); } } /** @@ -520,4 +526,7 @@ class backup_setting_ui_dateselector extends backup_setting_ui_text { } return parent::get_static_value(); } -} \ No newline at end of file +} + +class base_setting_ui_exception extends base_setting_exception {} +class backup_setting_ui_exception extends base_setting_ui_exception {}; \ No newline at end of file