diff options
author | Yaco <franco@reevo.org> | 2022-03-08 13:08:34 +0000 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2022-03-08 13:08:34 +0000 |
commit | c985c40d3f3fc6a2be3be3186df3bf2f32189475 (patch) | |
tree | cee11f5e5a7e351ee0fec36d58d72cbee4f7e49b /platform/www/lib/plugins/config/core/Setting/SettingRegex.php |
first commit after acervus codebase
Diffstat (limited to 'platform/www/lib/plugins/config/core/Setting/SettingRegex.php')
-rw-r--r-- | platform/www/lib/plugins/config/core/Setting/SettingRegex.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/config/core/Setting/SettingRegex.php b/platform/www/lib/plugins/config/core/Setting/SettingRegex.php new file mode 100644 index 0000000..b38f0a5 --- /dev/null +++ b/platform/www/lib/plugins/config/core/Setting/SettingRegex.php @@ -0,0 +1,34 @@ +<?php + +namespace dokuwiki\plugin\config\core\Setting; + +/** + * Class setting_regex + */ +class SettingRegex extends SettingString { + + protected $delimiter = '/'; // regex delimiter to be used in testing input + protected $pregflags = 'ui'; // regex pattern modifiers to be used in testing input + + /** @inheritdoc */ + public function update($input) { + + // let parent do basic checks, value, not changed, etc. + $local = $this->local; + if(!parent::update($input)) return false; + $this->local = $local; + + // see if the regex compiles and runs (we don't check for effectiveness) + $regex = $this->delimiter . $input . $this->delimiter . $this->pregflags; + $lastError = error_get_last(); + @preg_match($regex, 'testdata'); + if(preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) { + $this->input = $input; + $this->error = true; + return false; + } + + $this->local = $input; + return true; + } +} |