[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  namespace dokuwiki\plugin\config\core\Setting;
   4  
   5  /**
   6   * Class setting_regex
   7   */
   8  class SettingRegex extends SettingString
   9  {
  10      protected $delimiter = '/';    // regex delimiter to be used in testing input
  11      protected $pregflags = 'ui';   // regex pattern modifiers to be used in testing input
  12  
  13      /** @inheritdoc */
  14      public function update($input)
  15      {
  16  
  17          // let parent do basic checks, value, not changed, etc.
  18          $local = $this->local;
  19          if (!parent::update($input)) return false;
  20          $this->local = $local;
  21  
  22          // see if the regex compiles and runs (we don't check for effectiveness)
  23          $regex = $this->delimiter . $input . $this->delimiter . $this->pregflags;
  24          $lastError = error_get_last();
  25          @preg_match($regex, 'testdata');
  26          if (preg_last_error() != PREG_NO_ERROR || error_get_last() !== $lastError) {
  27              $this->input = $input;
  28              $this->error = true;
  29              return false;
  30          }
  31  
  32          $this->local = $input;
  33          return true;
  34      }
  35  }