SettingRegex.php 1.0 KB

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