protected function Entity::buildCondition in Search and Replace Scanner 8
Helper function to "build" the proper query condition.
Parameters
string $search: The string that is to be searched for.
bool $mode: The boolean that indicated whether or not the search should be case sensitive.
bool $wholeword: The boolean that indicates whether the search should be word bounded.
string $regex: The string for regular expression.
string $preceded: The string for preceded expression.
bool $followed: The boolean that indicates whether or not the search term is a regular expression.
Return value
array Returns an array containing the SQL and regex matching conditions.
4 calls to Entity::buildCondition()
- Node::replace in src/
Plugin/ Scanner/ Node.php - Performs the replace operation for the given string/expression.
- Node::search in src/
Plugin/ Scanner/ Node.php - Performs the serach operation for the given string/expression.
- Paragraph::replace in src/
Plugin/ Scanner/ Paragraph.php - Performs the replace operation for the given string/expression.
- Paragraph::search in src/
Plugin/ Scanner/ Paragraph.php - Performs the serach operation for the given string/expression.
File
- src/
Plugin/ Scanner/ Entity.php, line 143
Class
- Entity
- Class Entity.
Namespace
Drupal\scanner\Plugin\ScannerCode
protected function buildCondition($search, $mode, $wholeword, $regex, $preceded, $followed) {
$preceded_php = '';
if (!empty($preceded)) {
if (!$regex) {
$preceded = addcslashes($preceded, $this->scanerRegexChars);
}
$preceded_php = '(?<=' . $preceded . ')';
}
$followed_php = '';
if (!empty($followed)) {
if (!$followed) {
$followed = addcslashes($followed, $this->scanerRegexChars);
}
$followed_php = '(?=' . $followed . ')';
}
// Case 1.
if ($wholeword && $regex) {
$value = "[[:<:]]" . $preceded . $search . $followed . "[[:>:]]";
$operator = 'REGEXP';
$phpRegex = '/\\b' . $preceded_php . $search . $followed_php . '\\b/';
}
elseif ($wholeword && !$regex) {
$value = '[[:<:]]' . $preceded . addcslashes($search, $this->scannerRegexChars) . $followed . '[[:>:]]';
$operator = 'REGEXP';
$phpRegex = '/\\b' . $preceded_php . addcslashes($search, $this->scannerRegexChars) . $followed . '\\b/';
}
elseif (!$wholeword && $regex) {
$value = $preceded . $search . $followed;
$operator = 'REGEXP';
$phpRegex = '/' . $preceded_php . $search . $followed_php . '/';
}
else {
$value = '%' . $preceded . addcslashes($search, $this->scannerRegexChars) . $followed . '%';
$operator = 'LIKE';
$phpRegex = '/' . $preceded . addcslashes($search, $this->scannerRegexChars) . $followed . '/';
}
if ($mode) {
return [
'condition' => $value,
'operator' => $operator . ' BINARY',
'phpRegex' => $phpRegex,
];
}
else {
return [
'condition' => $value,
'operator' => $operator,
'phpRegex' => $phpRegex . 'i',
];
}
}