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

Skip to content

Commit 6138870

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

File tree

147 files changed

+3532
-442
lines changed

Some content is hidden

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

147 files changed

+3532
-442
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);

src/Symfony/Component/Debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,6 @@ private function convertFileToClass($path, $file, $prefix)
207207
*/
208208
private function classExists($class)
209209
{
210-
return class_exists($class, false) || interface_exists($class, false) || (function_exists('trait_exists') && trait_exists($class, false));
210+
return class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false);
211211
}
212212
}

src/Symfony/Component/Debug/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": "~2.8|~3.0.0",
2021
"psr/log": "~1.0"
2122
},
2223
"conflict": {

src/Symfony/Component/DomCrawler/Crawler.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,34 +173,7 @@ public function addHtmlContent($content, $charset = 'UTF-8')
173173

174174
try {
175175
// Convert charset to HTML-entities to work around bugs in DOMDocument::loadHTML()
176-
177-
if (function_exists('mb_convert_encoding')) {
178-
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
179-
} elseif (function_exists('iconv')) {
180-
$content = preg_replace_callback(
181-
'/[\x80-\xFF]+/',
182-
function ($m) {
183-
$m = unpack('C*', $m[0]);
184-
$i = 1;
185-
$entities = '';
186-
187-
while (isset($m[$i])) {
188-
if (0xF0 <= $m[$i]) {
189-
$c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
190-
} elseif (0xE0 <= $m[$i]) {
191-
$c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
192-
} else {
193-
$c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80;
194-
}
195-
196-
$entities .= '&#'.$c.';';
197-
}
198-
199-
return $entities;
200-
},
201-
iconv($charset, 'UTF-8', $content)
202-
);
203-
}
176+
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset);
204177
} catch (\Exception $e) {
205178
}
206179

src/Symfony/Component/DomCrawler/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/css-selector": "~2.8|~3.0.0"

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function reverseTransform($value)
197197
throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like');
198198
}
199199

200-
if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value)) {
200+
if (false !== $encoding = mb_detect_encoding($value)) {
201201
$length = mb_strlen($value, $encoding);
202202
$remainder = mb_substr($value, $position, $length, $encoding);
203203
} else {

src/Symfony/Component/Form/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"symfony/event-dispatcher": "~2.1|~3.0.0",
2121
"symfony/intl": "~2.4|~3.0.0",
2222
"symfony/options-resolver": "~2.6",
23+
"symfony/polyfill": "~2.8|~3.0.0",
2324
"symfony/property-access": "~2.3|~3.0.0"
2425
},
2526
"require-dev": {

src/Symfony/Component/HttpFoundation/JsonResponse.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function setData($data = array())
142142
}
143143

144144
if (JSON_ERROR_NONE !== json_last_error()) {
145-
throw new \InvalidArgumentException($this->transformJsonError());
145+
throw new \InvalidArgumentException(json_last_error_msg());
146146
}
147147

148148
$this->data = $data;
@@ -196,31 +196,4 @@ protected function update()
196196

197197
return $this->setContent($this->data);
198198
}
199-
200-
private function transformJsonError()
201-
{
202-
if (function_exists('json_last_error_msg')) {
203-
return json_last_error_msg();
204-
}
205-
206-
switch (json_last_error()) {
207-
case JSON_ERROR_DEPTH:
208-
return 'Maximum stack depth exceeded.';
209-
210-
case JSON_ERROR_STATE_MISMATCH:
211-
return 'Underflow or the modes mismatch.';
212-
213-
case JSON_ERROR_CTRL_CHAR:
214-
return 'Unexpected control character found.';
215-
216-
case JSON_ERROR_SYNTAX:
217-
return 'Syntax error, malformed JSON.';
218-
219-
case JSON_ERROR_UTF8:
220-
return 'Malformed UTF-8 characters, possibly incorrectly encoded.';
221-
222-
default:
223-
return 'Unknown error.';
224-
}
225-
}
226199
}

src/Symfony/Component/HttpFoundation/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ $response->send();
3434
The Request and the Response classes have many other methods that implement
3535
the HTTP specification.
3636

37-
Loading
38-
-------
39-
40-
If you are not using Composer but are using PHP 5.3.x, you must add the following to your autoloader:
41-
42-
```php
43-
// SessionHandlerInterface
44-
if (!interface_exists('SessionHandlerInterface')) {
45-
$loader->registerPrefixFallback(__DIR__.'/../vendor/symfony/src/Symfony/Component/HttpFoundation/Resources/stubs');
46-
}
47-
```
48-
4937
Resources
5038
---------
5139

src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,10 @@ public function testSetContentJsonSerializeError()
215215
}
216216
}
217217

218-
if (interface_exists('JsonSerializable')) {
219-
class JsonSerializableObject implements \JsonSerializable
218+
class JsonSerializableObject implements \JsonSerializable
219+
{
220+
public function jsonSerialize()
220221
{
221-
public function jsonSerialize()
222-
{
223-
throw new \Exception('This error is expected');
224-
}
222+
throw new \Exception('This error is expected');
225223
}
226224
}

src/Symfony/Component/HttpFoundation/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
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/expression-language": "~2.4|~3.0.0"
2324
},
2425
"autoload": {
25-
"psr-4": { "Symfony\\Component\\HttpFoundation\\": "" },
26-
"classmap": [ "Resources/stubs" ]
26+
"psr-4": { "Symfony\\Component\\HttpFoundation\\": "" }
2727
},
2828
"minimum-stability": "dev",
2929
"extra": {

src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,10 @@ public function read($path, $locale)
5353
'The resource bundle "%s/%s.json" contains invalid JSON: %s',
5454
$path,
5555
$locale,
56-
self::getLastJsonError()
56+
json_last_error_msg()
5757
));
5858
}
5959

6060
return $data;
6161
}
62-
63-
/**
64-
* @return string The last error message created by {@link json_decode()}
65-
*
66-
* @link http://de2.php.net/manual/en/function.json-last-error-msg.php#113243
67-
*/
68-
private static function getLastJsonError()
69-
{
70-
if (function_exists('json_last_error_msg')) {
71-
return json_last_error_msg();
72-
}
73-
74-
static $errors = array(
75-
JSON_ERROR_NONE => null,
76-
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
77-
JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
78-
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
79-
JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
80-
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
81-
);
82-
83-
$error = json_last_error();
84-
85-
return array_key_exists($error, $errors)
86-
? $errors[$error]
87-
: sprintf('Unknown error (%s)', $error);
88-
}
8962
}

src/Symfony/Component/Intl/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
}
2525
],
2626
"require": {
27-
"php": ">=5.3.9"
27+
"php": ">=5.3.9",
28+
"symfony/polyfill": "~2.8|~3.0.0"
2829
},
2930
"require-dev": {
3031
"symfony/filesystem": "~2.1|~3.0.0"

0 commit comments

Comments
 (0)