Add RegEx filter to JSON parsing

This commit is contained in:
Steffen Lange 2020-10-09 21:34:02 +02:00
parent ae0b34362e
commit a88cf9235e

View file

@ -34,16 +34,16 @@ abstract class PatchBase {
} }
protected function parse(string $re) : bool { protected function parse(string $re) : bool {
if ($str = $this->regex_str($re)) { if ($str = $this->regex_str($re)) {
$this->patch->setVersion($str); $this->patch->setVersion($str, true);
return true; return true;
} }
return false; return false;
} }
protected function parse_json(string $key) : bool { protected function parse_json(string $key, string $re = '/(.*)/') : bool {
$flat = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data))); $flat = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($this->data)));
if (!empty($flat[$key])) { if (!empty($flat[$key])) {
$this->patch->setVersion($flat[$key], true); $this->data = $flat[$key];
return true; return $this->parse($re);
} }
return false; return false;
} }