10a5b05ebSAndreas Gohr<?php 20a5b05ebSAndreas Gohr 30a5b05ebSAndreas Gohrnamespace dokuwiki\plugin\config\core\Setting; 40a5b05ebSAndreas Gohr 50a5b05ebSAndreas Gohr/** 60a5b05ebSAndreas Gohr * Class setting_regex 70a5b05ebSAndreas Gohr */ 88c7c53b0SAndreas Gohrclass SettingRegex extends SettingString 98c7c53b0SAndreas Gohr{ 100a5b05ebSAndreas Gohr protected $delimiter = '/'; // regex delimiter to be used in testing input 110a5b05ebSAndreas Gohr protected $pregflags = 'ui'; // regex pattern modifiers to be used in testing input 120a5b05ebSAndreas Gohr 130a5b05ebSAndreas Gohr /** @inheritdoc */ 14*d868eb89SAndreas Gohr public function update($input) 15*d868eb89SAndreas Gohr { 160a5b05ebSAndreas Gohr 170a5b05ebSAndreas Gohr // let parent do basic checks, value, not changed, etc. 180a5b05ebSAndreas Gohr $local = $this->local; 190a5b05ebSAndreas Gohr if (!parent::update($input)) return false; 200a5b05ebSAndreas Gohr $this->local = $local; 210a5b05ebSAndreas Gohr 220a5b05ebSAndreas Gohr // see if the regex compiles and runs (we don't check for effectiveness) 230a5b05ebSAndreas Gohr $regex = $this->delimiter . $input . $this->delimiter . $this->pregflags; 240a5b05ebSAndreas Gohr $lastError = error_get_last(); 250a5b05ebSAndreas Gohr @preg_match($regex, 'testdata'); 26467c1427SAndreas Gohr if (preg_last_error() != PREG_NO_ERROR || error_get_last() !== $lastError) { 270a5b05ebSAndreas Gohr $this->input = $input; 280a5b05ebSAndreas Gohr $this->error = true; 290a5b05ebSAndreas Gohr return false; 300a5b05ebSAndreas Gohr } 310a5b05ebSAndreas Gohr 320a5b05ebSAndreas Gohr $this->local = $input; 330a5b05ebSAndreas Gohr return true; 340a5b05ebSAndreas Gohr } 350a5b05ebSAndreas Gohr} 36