* This contains a heuristic for guessing the offsets and groups that are possible for a given regular expression.
*
* This may not be aware of all edge cases.
*/
classRegexKeyExtractor
{
/**
* @var string the inner pattern of the regular expression
*/
private$pattern;
/**
* @var int the byte offset in $this->pattern
*/
private$offset=0;
/**
* @var associative-array<string|int,true> the offsets or names of patterns
*/
private$matches=[];
privatefunction__construct(string$pattern)
{
$this->pattern=$pattern;
}
/**
* @param string|mixed $regex
* @return array<string|int,true> the best guess at the keys that would be parsed into $matches by preg_match, based on the regex and flags passed to preg_match
* @throws InvalidArgumentException if the regex could not be parsed by these heuristics
*/
publicstaticfunctiongetKeys($regex):array
{
if(!\is_string($regex)){
thrownewInvalidArgumentException("regex is not a string");