@@ -50,30 +50,7 @@ public function startQuery($sql, array $params = null, array $types = null)
50
50
}
51
51
52
52
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 );
77
54
}
78
55
79
56
if (null !== $ this ->logger ) {
@@ -101,4 +78,34 @@ protected function log($message, array $params)
101
78
{
102
79
$ this ->logger ->debug ($ message , $ params );
103
80
}
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
+ }
104
111
}
0 commit comments