1<?php 2 3namespace dokuwiki\plugin\config\core\Setting; 4 5/** 6 * Class setting_numeric 7 */ 8class SettingNumeric extends SettingString { 9 // This allows for many PHP syntax errors... 10 // var $_pattern = '/^[-+\/*0-9 ]*$/'; 11 // much more restrictive, but should eliminate syntax errors. 12 protected $pattern = '/^[-+]? *[0-9]+ *(?:[-+*] *[0-9]+ *)*$/'; 13 protected $min = null; 14 protected $max = null; 15 16 /** @inheritdoc */ 17 public function update($input) { 18 $local = $this->local; 19 $valid = parent::update($input); 20 if($valid && !(is_null($this->min) && is_null($this->max))) { 21 $numeric_local = (int) eval('return ' . $this->local . ';'); 22 if((!is_null($this->min) && $numeric_local < $this->min) || 23 (!is_null($this->max) && $numeric_local > $this->max)) { 24 $this->error = true; 25 $this->input = $input; 26 $this->local = $local; 27 $valid = false; 28 } 29 } 30 return $valid; 31 } 32 33 /** @inheritdoc */ 34 public function out($var, $fmt = 'php') { 35 36 if($this->isProtected()) return ''; 37 if(is_null($this->local) || ($this->default == $this->local)) return ''; 38 39 $out = ''; 40 41 if($fmt == 'php') { 42 $local = $this->local === '' ? "''" : $this->local; 43 $out .= '$' . $var . "['" . $this->getArrayKey() . "'] = " . $local . ";\n"; 44 } 45 46 return $out; 47 } 48} 49