1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 06:07:39 +02:00

refactoring

This commit is contained in:
David Grudl
2020-10-08 16:40:42 +02:00
parent f5fa2255ff
commit 34bc742245

View File

@@ -92,24 +92,25 @@ final class Translator
$sql[] = $arg; $sql[] = $arg;
} else { } else {
$sql[] = substr($arg, 0, $toSkip) $sql[] = substr($arg, 0, $toSkip)
/* // note: this can change $this->args & $this->cursor & ...
. preg_replace_callback('/ . preg_replace_callback(<<<'XX'
(?=[`[\'":%?]) ## speed-up /
(?: (?=[`['":%?]) ## speed-up
`(.+?)`| ## 1) `identifier` (?:
\[(.+?)\]| ## 2) [identifier] `(.+?)`| ## 1) `identifier`
(\')((?:\'\'|[^\'])*)\'| ## 3,4) 'string' \[(.+?)\]| ## 2) [identifier]
(")((?:""|[^"])*)"| ## 5,6) "string" (')((?:''|[^'])*)'| ## 3,4) string
(\'|")| ## 7) lone quote (")((?:""|[^"])*)"| ## 5,6) "string"
:(\S*?:)([a-zA-Z0-9._]?)| ## 8,9) :substitution: ('|")| ## 7) lone quote
%([a-zA-Z~][a-zA-Z0-9~]{0,5})|## 10) modifier :(\S*?:)([a-zA-Z0-9._]?)| ## 8,9) :substitution:
(\?) ## 11) placeholder %([a-zA-Z~][a-zA-Z0-9~]{0,5})| ## 10) modifier
)/xs', (\?) ## 11) placeholder
*/ // note: this can change $this->args & $this->cursor & ... )/xs
. preg_replace_callback('/(?=[`[\'":%?])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?)|%([a-zA-Z~][a-zA-Z0-9~]{0,5})|(\?))/s', XX
,
[$this, 'cb'], [$this, 'cb'],
substr($arg, $toSkip) substr($arg, $toSkip)
); );
if (preg_last_error()) { if (preg_last_error()) {
throw new PcreException; throw new PcreException;
} }
@@ -400,11 +401,22 @@ final class Translator
$toSkip = strcspn($value, '`[\'":'); $toSkip = strcspn($value, '`[\'":');
if (strlen($value) !== $toSkip) { if (strlen($value) !== $toSkip) {
$value = substr($value, 0, $toSkip) $value = substr($value, 0, $toSkip)
. preg_replace_callback( . preg_replace_callback(<<<'XX'
'/(?=[`[\'":])(?:`(.+?)`|\[(.+?)\]|(\')((?:\'\'|[^\'])*)\'|(")((?:""|[^"])*)"|(\'|")|:(\S*?:)([a-zA-Z0-9._]?))/s', /
[$this, 'cb'], (?=[`['":])
substr($value, $toSkip) (?:
); `(.+?)`|
\[(.+?)\]|
(')((?:''|[^'])*)'|
(")((?:""|[^"])*)"|
('|")|
:(\S*?:)([a-zA-Z0-9._]?)
)/sx
XX
,
[$this, 'cb'],
substr($value, $toSkip)
);
if (preg_last_error()) { if (preg_last_error()) {
throw new PcreException; throw new PcreException;
} }