Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improve update() comments
  • Loading branch information
Chris--S committed May 25, 2018
1 parent c73b800 commit 8356fe6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/plugins/config/core/Setting/Setting.php
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

0 comments on commit 8356fe6

Please sign in to comment.