Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02d2e2b

Browse files
Replace iconv_*() uses by mb_*(), add mbstring polyfill when required
1 parent b803680 commit 02d2e2b

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ private function normalizeParams(array $params)
9595
}
9696

9797
// detect if the too long string must be shorten
98-
if (self::MAX_STRING_LENGTH < iconv_strlen($params[$index], 'UTF-8')) {
99-
$params[$index] = iconv_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
98+
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
99+
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
100100
continue;
101101
}
102102
}

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20-
"doctrine/common": "~2.4"
20+
"doctrine/common": "~2.4",
21+
"symfony/polyfill-mbstring": "~1.0"
2122
},
2223
"require-dev": {
2324
"symfony/stopwatch": "~2.2|~3.0.0",

src/Symfony/Component/Validator/Constraints/LengthValidator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public function validate($value, Constraint $constraint)
3939
}
4040

4141
$stringValue = (string) $value;
42-
43-
if ('UTF8' === $charset = strtoupper($constraint->charset)) {
44-
$charset = 'UTF-8'; // iconv on Windows requires "UTF-8" instead of "UTF8"
45-
}
46-
47-
$length = @iconv_strlen($stringValue, $charset);
42+
$length = @mb_strlen($stringValue, $charset);
4843
$invalidCharset = false === $length;
4944

5045
if ($invalidCharset) {

src/Symfony/Component/Validator/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20+
"symfony/polyfill-mbstring": "~1.0",
2021
"symfony/translation": "~2.4|~3.0.0"
2122
},
2223
"require-dev": {

src/Symfony/Component/VarDumper/Cloner/VarCloner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ protected function doClone($var)
102102
} else {
103103
$stub->value = $v;
104104
}
105-
} elseif (0 <= $maxString && isset($v[1 + ($maxString >> 2)]) && 0 < $cut = iconv_strlen($v, 'UTF-8') - $maxString) {
105+
} elseif (0 <= $maxString && isset($v[1 + ($maxString >> 2)]) && 0 < $cut = mb_strlen($v, 'UTF-8') - $maxString) {
106106
$stub = new Stub();
107107
$stub->type = Stub::TYPE_STRING;
108108
$stub->class = Stub::STRING_UTF8;
109109
$stub->cut = $cut;
110-
$stub->value = iconv_substr($v, 0, $maxString, 'UTF-8');
110+
$stub->value = mb_substr($v, 0, $maxString, 'UTF-8');
111111
}
112112
break;
113113

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
169169
$this->dumpLine($cursor->depth, true);
170170
} else {
171171
$attr = array(
172-
'length' => 0 <= $cut ? iconv_strlen($str, 'UTF-8') + $cut : 0,
172+
'length' => 0 <= $cut ? mb_strlen($str, 'UTF-8') + $cut : 0,
173173
'binary' => $bin,
174174
);
175175
$str = explode("\n", $str);
@@ -195,8 +195,8 @@ public function dumpString(Cursor $cursor, $str, $bin, $cut)
195195
if ($i < $m) {
196196
$str .= "\n";
197197
}
198-
if (0 < $this->maxStringWidth && $this->maxStringWidth < $len = iconv_strlen($str, 'UTF-8')) {
199-
$str = iconv_substr($str, 0, $this->maxStringWidth, 'UTF-8');
198+
if (0 < $this->maxStringWidth && $this->maxStringWidth < $len = mb_strlen($str, 'UTF-8')) {
199+
$str = mb_substr($str, 0, $this->maxStringWidth, 'UTF-8');
200200
$lineCut = $len - $this->maxStringWidth;
201201
}
202202
if ($m && 0 < $cursor->depth) {

0 commit comments

Comments
 (0)