Replace foreach and strtr with regex + addcslashes

parent 7a92de7b
...@@ -42,9 +42,12 @@ use Doctrine\DBAL\Schema\TableDiff; ...@@ -42,9 +42,12 @@ use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types; use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function addcslashes;
use function implode;
use function preg_quote;
use function preg_replace;
use function sprintf; use function sprintf;
use function strlen; use function strlen;
use function strtr;
/** /**
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central * Base class for all DatabasePlatforms. The DatabasePlatforms are the central
...@@ -3592,12 +3595,11 @@ abstract class AbstractPlatform ...@@ -3592,12 +3595,11 @@ abstract class AbstractPlatform
*/ */
final public function escapeStringForLike(string $inputString, string $escapeChar) : string final public function escapeStringForLike(string $inputString, string $escapeChar) : string
{ {
$replacePairs = [$escapeChar => $escapeChar . $escapeChar]; return preg_replace(
foreach ($this->getLikeWildcardCharacters() as $wildcardChar) { '~([' . preg_quote(implode('', $this->getLikeWildcardCharacters()) . $escapeChar, '~') . '])~u',
$replacePairs[$wildcardChar] = $escapeChar . $wildcardChar; addcslashes($escapeChar, '\\') . '$1',
} $inputString
);
return strtr($inputString, $replacePairs);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment