1<?php
2
3namespace dokuwiki\plugin\config\core\Setting;
4
5/**
6 * Class setting_regex
7 */
8class 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        // let parent do basic checks, value, not changed, etc.
17        $local = $this->local;
18        if(!parent::update($input)) return false;
19        $this->local = $local;
20
21        // see if the regex compiles and runs (we don't check for effectiveness)
22        $regex = $this->delimiter . $input . $this->delimiter . $this->pregflags;
23        $lastError = error_get_last();
24        @preg_match($regex, 'testdata');
25        if(preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) {
26            $this->input = $input;
27            $this->error = true;
28            return false;
29        }
30
31        $this->local = $input;
32        return true;
33    }
34}
35