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

Skip to content

Commit c81923c

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

File tree

107 files changed

+2944
-557
lines changed

Some content is hidden

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

107 files changed

+2944
-557
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"symfony/locale": "self.version",
4949
"symfony/monolog-bridge": "self.version",
5050
"symfony/options-resolver": "self.version",
51+
"symfony/polyfill": "self.version",
5152
"symfony/process": "self.version",
5253
"symfony/property-access": "self.version",
5354
"symfony/property-info": "self.version",
@@ -96,10 +97,10 @@
9697
"Symfony\\Component\\": "src/Symfony/Component/"
9798
},
9899
"classmap": [
99-
"src/Symfony/Component/HttpFoundation/Resources/stubs",
100+
"src/Symfony/Component/Polyfill/Resources/stubs",
100101
"src/Symfony/Component/Intl/Resources/stubs"
101102
],
102-
"files": [ "src/Symfony/Component/Intl/Resources/stubs/functions.php" ]
103+
"files": [ "src/Symfony/Component/Polyfill/bootstrap.php" ]
103104
},
104105
"minimum-stability": "dev",
105106
"extra": {

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@
4343
</exclude>
4444
</whitelist>
4545
</filter>
46+
47+
<listeners>
48+
<listener class="Symfony\Component\Polyfill\Tests\FunctionsTestListener" />
49+
</listeners>
4650
</phpunit>

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 < iconv_strlen($params[$index], 'UTF-8')) {
103+
$params[$index] = iconv_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]';
104+
continue;
112105
}
113106
}
114107

src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ public function testLogLongString()
132132
));
133133
}
134134

135-
/**
136-
* @requires extension mbstring
137-
*/
138135
public function testLogUTF8LongString()
139136
{
140137
$logger = $this->getMock('Psr\\Log\\LoggerInterface');
@@ -160,7 +157,7 @@ public function testLogUTF8LongString()
160157
$dbalLogger
161158
->expects($this->once())
162159
->method('log')
163-
->with('SQL', array('short' => $shortString, 'long' => mb_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, mb_detect_encoding($longString)).' [...]'))
160+
->with('SQL', array('short' => $shortString, 'long' => iconv_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]'))
164161
;
165162

166163
$dbalLogger->startQuery('SQL', array(

src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener
2424
private $skippedFile = false;
2525
private $wasSkipped = array();
2626
private $isSkipped = array();
27-
private $testsStack = array();
2827

2928
public function __destruct()
3029
{

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/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"symfony/event-dispatcher": "~2.8|~3.0.0",
2424
"symfony/http-foundation": "~2.4.9|~2.5,>=2.5.4|~3.0.0",
2525
"symfony/http-kernel": "~2.8",
26+
"symfony/polyfill": "~2.8|~3.0.0",
2627
"symfony/filesystem": "~2.3|~3.0.0",
2728
"symfony/routing": "~2.8|~3.0.0",
2829
"symfony/security-core": "~2.6|~3.0.0",

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/Tests/ApplicationTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,6 @@ public function testRenderException()
558558
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
559559
}
560560

561-
/**
562-
* @requires extension mbstring
563-
*/
564561
public function testRenderExceptionWithDoubleWidthCharacters()
565562
{
566563
$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ public function testFormatBlock()
5252
);
5353
}
5454

55-
/**
56-
* @requires extension mbstring
57-
*/
5855
public function testFormatBlockWithDiacriticLetters()
5956
{
6057
$formatter = new FormatterHelper();
@@ -68,9 +65,6 @@ public function testFormatBlockWithDiacriticLetters()
6865
);
6966
}
7067

71-
/**
72-
* @requires extension mbstring
73-
*/
7468
public function testFormatBlockWithDoubleWidthDiacriticLetters()
7569
{
7670
$formatter = new FormatterHelper();

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ public function testRedrawFrequency()
155155
$progress->advance(1);
156156
}
157157

158-
/**
159-
* @requires extension mbstring
160-
*/
161158
public function testMultiByteSupport()
162159
{
163160
$progress = new ProgressHelper();

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ public function testRenderProvider()
256256
);
257257
}
258258

259-
/**
260-
* @requires extension mbstring
261-
*/
262259
public function testRenderMultiByte()
263260
{
264261
$table = new TableHelper();
@@ -282,9 +279,6 @@ public function testRenderMultiByte()
282279
$this->assertEquals($expected, $this->getOutputContent($output));
283280
}
284281

285-
/**
286-
* @requires extension mbstring
287-
*/
288282
public function testRenderFullWidthCharacters()
289283
{
290284
$table = new TableHelper();

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,6 @@ public function testRedrawFrequency()
307307
$bar->advance(1);
308308
}
309309

310-
/**
311-
* @requires extension mbstring
312-
*/
313310
public function testMultiByteSupport()
314311
{
315312
$bar = new ProgressBar($output = $this->getOutputStream());
@@ -541,9 +538,6 @@ public function testMultilineFormat()
541538
);
542539
}
543540

544-
/**
545-
* @requires extension mbstring
546-
*/
547541
public function testAnsiColorsAndEmojis()
548542
{
549543
$bar = new ProgressBar($output = $this->getOutputStream(), 15);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,6 @@ public function testRenderProvider()
464464
);
465465
}
466466

467-
/**
468-
* @requires extension mbstring
469-
*/
470467
public function testRenderMultiByte()
471468
{
472469
$table = new Table($output = $this->getOutputStream());

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/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/Tests/CrawlerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public function testAddHtmlContentWithBaseTag()
102102

103103
/**
104104
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
105-
* @requires extension mbstring
106105
*/
107106
public function testAddHtmlContentCharset()
108107
{
@@ -137,7 +136,6 @@ public function testAddHtmlContentUnsupportedCharset()
137136

138137
/**
139138
* @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent
140-
* @requires extension mbstring
141139
*/
142140
public function testAddHtmlContentCharsetGbk()
143141
{

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/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ public function testReverseTransformWithGrouping($to, $from, $locale)
238238

239239
/**
240240
* @see https://github.com/symfony/symfony/issues/7609
241-
*
242-
* @requires extension mbstring
243241
*/
244242
public function testReverseTransformWithGroupingAndFixedSpaces()
245243
{
@@ -583,7 +581,6 @@ public function testReverseTransformDisallowsCenteredExtraCharacters()
583581
/**
584582
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
585583
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
586-
* @requires extension mbstring
587584
*/
588585
public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
589586
{
@@ -600,7 +597,6 @@ public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
600597
/**
601598
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
602599
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
603-
* @requires extension mbstring
604600
*/
605601
public function testReverseTransformIgnoresTrailingSpacesInExceptionMessage()
606602
{
@@ -628,7 +624,6 @@ public function testReverseTransformDisallowsTrailingExtraCharacters()
628624
/**
629625
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
630626
* @expectedExceptionMessage The number contains unrecognized characters: "foo"
631-
* @requires extension mbstring
632627
*/
633628
public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()
634629
{

src/Symfony/Component/Form/Tests/Util/StringUtilTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function testTrim()
2424

2525
/**
2626
* @dataProvider spaceProvider
27-
* @requires extension mbstring
2827
*/
2928
public function testTrimUtf8Separators($hex)
3029
{

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
}

0 commit comments

Comments
 (0)