Skip to content

Commit 8af056e

Browse files
committed
No change - the normalizeParams is a copy-and-paste of the earlier logic
1 parent 6d5fb94 commit 8af056e

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

Logger/DbalLogger.php

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,7 @@ public function startQuery($sql, array $params = null, array $types = null)
5050
}
5151

5252
if (is_array($params)) {
53-
foreach ($params as $index => $param) {
54-
if (!is_string($params[$index])) {
55-
continue;
56-
}
57-
58-
// non utf-8 strings break json encoding
59-
if (!preg_match('//u', $params[$index])) {
60-
$params[$index] = self::BINARY_DATA_VALUE;
61-
continue;
62-
}
63-
64-
// detect if the too long string must be shorten
65-
if (function_exists('mb_strlen')) {
66-
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
67-
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
68-
continue;
69-
}
70-
} else {
71-
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
72-
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
73-
continue;
74-
}
75-
}
76-
}
53+
$params = $this->normalizeParams($params);
7754
}
7855

7956
if (null !== $this->logger) {
@@ -101,4 +78,34 @@ protected function log($message, array $params)
10178
{
10279
$this->logger->debug($message, $params);
10380
}
81+
82+
private function normalizeParams(array $params)
83+
{
84+
foreach ($params as $index => $param) {
85+
if (!is_string($params[$index])) {
86+
continue;
87+
}
88+
89+
// non utf-8 strings break json encoding
90+
if (!preg_match('//u', $params[$index])) {
91+
$params[$index] = self::BINARY_DATA_VALUE;
92+
continue;
93+
}
94+
95+
// detect if the too long string must be shorten
96+
if (function_exists('mb_strlen')) {
97+
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
98+
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
99+
continue;
100+
}
101+
} else {
102+
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
103+
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
104+
continue;
105+
}
106+
}
107+
}
108+
109+
return $params;
110+
}
104111
}

0 commit comments

Comments
 (0)