Permalink
Browse files

improve update() comments

  • Loading branch information...
Chris--S committed May 25, 2018
1 parent c73b800 commit 8356fe608feb6fe52e9c2115debd8008df3da416
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/plugins/config/core/Setting/Setting.php
@@ -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;
@@ -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;
}

0 comments on commit 8356fe6

Please sign in to comment.