public function Normalize::addPattern in Bibliography Module 7.2
Add a regex pattern
The regex pattern should be as specific as possible
Parameters
string $regex: The regex should contain the number of parentheses matching the match patterns
array $matchPattern: Array of properties to convert the match patterns to
int $where: self::PREPEND or self::APPEND
2 calls to Normalize::addPattern()
- Normalize::appendPattern in lib/
msrc-authortool/ src/ Nametools/ Normalize.php - Append a pattern to this list, making it the last to check
- Normalize::prependPattern in lib/
msrc-authortool/ src/ Nametools/ Normalize.php - Prepend a pattern to the list, making it the first to check
File
- lib/
msrc-authortool/ src/ Nametools/ Normalize.php, line 74
Class
- Normalize
- Normalize strings from common formats using REGEX
Namespace
NametoolsCode
public function addPattern($regex, $matchPattern, $where = self::APPEND) {
//Test to ensure the number of matches equals the number
//of items in the matchPattern
if ($this->regexCounter
->count($regex) != count($matchPattern)) {
throw new \InvalidArgumentException("The number of matches in the\n regular expression must match the number of elements in the matchPattern");
}
//Test to ensure the matchPattern contains only properties that
//are in the actual match Class
foreach ($matchPattern as $propName) {
if (!in_array($propName, array_keys(get_object_vars($this->matchObject)))) {
throw new \InvalidArgumentException(sprintf("The match pattern should\n only contain properties in the %s class!", get_class($this->matchObject)));
}
}
//Add it
if ($where == self::PREPEND) {
$this->patterns = array_merge(array(
$regex => $matchPattern,
), $this->patterns);
}
else {
$this->patterns[$regex] = $matchPattern;
}
}