[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/config/core/Setting/ -> SettingNumeric.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\plugin\config\core\Setting;
   4  
   5  /**
   6   * Class setting_numeric
   7   */
   8  class 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          if($fmt != 'php') return '';
  36  
  37          $local = $this->local === '' ? "''" : $this->local;
  38          $out = '$' . $var . "['" . $this->getArrayKey() . "'] = " . $local . ";\n";
  39  
  40          return $out;
  41      }
  42  }