Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve update() comments #2404

Merged
merged 1 commit into from
May 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/plugins/config/core/Setting/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public function initialize($default = null, $local = null, $protected = null) {
}

/**
* update changed setting with user provided value $input
* - if changed value fails error check, save it to $this->_input (to allow echoing later)
* - if changed value passes error check, set $this->_local to the new value
* update changed setting with validated user provided value $input
* - if changed value fails validation check, save it to $this->input (to allow echoing later)
* - if changed value passes validation check, set $this->local to the new value
*
* @param mixed $input the new value
* @return boolean true if changed, false otherwise (also on error)
* @return boolean true if changed, false otherwise
*/
public function update($input) {
if(is_null($input)) return false;
Expand All @@ -78,13 +78,17 @@ public function update($input) {
$value = is_null($this->local) ? $this->default : $this->local;
if($value == $input) return false;

// validate new value
if($this->pattern && !preg_match($this->pattern, $input)) {
$this->error = true;
$this->input = $input;
return false;
}

// update local copy of this setting with new value
$this->local = $input;

// setting ready for update
return true;
}

Expand Down