Skip to content

Commit 903e239

Browse files
[Polyfill] A new component for portability across PHP versions and extensions
1 parent eca3e37 commit 903e239

File tree

141 files changed

+3456
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+3456
-430
lines changed

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"doctrine/common": "~2.4",
2121
"twig/twig": "~1.20|~2.0",
2222
"psr/log": "~1.0",
23-
"symfony/security-acl": "~2.7",
24-
"paragonie/random_compat": "~1.0"
23+
"symfony/security-acl": "~2.7"
2524
},
2625
"replace": {
2726
"symfony/asset": "self.version",
@@ -48,6 +47,7 @@
4847
"symfony/locale": "self.version",
4948
"symfony/monolog-bridge": "self.version",
5049
"symfony/options-resolver": "self.version",
50+
"symfony/polyfill": "self.version",
5151
"symfony/process": "self.version",
5252
"symfony/property-access": "self.version",
5353
"symfony/property-info": "self.version",
@@ -96,10 +96,13 @@
9696
"Symfony\\Component\\": "src/Symfony/Component/"
9797
},
9898
"classmap": [
99-
"src/Symfony/Component/HttpFoundation/Resources/stubs",
99+
"src/Symfony/Component/Polyfill/Resources/stubs",
100100
"src/Symfony/Component/Intl/Resources/stubs"
101101
],
102-
"files": [ "src/Symfony/Component/Intl/Resources/stubs/functions.php" ]
102+
"files": [
103+
"src/Symfony/Component/Polyfill/bootstrap.php",
104+
"src/Symfony/Component/Intl/Resources/stubs/functions.php"
105+
]
103106
},
104107
"minimum-stability": "dev",
105108
"extra": {

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,9 @@ private function normalizeParams(array $params)
9999
}
100100

101101
// detect if the too long string must be shorten
102-
if (function_exists('mb_strlen')) {
103-
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
104-
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
105-
continue;
106-
}
107-
} else {
108-
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
109-
$params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]';
110-
continue;
111-
}
102+
if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) {
103+
$params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
104+
continue;
112105
}
113106
}
114107

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": "~2.8|~3.0.0"
2122
},
2223
"require-dev": {
2324
"symfony/stopwatch": "~2.2|~3.0.0",

src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private function sanitizeString($string, $length = 40)
240240
{
241241
$string = trim(preg_replace('/\s+/', ' ', $string));
242242

243-
if (function_exists('mb_strlen') && false !== $encoding = mb_detect_encoding($string)) {
243+
if (false !== $encoding = mb_detect_encoding($string)) {
244244
if (mb_strlen($string, $encoding) > $length) {
245245
return mb_substr($string, 0, $length - 3, $encoding).'...';
246246
}

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private static function getClassHierarchy(\ReflectionClass $class)
283283

284284
$traits = array();
285285

286-
if (function_exists('get_declared_traits')) {
286+
if (method_exists('ReflectionClass', 'getTraits')) {
287287
foreach ($classes as $c) {
288288
foreach (self::resolveDependencies(self::computeTraitDeps($c), $c) as $trait) {
289289
if ($trait !== $c) {

src/Symfony/Component/Console/Application.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,10 +1077,6 @@ public function setDefaultCommand($commandName)
10771077

10781078
private function stringWidth($string)
10791079
{
1080-
if (!function_exists('mb_strwidth')) {
1081-
return strlen($string);
1082-
}
1083-
10841080
if (false === $encoding = mb_detect_encoding($string)) {
10851081
return strlen($string);
10861082
}
@@ -1094,10 +1090,6 @@ private function splitStringByWidth($string, $width)
10941090
// additionally, array_slice() is not enough as some character has doubled width.
10951091
// we need a function to split string not by character count but by string width
10961092

1097-
if (!function_exists('mb_strwidth')) {
1098-
return str_split($string, $width);
1099-
}
1100-
11011093
if (false === $encoding = mb_detect_encoding($string)) {
11021094
return str_split($string, $width);
11031095
}

src/Symfony/Component/Console/Helper/Helper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ public function getHelperSet()
5151
*/
5252
public static function strlen($string)
5353
{
54-
if (!function_exists('mb_strwidth')) {
55-
return strlen($string);
56-
}
57-
5854
if (false === $encoding = mb_detect_encoding($string)) {
5955
return strlen($string);
6056
}

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private function renderCell(array $row, $column, $cellFormat)
351351
}
352352

353353
// str_pad won't work properly with multi-byte strings, we need to fix the padding
354-
if (function_exists('mb_strwidth') && false !== $encoding = mb_detect_encoding($cell)) {
354+
if (false !== $encoding = mb_detect_encoding($cell)) {
355355
$width += strlen($cell) - mb_strwidth($cell, $encoding);
356356
}
357357

src/Symfony/Component/Console/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.3.9"
19+
"php": ">=5.3.9",
20+
"symfony/polyfill": "~2.8|~3.0.0"
2021
},
2122
"require-dev": {
2223
"symfony/event-dispatcher": "~2.1|~3.0.0",

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function loadClass($class)
161161

162162
ErrorHandler::unstackErrors();
163163

164-
$exists = class_exists($class, false) || interface_exists($class, false) || (function_exists('trait_exists') && trait_exists($class, false));
164+
$exists = class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false);
165165

166166
if ('\\' === $class[0]) {
167167
$class = substr($class, 1);

0 commit comments

Comments
 (0)