diff --git a/composer.json b/composer.json index b9b9a193ba..d7a70e81c0 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,13 @@ "twig/twig": "~1.20|~2.0", "psr/log": "~1.0", "symfony/security-acl": "~2.7", - "paragonie/random_compat": "~1.0" + "symfony/polyfill-intl-icu": "~1.0", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php54": "~1.0", + "symfony/polyfill-php55": "~1.0", + "symfony/polyfill-php56": "~1.0", + "symfony/polyfill-php70": "~1.0", + "symfony/polyfill-util": "~1.0" }, "replace": { "symfony/asset": "self.version", @@ -77,7 +83,6 @@ "doctrine/orm": "~2.4,>=2.4.5", "doctrine/doctrine-bundle": "~1.2", "monolog/monolog": "~1.11", - "ircmaxell/password-compat": "~1.0", "ocramius/proxy-manager": "~0.4|~1.0", "egulias/email-validator": "~1.2", "phpdocumentor/reflection": "^1.0.7" @@ -96,10 +101,8 @@ "Symfony\\Component\\": "src/Symfony/Component/" }, "classmap": [ - "src/Symfony/Component/HttpFoundation/Resources/stubs", "src/Symfony/Component/Intl/Resources/stubs" - ], - "files": [ "src/Symfony/Component/Intl/Resources/stubs/functions.php" ] + ] }, "minimum-stability": "dev", "extra": { diff --git a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php index 2d834d7d40..51f9f75e4b 100644 --- a/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php +++ b/src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php @@ -99,16 +99,9 @@ class DbalLogger implements SQLLogger } // detect if the too long string must be shorten - if (function_exists('mb_strlen')) { - if (self::MAX_STRING_LENGTH < mb_strlen($params[$index], 'UTF-8')) { - $params[$index] = mb_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]'; - continue; - } - } else { - if (self::MAX_STRING_LENGTH < strlen($params[$index])) { - $params[$index] = substr($params[$index], 0, self::MAX_STRING_LENGTH - 6).' [...]'; - continue; - } + if (self::MAX_STRING_LENGTH < iconv_strlen($params[$index], 'UTF-8')) { + $params[$index] = iconv_substr($params[$index], 0, self::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]'; + continue; } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php index 9141e9a2d3..74afda32eb 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php @@ -132,9 +132,6 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase )); } - /** - * @requires extension mbstring - */ public function testLogUTF8LongString() { $logger = $this->getMock('Psr\\Log\\LoggerInterface'); @@ -160,7 +157,7 @@ class DbalLoggerTest extends \PHPUnit_Framework_TestCase $dbalLogger ->expects($this->once()) ->method('log') - ->with('SQL', array('short' => $shortString, 'long' => mb_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, mb_detect_encoding($longString)).' [...]')) + ->with('SQL', array('short' => $shortString, 'long' => iconv_substr($longString, 0, DbalLogger::MAX_STRING_LENGTH - 6, 'UTF-8').' [...]')) ; $dbalLogger->startQuery('SQL', array( diff --git a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php index 367cc826dc..330cad105b 100644 --- a/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php +++ b/src/Symfony/Bridge/PhpUnit/SymfonyTestsListener.php @@ -24,7 +24,6 @@ class SymfonyTestsListener extends \PHPUnit_Framework_BaseTestListener private $skippedFile = false; private $wasSkipped = array(); private $isSkipped = array(); - private $testsStack = array(); public function __destruct() { diff --git a/src/Symfony/Bridge/Twig/composer.json b/src/Symfony/Bridge/Twig/composer.json index e33589122f..a76006086a 100644 --- a/src/Symfony/Bridge/Twig/composer.json +++ b/src/Symfony/Bridge/Twig/composer.json @@ -24,7 +24,7 @@ "symfony/finder": "~2.3|~3.0.0", "symfony/form": "~2.8", "symfony/http-kernel": "~2.8|~3.0.0", - "symfony/intl": "~2.3|~3.0.0", + "symfony/polyfill-intl-icu": "~1.0", "symfony/routing": "~2.2|~3.0.0", "symfony/templating": "~2.1|~3.0.0", "symfony/translation": "~2.7|~3.0.0", diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php index 1608010116..da99cf1d29 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php @@ -240,7 +240,7 @@ EOF { $string = trim(preg_replace('/\s+/', ' ', $string)); - if (function_exists('mb_strlen') && false !== $encoding = mb_detect_encoding($string)) { + if (false !== $encoding = mb_detect_encoding($string, null, true)) { if (mb_strlen($string, $encoding) > $length) { return mb_substr($string, 0, $length - 3, $encoding).'...'; } diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index d53e785a7e..cf9b510b34 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -24,6 +24,7 @@ "symfony/event-dispatcher": "~2.8|~3.0.0", "symfony/http-foundation": "~2.4.9|~2.5,>=2.5.4|~3.0.0", "symfony/http-kernel": "~2.8", + "symfony/polyfill-mbstring": "~1.0", "symfony/filesystem": "~2.3|~3.0.0", "symfony/routing": "~2.8|~3.0.0", "symfony/security-core": "~2.6|~3.0.0", @@ -40,7 +41,7 @@ "symfony/css-selector": "~2.0,>=2.0.5|~3.0.0", "symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0", "symfony/finder": "~2.0,>=2.0.5|~3.0.0", - "symfony/intl": "~2.3|~3.0.0", + "symfony/polyfill-intl-icu": "~1.0", "symfony/security": "~2.6|~3.0.0", "symfony/form": "~2.8", "symfony/expression-language": "~2.6|~3.0.0", diff --git a/src/Symfony/Bundle/SecurityBundle/composer.json b/src/Symfony/Bundle/SecurityBundle/composer.json index 256652dafa..7c6b9dc98d 100644 --- a/src/Symfony/Bundle/SecurityBundle/composer.json +++ b/src/Symfony/Bundle/SecurityBundle/composer.json @@ -23,7 +23,6 @@ }, "require-dev": { "symfony/browser-kit": "~2.4|~3.0.0", - "symfony/config": "~2.8|~3.0.0", "symfony/console": "~2.7|~3.0.0", "symfony/css-selector": "~2.0,>=2.0.5|~3.0.0", "symfony/dom-crawler": "~2.0,>=2.0.5|~3.0.0", @@ -37,8 +36,7 @@ "symfony/yaml": "~2.0,>=2.0.5|~3.0.0", "symfony/expression-language": "~2.6|~3.0.0", "doctrine/doctrine-bundle": "~1.2", - "twig/twig": "~1.20|~2.0", - "ircmaxell/password-compat": "~1.0" + "twig/twig": "~1.20|~2.0" }, "autoload": { "psr-4": { "Symfony\\Bundle\\SecurityBundle\\": "" } diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 71ac6aed41..1f398622bf 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -1077,11 +1077,7 @@ class Application private function stringWidth($string) { - if (!function_exists('mb_strwidth')) { - return strlen($string); - } - - if (false === $encoding = mb_detect_encoding($string)) { + if (false === $encoding = mb_detect_encoding($string, null, true)) { return strlen($string); } @@ -1094,11 +1090,7 @@ class Application // additionally, array_slice() is not enough as some character has doubled width. // we need a function to split string not by character count but by string width - if (!function_exists('mb_strwidth')) { - return str_split($string, $width); - } - - if (false === $encoding = mb_detect_encoding($string)) { + if (false === $encoding = mb_detect_encoding($string, null, true)) { return str_split($string, $width); } diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Component/Console/Helper/Helper.php index b288d446bd..b542be3a66 100644 --- a/src/Symfony/Component/Console/Helper/Helper.php +++ b/src/Symfony/Component/Console/Helper/Helper.php @@ -51,11 +51,7 @@ abstract class Helper implements HelperInterface */ public static function strlen($string) { - if (!function_exists('mb_strwidth')) { - return strlen($string); - } - - if (false === $encoding = mb_detect_encoding($string)) { + if (false === $encoding = mb_detect_encoding($string, null, true)) { return strlen($string); } diff --git a/src/Symfony/Component/Console/Helper/Table.php b/src/Symfony/Component/Console/Helper/Table.php index 5d89b59a8b..db41f092fa 100644 --- a/src/Symfony/Component/Console/Helper/Table.php +++ b/src/Symfony/Component/Console/Helper/Table.php @@ -351,7 +351,7 @@ class Table } // str_pad won't work properly with multi-byte strings, we need to fix the padding - if (function_exists('mb_strwidth') && false !== $encoding = mb_detect_encoding($cell)) { + if (false !== $encoding = mb_detect_encoding($cell, null, true)) { $width += strlen($cell) - mb_strwidth($cell, $encoding); } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index e98ceb3e02..c5e16088b2 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -558,9 +558,6 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal'); } - /** - * @requires extension mbstring - */ public function testRenderExceptionWithDoubleWidthCharacters() { $application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth')); diff --git a/src/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php index 15b53e1da6..e0aa9211d3 100644 --- a/src/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/FormatterHelperTest.php @@ -52,9 +52,6 @@ class FormatterHelperTest extends \PHPUnit_Framework_TestCase ); } - /** - * @requires extension mbstring - */ public function testFormatBlockWithDiacriticLetters() { $formatter = new FormatterHelper(); @@ -68,9 +65,6 @@ class FormatterHelperTest extends \PHPUnit_Framework_TestCase ); } - /** - * @requires extension mbstring - */ public function testFormatBlockWithDoubleWidthDiacriticLetters() { $formatter = new FormatterHelper(); diff --git a/src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php index 7c866e8570..f835a71e77 100644 --- a/src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/LegacyProgressHelperTest.php @@ -155,9 +155,6 @@ class LegacyProgressHelperTest extends \PHPUnit_Framework_TestCase $progress->advance(1); } - /** - * @requires extension mbstring - */ public function testMultiByteSupport() { $progress = new ProgressHelper(); diff --git a/src/Symfony/Component/Console/Tests/Helper/LegacyTableHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/LegacyTableHelperTest.php index 02c6d7f6e2..3838e00712 100644 --- a/src/Symfony/Component/Console/Tests/Helper/LegacyTableHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/LegacyTableHelperTest.php @@ -256,9 +256,6 @@ TABLE ); } - /** - * @requires extension mbstring - */ public function testRenderMultiByte() { $table = new TableHelper(); @@ -282,9 +279,6 @@ TABLE; $this->assertEquals($expected, $this->getOutputContent($output)); } - /** - * @requires extension mbstring - */ public function testRenderFullWidthCharacters() { $table = new TableHelper(); diff --git a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php index e22734a29e..16a4bba54b 100644 --- a/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php @@ -307,9 +307,6 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase $bar->advance(1); } - /** - * @requires extension mbstring - */ public function testMultiByteSupport() { $bar = new ProgressBar($output = $this->getOutputStream()); @@ -541,9 +538,6 @@ class ProgressBarTest extends \PHPUnit_Framework_TestCase ); } - /** - * @requires extension mbstring - */ public function testAnsiColorsAndEmojis() { $bar = new ProgressBar($output = $this->getOutputStream(), 15); diff --git a/src/Symfony/Component/Console/Tests/Helper/TableTest.php b/src/Symfony/Component/Console/Tests/Helper/TableTest.php index 4f89a9938f..5a33b7d2f9 100644 --- a/src/Symfony/Component/Console/Tests/Helper/TableTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/TableTest.php @@ -464,9 +464,6 @@ TABLE ); } - /** - * @requires extension mbstring - */ public function testRenderMultiByte() { $table = new Table($output = $this->getOutputStream()); diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 9ed17c30d3..d8500b47ea 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { "symfony/event-dispatcher": "~2.1|~3.0.0", diff --git a/src/Symfony/Component/DomCrawler/Crawler.php b/src/Symfony/Component/DomCrawler/Crawler.php index ece2e9847a..c238352f21 100644 --- a/src/Symfony/Component/DomCrawler/Crawler.php +++ b/src/Symfony/Component/DomCrawler/Crawler.php @@ -173,34 +173,7 @@ class Crawler extends \SplObjectStorage try { // Convert charset to HTML-entities to work around bugs in DOMDocument::loadHTML() - - if (function_exists('mb_convert_encoding')) { - $content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset); - } elseif (function_exists('iconv')) { - $content = preg_replace_callback( - '/[\x80-\xFF]+/', - function ($m) { - $m = unpack('C*', $m[0]); - $i = 1; - $entities = ''; - - while (isset($m[$i])) { - if (0xF0 <= $m[$i]) { - $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; - } elseif (0xE0 <= $m[$i]) { - $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; - } else { - $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80; - } - - $entities .= '&#'.$c.';'; - } - - return $entities; - }, - iconv($charset, 'UTF-8', $content) - ); - } + $content = mb_convert_encoding($content, 'HTML-ENTITIES', $charset); } catch (\Exception $e) { } diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index de8e217aee..ecdfc0fe23 100755 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -102,7 +102,6 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase /** * @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent - * @requires extension mbstring */ public function testAddHtmlContentCharset() { @@ -137,7 +136,6 @@ class CrawlerTest extends \PHPUnit_Framework_TestCase /** * @covers Symfony\Component\DomCrawler\Crawler::addHtmlContent - * @requires extension mbstring */ public function testAddHtmlContentCharsetGbk() { diff --git a/src/Symfony/Component/DomCrawler/composer.json b/src/Symfony/Component/DomCrawler/composer.json index 5e3922fe8e..ce2aa8fd6a 100644 --- a/src/Symfony/Component/DomCrawler/composer.json +++ b/src/Symfony/Component/DomCrawler/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { "symfony/css-selector": "~2.8|~3.0.0" diff --git a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php index 8aef383fe4..0c7c327f48 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php +++ b/src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php @@ -197,7 +197,7 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface throw new TransformationFailedException('I don\'t have a clear idea what infinity looks like'); } - if (function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value)) { + if (false !== $encoding = mb_detect_encoding($value, null, true)) { $length = mb_strlen($value, $encoding); $remainder = mb_substr($value, $position, $length, $encoding); } else { diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php index 02131f68c4..2a47178dad 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php @@ -238,8 +238,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase /** * @see https://github.com/symfony/symfony/issues/7609 - * - * @requires extension mbstring */ public function testReverseTransformWithGroupingAndFixedSpaces() { @@ -583,7 +581,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException * @expectedExceptionMessage The number contains unrecognized characters: "foo8" - * @requires extension mbstring */ public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte() { @@ -600,7 +597,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException * @expectedExceptionMessage The number contains unrecognized characters: "foo8" - * @requires extension mbstring */ public function testReverseTransformIgnoresTrailingSpacesInExceptionMessage() { @@ -628,7 +624,6 @@ class NumberToLocalizedStringTransformerTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException * @expectedExceptionMessage The number contains unrecognized characters: "foo" - * @requires extension mbstring */ public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte() { diff --git a/src/Symfony/Component/Form/Tests/Util/StringUtilTest.php b/src/Symfony/Component/Form/Tests/Util/StringUtilTest.php index ddbafe49dc..bd9b28c46e 100644 --- a/src/Symfony/Component/Form/Tests/Util/StringUtilTest.php +++ b/src/Symfony/Component/Form/Tests/Util/StringUtilTest.php @@ -24,7 +24,6 @@ class StringUtilTest extends \PHPUnit_Framework_TestCase /** * @dataProvider spaceProvider - * @requires extension mbstring */ public function testTrimUtf8Separators($hex) { diff --git a/src/Symfony/Component/Form/composer.json b/src/Symfony/Component/Form/composer.json index 307b383610..dd43dcd3c2 100644 --- a/src/Symfony/Component/Form/composer.json +++ b/src/Symfony/Component/Form/composer.json @@ -20,6 +20,7 @@ "symfony/event-dispatcher": "~2.1|~3.0.0", "symfony/intl": "~2.4|~3.0.0", "symfony/options-resolver": "~2.6", + "symfony/polyfill-mbstring": "~1.0", "symfony/property-access": "~2.3|~3.0.0" }, "require-dev": { diff --git a/src/Symfony/Component/HttpFoundation/JsonResponse.php b/src/Symfony/Component/HttpFoundation/JsonResponse.php index 5399d1b1f1..0445a9a6ce 100644 --- a/src/Symfony/Component/HttpFoundation/JsonResponse.php +++ b/src/Symfony/Component/HttpFoundation/JsonResponse.php @@ -142,7 +142,7 @@ class JsonResponse extends Response } if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException($this->transformJsonError()); + throw new \InvalidArgumentException(json_last_error_msg()); } $this->data = $data; @@ -196,31 +196,4 @@ class JsonResponse extends Response return $this->setContent($this->data); } - - private function transformJsonError() - { - if (function_exists('json_last_error_msg')) { - return json_last_error_msg(); - } - - switch (json_last_error()) { - case JSON_ERROR_DEPTH: - return 'Maximum stack depth exceeded.'; - - case JSON_ERROR_STATE_MISMATCH: - return 'Underflow or the modes mismatch.'; - - case JSON_ERROR_CTRL_CHAR: - return 'Unexpected control character found.'; - - case JSON_ERROR_SYNTAX: - return 'Syntax error, malformed JSON.'; - - case JSON_ERROR_UTF8: - return 'Malformed UTF-8 characters, possibly incorrectly encoded.'; - - default: - return 'Unknown error.'; - } - } } diff --git a/src/Symfony/Component/HttpFoundation/README.md b/src/Symfony/Component/HttpFoundation/README.md index 11ad6eef54..a7dba39e0b 100644 --- a/src/Symfony/Component/HttpFoundation/README.md +++ b/src/Symfony/Component/HttpFoundation/README.md @@ -34,18 +34,6 @@ $response->send(); The Request and the Response classes have many other methods that implement the HTTP specification. -Loading -------- - -If you are not using Composer but are using PHP 5.3.x, you must add the following to your autoloader: - -```php -// SessionHandlerInterface -if (!interface_exists('SessionHandlerInterface')) { - $loader->registerPrefixFallback(__DIR__.'/../vendor/symfony/src/Symfony/Component/HttpFoundation/Resources/stubs'); -} -``` - Resources --------- diff --git a/src/Symfony/Component/HttpFoundation/Resources/stubs/SessionHandlerInterface.php b/src/Symfony/Component/HttpFoundation/Resources/stubs/SessionHandlerInterface.php deleted file mode 100644 index 9baa7bc0f6..0000000000 --- a/src/Symfony/Component/HttpFoundation/Resources/stubs/SessionHandlerInterface.php +++ /dev/null @@ -1,102 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -/** - * SessionHandlerInterface for PHP < 5.4. - * - * The order in which these methods are invoked by PHP are: - * 1. open [session_start] - * 2. read - * 3. gc [optional depending on probability settings: gc_probability / gc_divisor] - * 4. destroy [optional when session_regenerate_id(true) is used] - * 5. write [session_write_close] or destroy [session_destroy] - * 6. close - * - * Extensive documentation can be found at php.net, see links: - * - * @see http://php.net/sessionhandlerinterface - * @see http://php.net/session.customhandler - * @see http://php.net/session-set-save-handler - * - * @author Drak - * @author Tobias Schultze - */ -interface SessionHandlerInterface -{ - /** - * Re-initializes existing session, or creates a new one. - * - * @see http://php.net/sessionhandlerinterface.open - * - * @param string $savePath Save path - * @param string $sessionName Session name, see http://php.net/function.session-name.php - * - * @return bool true on success, false on failure - */ - public function open($savePath, $sessionName); - - /** - * Closes the current session. - * - * @see http://php.net/sessionhandlerinterface.close - * - * @return bool true on success, false on failure - */ - public function close(); - - /** - * Reads the session data. - * - * @see http://php.net/sessionhandlerinterface.read - * - * @param string $sessionId Session ID, see http://php.net/function.session-id - * - * @return string Same session data as passed in write() or empty string when non-existent or on failure - */ - public function read($sessionId); - - /** - * Writes the session data to the storage. - * - * Care, the session ID passed to write() can be different from the one previously - * received in read() when the session ID changed due to session_regenerate_id(). - * - * @see http://php.net/sessionhandlerinterface.write - * - * @param string $sessionId Session ID , see http://php.net/function.session-id - * @param string $data Serialized session data to save - * - * @return bool true on success, false on failure - */ - public function write($sessionId, $data); - - /** - * Destroys a session. - * - * @see http://php.net/sessionhandlerinterface.destroy - * - * @param string $sessionId Session ID, see http://php.net/function.session-id - * - * @return bool true on success, false on failure - */ - public function destroy($sessionId); - - /** - * Cleans up expired sessions (garbage collection). - * - * @see http://php.net/sessionhandlerinterface.gc - * - * @param string|int $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed - * - * @return bool true on success, false on failure - */ - public function gc($maxlifetime); -} diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index fd03dc8447..52e9900d71 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -101,11 +101,7 @@ class NativeSessionStorage implements SessionStorageInterface session_cache_limiter(''); // disable by default because it's managed by HeaderBag (if used) ini_set('session.use_cookies', 1); - if (PHP_VERSION_ID >= 50400) { - session_register_shutdown(); - } else { - register_shutdown_function('session_write_close'); - } + session_register_shutdown(); $this->setMetadataBag($metaBag); $this->setOptions($options); diff --git a/src/Symfony/Component/HttpFoundation/composer.json b/src/Symfony/Component/HttpFoundation/composer.json index 3933c57e73..5a611e6d0c 100644 --- a/src/Symfony/Component/HttpFoundation/composer.json +++ b/src/Symfony/Component/HttpFoundation/composer.json @@ -16,14 +16,14 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-php54": "~1.0" }, "require-dev": { "symfony/expression-language": "~2.4|~3.0.0" }, "autoload": { - "psr-4": { "Symfony\\Component\\HttpFoundation\\": "" }, - "classmap": [ "Resources/stubs" ] + "psr-4": { "Symfony\\Component\\HttpFoundation\\": "" } }, "minimum-stability": "dev", "extra": { diff --git a/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php b/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php index 1e19de10a8..2d093dfd37 100644 --- a/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/Profiler/MongoDbProfilerStorageTest.php @@ -105,7 +105,7 @@ class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest $profile = new Profile('utf8_test_profile'); $data = 'HЁʃʃϿ, ϢorЃd!'; - $nonUtf8Data = mb_convert_encoding($data, 'UCS-2'); + $nonUtf8Data = iconv('UTF-8', 'UCS-2', $data); $collector = new MongoDbProfilerStorageTestDataCollector(); $collector->setData($nonUtf8Data); diff --git a/src/Symfony/Component/Intl/Collator/Collator.php b/src/Symfony/Component/Intl/Collator/Collator.php index 90fba8d491..7482aaa26f 100644 --- a/src/Symfony/Component/Intl/Collator/Collator.php +++ b/src/Symfony/Component/Intl/Collator/Collator.php @@ -30,6 +30,8 @@ use Symfony\Component\Intl\Locale\Locale; * * @author Igor Wiedler * @author Bernhard Schussek + * + * @internal */ class Collator { diff --git a/src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php b/src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php index 1973843481..84b20abf77 100644 --- a/src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php +++ b/src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php @@ -53,37 +53,10 @@ class JsonBundleReader implements BundleReaderInterface 'The resource bundle "%s/%s.json" contains invalid JSON: %s', $path, $locale, - self::getLastJsonError() + json_last_error_msg() )); } return $data; } - - /** - * @return string The last error message created by {@link json_decode()} - * - * @link http://de2.php.net/manual/en/function.json-last-error-msg.php#113243 - */ - private static function getLastJsonError() - { - if (function_exists('json_last_error_msg')) { - return json_last_error_msg(); - } - - static $errors = array( - JSON_ERROR_NONE => null, - JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', - JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', - JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', - JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON', - JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', - ); - - $error = json_last_error(); - - return array_key_exists($error, $errors) - ? $errors[$error] - : sprintf('Unknown error (%s)', $error); - } } diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php index 0183683932..66376475c6 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/AmPmTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for AM/PM markers format. * * @author Igor Wiedler + * + * @internal */ class AmPmTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php index 6263e22405..a174fdcabc 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfWeekTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for day of week format. * * @author Igor Wiedler + * + * @internal */ class DayOfWeekTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php index 0c88b859d1..5af6dd7243 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for day of year format. * * @author Igor Wiedler + * + * @internal */ class DayOfYearTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php index 1f79761958..f0ded907c3 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for day format. * * @author Igor Wiedler + * + * @internal */ class DayTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php index 3c3410e879..0f627d9510 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php @@ -18,6 +18,8 @@ use Symfony\Component\Intl\Globals\IntlGlobals; * Parser and formatter for date formats. * * @author Igor Wiedler + * + * @internal */ class FullTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php index ce79300267..948e345044 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for 12 hour format (0-11). * * @author Igor Wiedler + * + * @internal */ class Hour1200Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php index 57d0c3192b..19c4d203ab 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1201Transformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for 12 hour format (1-12). * * @author Igor Wiedler + * + * @internal */ class Hour1201Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php index a6642bc6af..e43d0ee8b2 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for 24 hour format (0-23). * * @author Igor Wiedler + * + * @internal */ class Hour2400Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php index 6fbb445502..df4e671aaf 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for 24 hour format (1-24). * * @author Igor Wiedler + * + * @internal */ class Hour2401Transformer extends HourTransformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php index 1dfddefef3..349d8e29ae 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/HourTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Base class for hour transformers. * * @author Eriksen Costa + * + * @internal */ abstract class HourTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php index ac7b2ae93c..08b5356e3f 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MinuteTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for minute format. * * @author Igor Wiedler + * + * @internal */ class MinuteTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php index 4b02c85b24..6d7c819800 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/MonthTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for month format. * * @author Igor Wiedler + * + * @internal */ class MonthTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php index 944298baf9..fa7e91d038 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/QuarterTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for quarter format. * * @author Igor Wiedler + * + * @internal */ class QuarterTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php index 5d37ed835d..dd2e7bd9f9 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/SecondTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for the second format. * * @author Igor Wiedler + * + * @internal */ class SecondTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php index 6f9c0d5a02..8d16b365e5 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimeZoneTransformer.php @@ -17,6 +17,8 @@ use Symfony\Component\Intl\Exception\NotImplementedException; * Parser and formatter for time zone format. * * @author Igor Wiedler + * + * @internal */ class TimeZoneTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php index 25ecab572a..26a25db355 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Transformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for date formats. * * @author Igor Wiedler + * + * @internal */ abstract class Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php index a715bf4284..0b546b774a 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/YearTransformer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\DateFormatter\DateFormat; * Parser and formatter for year format. * * @author Igor Wiedler + * + * @internal */ class YearTransformer extends Transformer { diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index af398afc91..345bd18e18 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -43,6 +43,8 @@ use Symfony\Component\Intl\Locale\Locale; * * @author Igor Wiedler * @author Bernhard Schussek + * + * @internal */ class IntlDateFormatter { diff --git a/src/Symfony/Component/Intl/Globals/IntlGlobals.php b/src/Symfony/Component/Intl/Globals/IntlGlobals.php index 2d5d4d3600..ec2ee17469 100644 --- a/src/Symfony/Component/Intl/Globals/IntlGlobals.php +++ b/src/Symfony/Component/Intl/Globals/IntlGlobals.php @@ -15,6 +15,8 @@ namespace Symfony\Component\Intl\Globals; * Provides fake static versions of the global functions in the intl extension. * * @author Bernhard Schussek + * + * @internal */ abstract class IntlGlobals { diff --git a/src/Symfony/Component/Intl/Locale/Locale.php b/src/Symfony/Component/Intl/Locale/Locale.php index 23194a064d..0217b14521 100644 --- a/src/Symfony/Component/Intl/Locale/Locale.php +++ b/src/Symfony/Component/Intl/Locale/Locale.php @@ -21,6 +21,8 @@ use Symfony\Component\Intl\Exception\MethodNotImplementedException; * * @author Eriksen Costa * @author Bernhard Schussek + * + * @internal */ class Locale { diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index c1a77a7406..13b1f48868 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -37,6 +37,8 @@ use Symfony\Component\Intl\Locale\Locale; * * @author Eriksen Costa * @author Bernhard Schussek + * + * @internal */ class NumberFormatter { diff --git a/src/Symfony/Component/Intl/Resources/stubs/functions.php b/src/Symfony/Component/Intl/Resources/stubs/functions.php deleted file mode 100644 index 704f0f0c72..0000000000 --- a/src/Symfony/Component/Intl/Resources/stubs/functions.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -use Symfony\Component\Intl\Globals\IntlGlobals; - -if (!function_exists('intl_is_failure')) { - /** - * Stub implementation for the {@link intl_is_failure()} function of the intl - * extension. - * - * @author Bernhard Schussek - * - * @param int $errorCode The error code returned by intl_get_error_code(). - * - * @return bool Whether the error code indicates an error. - * - * @see IntlGlobals::isFailure() - */ - function intl_is_failure($errorCode) - { - return IntlGlobals::isFailure($errorCode); - } - - /** - * Stub implementation for the {@link intl_get_error_code()} function of the - * intl extension. - * - * @author Bernhard Schussek - * - * @return bool The error code of the last intl function call or - * IntlGlobals::U_ZERO_ERROR if no error occurred. - * - * @see IntlGlobals::getErrorCode() - */ - function intl_get_error_code() - { - return IntlGlobals::getErrorCode(); - } - - /** - * Stub implementation for the {@link intl_get_error_code()} function of the - * intl extension. - * - * @author Bernhard Schussek - * - * @return bool The error message of the last intl function call or - * "U_ZERO_ERROR" if no error occurred. - * - * @see IntlGlobals::getErrorMessage() - */ - function intl_get_error_message() - { - return IntlGlobals::getErrorMessage(); - } - - /** - * Stub implementation for the {@link intl_error_name()} function of the intl - * extension. - * - * @param int $errorCode The error code. - * - * @return string The name of the error code constant. - * - * @see IntlGlobals::getErrorName() - */ - function intl_error_name($errorCode) - { - return IntlGlobals::getErrorName($errorCode); - } -} diff --git a/src/Symfony/Component/Intl/composer.json b/src/Symfony/Component/Intl/composer.json index 2b9a24ebf1..d862424942 100644 --- a/src/Symfony/Component/Intl/composer.json +++ b/src/Symfony/Component/Intl/composer.json @@ -24,7 +24,9 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-intl-icu": "~1.0", + "symfony/polyfill-php54": "~1.0" }, "require-dev": { "symfony/filesystem": "~2.1|~3.0.0" @@ -34,8 +36,7 @@ }, "autoload": { "psr-4": { "Symfony\\Component\\Intl\\": "" }, - "classmap": [ "Resources/stubs" ], - "files": [ "Resources/stubs/functions.php" ] + "classmap": [ "Resources/stubs" ] }, "minimum-stability": "dev", "extra": { diff --git a/src/Symfony/Component/Ldap/LdapClient.php b/src/Symfony/Component/Ldap/LdapClient.php index 41c8892f71..734ff4e906 100644 --- a/src/Symfony/Component/Ldap/LdapClient.php +++ b/src/Symfony/Component/Ldap/LdapClient.php @@ -97,11 +97,7 @@ class LdapClient implements LdapClientInterface */ public function escape($subject, $ignore = '', $flags = 0) { - if (function_exists('ldap_escape')) { - return ldap_escape($subject, $ignore, $flags); - } - - return $this->doEscape($subject, $ignore, $flags); + return ldap_escape($subject, $ignore, $flags); } private function connect() @@ -132,98 +128,4 @@ class LdapClient implements LdapClientInterface $this->connection = null; } - - /** - * Stub implementation of the {@link ldap_escape()} function of the ldap - * extension. - * - * Escape strings for safe use in LDAP filters and DNs. - * - * @author Chris Wright - * - * @param string $subject - * @param string $ignore - * @param int $flags - * - * @return string - * - * @see http://stackoverflow.com/a/8561604 - */ - private function doEscape($subject, $ignore = '', $flags = 0) - { - $charMaps = $this->getCharmaps(); - - // Create the base char map to escape - $flags = (int) $flags; - $charMap = array(); - - if ($flags & self::LDAP_ESCAPE_FILTER) { - $charMap += $charMaps[self::LDAP_ESCAPE_FILTER]; - } - - if ($flags & self::LDAP_ESCAPE_DN) { - $charMap += $charMaps[self::LDAP_ESCAPE_DN]; - } - - if (!$charMap) { - $charMap = $charMaps[0]; - } - - // Remove any chars to ignore from the list - $ignore = (string) $ignore; - - for ($i = 0, $l = strlen($ignore); $i < $l; ++$i) { - unset($charMap[$ignore[$i]]); - } - - // Do the main replacement - $result = strtr($subject, $charMap); - - // Encode leading/trailing spaces if LDAP_ESCAPE_DN is passed - if ($flags & self::LDAP_ESCAPE_DN) { - if ($result[0] === ' ') { - $result = '\\20'.substr($result, 1); - } - - if ($result[strlen($result) - 1] === ' ') { - $result = substr($result, 0, -1).'\\20'; - } - } - - return $result; - } - - private function getCharmaps() - { - if (null !== $this->charmaps) { - return $this->charmaps; - } - - $charMaps = array( - self::LDAP_ESCAPE_FILTER => array('\\', '*', '(', ')', "\x00"), - self::LDAP_ESCAPE_DN => array('\\', ',', '=', '+', '<', '>', ';', '"', '#'), - ); - - $charMaps[0] = array(); - - for ($i = 0; $i < 256; ++$i) { - $charMaps[0][chr($i)] = sprintf('\\%02x', $i); - } - - for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_FILTER]); $i < $l; ++$i) { - $chr = $charMaps[self::LDAP_ESCAPE_FILTER][$i]; - unset($charMaps[self::LDAP_ESCAPE_FILTER][$i]); - $charMaps[self::LDAP_ESCAPE_FILTER][$chr] = $charMaps[0][$chr]; - } - - for ($i = 0, $l = count($charMaps[self::LDAP_ESCAPE_DN]); $i < $l; ++$i) { - $chr = $charMaps[self::LDAP_ESCAPE_DN][$i]; - unset($charMaps[self::LDAP_ESCAPE_DN][$i]); - $charMaps[self::LDAP_ESCAPE_DN][$chr] = $charMaps[0][$chr]; - } - - $this->charmaps = $charMaps; - - return $this->charmaps; - } } diff --git a/src/Symfony/Component/Ldap/Tests/LdapClientTest.php b/src/Symfony/Component/Ldap/Tests/LdapClientTest.php deleted file mode 100644 index 22a548c272..0000000000 --- a/src/Symfony/Component/Ldap/Tests/LdapClientTest.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Security\Core\Tests\Authentication\Provider; - -use Symfony\Component\Ldap\LdapClient; - -/** - * @requires extension ldap - */ -class LdapClientTest extends \PHPUnit_Framework_TestCase -{ - /** - * @dataProvider provideLdapEscapeValues - */ - public function testLdapEscape($subject, $ignore, $flags, $expected) - { - $ldap = new LdapClient(); - $this->assertSame($expected, $ldap->escape($subject, $ignore, $flags)); - } - - /** - * Provides values for the ldap_escape shim. These tests come from the official - * extension. - * - * @see https://github.com/php/php-src/blob/master/ext/ldap/tests/ldap_escape_dn.phpt - * @see https://github.com/php/php-src/blob/master/ext/ldap/tests/ldap_escape_all.phpt - * @see https://github.com/php/php-src/blob/master/ext/ldap/tests/ldap_escape_both.phpt - * @see https://github.com/php/php-src/blob/master/ext/ldap/tests/ldap_escape_filter.phpt - * @see https://github.com/php/php-src/blob/master/ext/ldap/tests/ldap_escape_ignore.phpt - * - * @return array - */ - public function provideLdapEscapeValues() - { - return array( - array('foo=bar(baz)*', null, LdapClient::LDAP_ESCAPE_DN, 'foo\3dbar(baz)*'), - array('foo=bar(baz)*', null, null, '\66\6f\6f\3d\62\61\72\28\62\61\7a\29\2a'), - array('foo=bar(baz)*', null, LdapClient::LDAP_ESCAPE_DN | LdapClient::LDAP_ESCAPE_FILTER, 'foo\3dbar\28baz\29\2a'), - array('foo=bar(baz)*', null, LdapClient::LDAP_ESCAPE_FILTER, 'foo=bar\28baz\29\2a'), - array('foo=bar(baz)*', 'ao', null, '\66oo\3d\62a\72\28\62a\7a\29\2a'), - ); - } -} diff --git a/src/Symfony/Component/Ldap/composer.json b/src/Symfony/Component/Ldap/composer.json index 612b7c83fe..21e4adea96 100644 --- a/src/Symfony/Component/Ldap/composer.json +++ b/src/Symfony/Component/Ldap/composer.json @@ -17,6 +17,7 @@ ], "require": { "php": ">=5.3.9", + "symfony/polyfill-php56": "~1.0", "ext-ldap": "*" }, "autoload": { diff --git a/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php b/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php index d2b031999c..c0c8fe0993 100644 --- a/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php +++ b/src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php @@ -34,10 +34,6 @@ class BCryptPasswordEncoder extends BasePasswordEncoder */ public function __construct($cost) { - if (!function_exists('password_hash')) { - throw new \RuntimeException('To use the BCrypt encoder, you need to upgrade to PHP 5.5 or install the "ircmaxell/password-compat" via Composer.'); - } - $cost = (int) $cost; if ($cost < 4 || $cost > 31) { throw new \InvalidArgumentException('Cost must be in the range of 4-31.'); diff --git a/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php b/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php index 1c9ada1e64..12126d8454 100644 --- a/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php +++ b/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php @@ -11,8 +11,6 @@ namespace Symfony\Component\Security\Core\Encoder; -use Symfony\Component\Security\Core\Util\StringUtils; - /** * BasePasswordEncoder is the base class for all password encoders. * @@ -83,7 +81,7 @@ abstract class BasePasswordEncoder implements PasswordEncoderInterface */ protected function comparePasswords($password1, $password2) { - return StringUtils::equals($password1, $password2); + return hash_equals($password1, $password2); } /** diff --git a/src/Symfony/Component/Security/Core/Encoder/Pbkdf2PasswordEncoder.php b/src/Symfony/Component/Security/Core/Encoder/Pbkdf2PasswordEncoder.php index 6f24c4f1e2..8422a4baae 100644 --- a/src/Symfony/Component/Security/Core/Encoder/Pbkdf2PasswordEncoder.php +++ b/src/Symfony/Component/Security/Core/Encoder/Pbkdf2PasswordEncoder.php @@ -64,11 +64,7 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm)); } - if (function_exists('hash_pbkdf2')) { - $digest = hash_pbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length, true); - } else { - $digest = $this->hashPbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length); - } + $digest = hash_pbkdf2($this->algorithm, $raw, $salt, $this->iterations, $this->length, true); return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest); } @@ -80,24 +76,4 @@ class Pbkdf2PasswordEncoder extends BasePasswordEncoder { return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt)); } - - private function hashPbkdf2($algorithm, $password, $salt, $iterations, $length = 0) - { - // Number of blocks needed to create the derived key - $blocks = ceil($length / strlen(hash($algorithm, null, true))); - $digest = ''; - - for ($i = 1; $i <= $blocks; ++$i) { - $ib = $block = hash_hmac($algorithm, $salt.pack('N', $i), $password, true); - - // Iterations - for ($j = 1; $j < $iterations; ++$j) { - $ib ^= ($block = hash_hmac($algorithm, $block, $password, true)); - } - - $digest .= $ib; - } - - return substr($digest, 0, $this->length); - } } diff --git a/src/Symfony/Component/Security/Core/Tests/Util/StringUtilsTest.php b/src/Symfony/Component/Security/Core/Tests/Util/StringUtilsTest.php index faeaf259f7..78d9b05a17 100644 --- a/src/Symfony/Component/Security/Core/Tests/Util/StringUtilsTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Util/StringUtilsTest.php @@ -15,6 +15,8 @@ use Symfony\Component\Security\Core\Util\StringUtils; /** * Data from PHP.net's hash_equals tests. + * + * @group legacy */ class StringUtilsTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Security/Core/Util/StringUtils.php b/src/Symfony/Component/Security/Core/Util/StringUtils.php index 343585c88c..5900812f92 100644 --- a/src/Symfony/Component/Security/Core/Util/StringUtils.php +++ b/src/Symfony/Component/Security/Core/Util/StringUtils.php @@ -11,10 +11,16 @@ namespace Symfony\Component\Security\Core\Util; +@trigger_error('The '.__NAMESPACE__.'\\StringUtils class is deprecated since version 2.8 and will be removed in 3.0. Use hash_equals() instead.', E_USER_DEPRECATED); + +use Symfony\Component\Polyfill\Util\Binary; + /** * String utility functions. * * @author Fabien Potencier + * + * @deprecated since 2.8, to be removed in 3.0. */ class StringUtils { @@ -47,25 +53,7 @@ class StringUtils $userInput = (string) $userInput; } - if (function_exists('hash_equals')) { - return hash_equals($knownString, $userInput); - } - - $knownLen = self::safeStrlen($knownString); - $userLen = self::safeStrlen($userInput); - - if ($userLen !== $knownLen) { - return false; - } - - $result = 0; - - for ($i = 0; $i < $knownLen; ++$i) { - $result |= (ord($knownString[$i]) ^ ord($userInput[$i])); - } - - // They are only identical strings if $result is exactly 0... - return 0 === $result; + return hash_equals($knownString, $userInput); } /** @@ -77,17 +65,6 @@ class StringUtils */ public static function safeStrlen($string) { - // Premature optimization - // Since this cannot be changed at runtime, we can cache it - static $funcExists = null; - if (null === $funcExists) { - $funcExists = function_exists('mb_strlen'); - } - - if ($funcExists) { - return mb_strlen($string, '8bit'); - } - - return strlen($string); + return Binary::strlen($string); } } diff --git a/src/Symfony/Component/Security/Core/composer.json b/src/Symfony/Component/Security/Core/composer.json index 31b4653967..c75d2d5fce 100644 --- a/src/Symfony/Component/Security/Core/composer.json +++ b/src/Symfony/Component/Security/Core/composer.json @@ -17,25 +17,25 @@ ], "require": { "php": ">=5.3.9", - "paragonie/random_compat": "~1.0" + "symfony/polyfill-php55": "~1.0", + "symfony/polyfill-php56": "~1.0", + "symfony/polyfill-util": "~1.0" }, "require-dev": { "symfony/event-dispatcher": "~2.1|~3.0.0", "symfony/expression-language": "~2.6|~3.0.0", "symfony/http-foundation": "~2.4|~3.0.0", + "symfony/ldap": "~2.8|~3.0.0", "symfony/translation": "~2.0,>=2.0.5|~3.0.0", "symfony/validator": "~2.5,>=2.5.5|~3.0.0", - "psr/log": "~1.0", - "ircmaxell/password-compat": "1.0.*", - "symfony/ldap": "~2.8|~3.0.0" + "psr/log": "~1.0" }, "suggest": { "symfony/event-dispatcher": "", "symfony/http-foundation": "", "symfony/validator": "For using the user password constraint", "symfony/expression-language": "For using the expression voter", - "symfony/ldap": "For using LDAP integration", - "ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5" + "symfony/ldap": "For using LDAP integration" }, "autoload": { "psr-4": { "Symfony\\Component\\Security\\Core\\": "" } diff --git a/src/Symfony/Component/Security/Csrf/CsrfTokenManager.php b/src/Symfony/Component/Security/Csrf/CsrfTokenManager.php index e1295029ac..cdda543cc0 100644 --- a/src/Symfony/Component/Security/Csrf/CsrfTokenManager.php +++ b/src/Symfony/Component/Security/Csrf/CsrfTokenManager.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Security\Csrf; -use Symfony\Component\Security\Core\Util\StringUtils; use Symfony\Component\Security\Csrf\TokenGenerator\UriSafeTokenGenerator; use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface; use Symfony\Component\Security\Csrf\TokenStorage\NativeSessionTokenStorage; @@ -92,6 +91,6 @@ class CsrfTokenManager implements CsrfTokenManagerInterface return false; } - return StringUtils::equals($this->storage->getToken($token->getId()), $token->getValue()); + return hash_equals($this->storage->getToken($token->getId()), $token->getValue()); } } diff --git a/src/Symfony/Component/Security/Csrf/composer.json b/src/Symfony/Component/Security/Csrf/composer.json index 2afebf913f..c8e2fae319 100644 --- a/src/Symfony/Component/Security/Csrf/composer.json +++ b/src/Symfony/Component/Security/Csrf/composer.json @@ -17,8 +17,8 @@ ], "require": { "php": ">=5.3.9", - "symfony/security-core": "~2.4|~3.0.0", - "paragonie/random_compat": "~1.0" + "symfony/polyfill-php56": "~1.0", + "symfony/security-core": "~2.4|~3.0.0" }, "require-dev": { "symfony/http-foundation": "~2.1|~3.0.0" diff --git a/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php b/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php index f6107ec406..a4437027d0 100644 --- a/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php +++ b/src/Symfony/Component/Security/Http/RememberMe/TokenBasedRememberMeServices.php @@ -17,7 +17,6 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\User\UserInterface; -use Symfony\Component\Security\Core\Util\StringUtils; /** * Concrete implementation of the RememberMeServicesInterface providing @@ -54,7 +53,7 @@ class TokenBasedRememberMeServices extends AbstractRememberMeServices throw new \RuntimeException(sprintf('The UserProviderInterface implementation must return an instance of UserInterface, but returned "%s".', get_class($user))); } - if (true !== StringUtils::equals($this->generateCookieHash($class, $username, $expires, $user->getPassword()), $hash)) { + if (true !== hash_equals($this->generateCookieHash($class, $username, $expires, $user->getPassword()), $hash)) { throw new AuthenticationException('The cookie\'s hash is invalid.'); } diff --git a/src/Symfony/Component/Security/Http/composer.json b/src/Symfony/Component/Security/Http/composer.json index 65978ee107..686a629e74 100644 --- a/src/Symfony/Component/Security/Http/composer.json +++ b/src/Symfony/Component/Security/Http/composer.json @@ -21,8 +21,9 @@ "symfony/event-dispatcher": "~2.1|~3.0.0", "symfony/http-foundation": "~2.4|~3.0.0", "symfony/http-kernel": "~2.4|~3.0.0", - "symfony/property-access": "~2.3|~3.0.0", - "paragonie/random_compat": "~1.0" + "symfony/polyfill-php56": "~1.0", + "symfony/polyfill-php70": "~1.0", + "symfony/property-access": "~2.3|~3.0.0" }, "require-dev": { "symfony/routing": "~2.2|~3.0.0", diff --git a/src/Symfony/Component/Security/composer.json b/src/Symfony/Component/Security/composer.json index 65a2eb0bc6..beb2f88c52 100644 --- a/src/Symfony/Component/Security/composer.json +++ b/src/Symfony/Component/Security/composer.json @@ -21,8 +21,11 @@ "symfony/event-dispatcher": "~2.2|~3.0.0", "symfony/http-foundation": "~2.1|~3.0.0", "symfony/http-kernel": "~2.4|~3.0.0", - "symfony/property-access": "~2.3|~3.0.0", - "paragonie/random_compat": "~1.0" + "symfony/polyfill-php55": "~1.0", + "symfony/polyfill-php56": "~1.0", + "symfony/polyfill-php70": "~1.0", + "symfony/polyfill-util": "~1.0", + "symfony/property-access": "~2.3|~3.0.0" }, "replace": { "symfony/security-core": "self.version", @@ -32,14 +35,13 @@ }, "require-dev": { "symfony/finder": "~2.3|~3.0.0", - "symfony/intl": "~2.3|~3.0.0", + "symfony/polyfill-intl-icu": "~1.0", "symfony/routing": "~2.2|~3.0.0", "symfony/translation": "~2.0,>=2.0.5|~3.0.0", "symfony/validator": "~2.5,>=2.5.5|~3.0.0", "doctrine/common": "~2.2", "doctrine/dbal": "~2.2", "psr/log": "~1.0", - "ircmaxell/password-compat": "~1.0", "symfony/expression-language": "~2.6|~3.0.0", "symfony/ldap": "~2.8|~3.0.0" }, @@ -50,7 +52,6 @@ "symfony/validator": "For using the user password constraint", "symfony/routing": "For using the HttpUtils class to create sub-requests, redirect the user, and match URLs", "symfony/expression-language": "For using the expression voter", - "ircmaxell/password-compat": "For using the BCrypt password encoder in PHP <5.5", "symfony/ldap": "For using the LDAP user and authentication providers" }, "autoload": { diff --git a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php index 5f5f2899f5..d4070c2304 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonDecode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonDecode.php @@ -108,7 +108,7 @@ class JsonDecode implements DecoderInterface } if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) { - throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage()); + throw new UnexpectedValueException(json_last_error_message()); } return $decodedData; diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php index 3a6b2fdbbb..aa7d64530e 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncode.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncode.php @@ -56,7 +56,7 @@ class JsonEncode implements EncoderInterface $encodedJson = json_encode($data, $context['json_encode_options']); if (JSON_ERROR_NONE !== $this->lastError = json_last_error()) { - throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage()); + throw new UnexpectedValueException(json_last_error_message()); } return $encodedJson; diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php index 284f579a04..159d435836 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php @@ -100,26 +100,13 @@ class JsonEncoder implements EncoderInterface, DecoderInterface * Resolves json_last_error message. * * @return string + * + * @deprecated since 2.8, to be removed in 3.0. Use json_last_error_msg() instead. */ public static function getLastErrorMessage() { - if (function_exists('json_last_error_msg')) { - return json_last_error_msg(); - } + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use json_last_error_msg() instead.', E_USER_DEPRECATED); - switch (json_last_error()) { - case JSON_ERROR_DEPTH: - return 'Maximum stack depth exceeded'; - case JSON_ERROR_STATE_MISMATCH: - return 'Underflow or the modes mismatch'; - case JSON_ERROR_CTRL_CHAR: - return 'Unexpected control character found'; - case JSON_ERROR_SYNTAX: - return 'Syntax error, malformed JSON'; - case JSON_ERROR_UTF8: - return 'Malformed UTF-8 characters, possibly incorrectly encoded'; - default: - return 'Unknown error'; - } + return json_last_error_msg(); } } diff --git a/src/Symfony/Component/Serializer/composer.json b/src/Symfony/Component/Serializer/composer.json index 58783fff10..8872215af0 100644 --- a/src/Symfony/Component/Serializer/composer.json +++ b/src/Symfony/Component/Serializer/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-php54": "~1.0" }, "require-dev": { "symfony/yaml": "~2.0,>=2.0.5|~3.0.0", diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index 253796c051..042dc6c8e9 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -330,6 +330,9 @@ class PhpEngine implements EngineInterface, \ArrayAccess */ public function setCharset($charset) { + if ('UTF8' === $charset = strtoupper($charset)) { + $charset = 'UTF-8'; // iconv on Windows requires "UTF-8" instead of "UTF8" + } $this->charset = $charset; foreach ($this->helpers as $helper) { @@ -448,7 +451,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess */ function ($value) use ($that) { if ('UTF-8' != $that->getCharset()) { - $value = $that->convertEncoding($value, 'UTF-8', $that->getCharset()); + $value = iconv($that->getCharset(), 'UTF-8', $value); } $callback = function ($matches) use ($that) { @@ -460,7 +463,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess } // \uHHHH - $char = $that->convertEncoding($char, 'UTF-16BE', 'UTF-8'); + $char = iconv('UTF-8', 'UTF-16BE', $char); return '\\u'.substr('0000'.bin2hex($char), -4); }; @@ -470,7 +473,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess } if ('UTF-8' != $that->getCharset()) { - $value = $that->convertEncoding($value, $that->getCharset(), 'UTF-8'); + $value = iconv('UTF-8', $that->getCharset(), $value); } return $value; @@ -489,17 +492,13 @@ class PhpEngine implements EngineInterface, \ArrayAccess * * @return string The string with the new encoding * - * @throws \RuntimeException if no suitable encoding function is found (iconv or mbstring) + * @deprecated since 2.8, to be removed in 3.0. Use iconv() instead. */ public function convertEncoding($string, $to, $from) { - if (function_exists('mb_convert_encoding')) { - return mb_convert_encoding($string, $to, $from); - } elseif (function_exists('iconv')) { - return iconv($from, $to, $string); - } + @trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use iconv() instead.', E_USER_DEPRECATED); - throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); + return iconv($from, $to, $string); } /** diff --git a/src/Symfony/Component/Translation/DataCollector/TranslationDataCollector.php b/src/Symfony/Component/Translation/DataCollector/TranslationDataCollector.php index 090f16d7ec..cb59d0a7e7 100644 --- a/src/Symfony/Component/Translation/DataCollector/TranslationDataCollector.php +++ b/src/Symfony/Component/Translation/DataCollector/TranslationDataCollector.php @@ -137,7 +137,7 @@ class TranslationDataCollector extends DataCollector implements LateDataCollecto { $string = trim(preg_replace('/\s+/', ' ', $string)); - if (function_exists('mb_strlen') && false !== $encoding = mb_detect_encoding($string)) { + if (false !== $encoding = mb_detect_encoding($string, null, true)) { if (mb_strlen($string, $encoding) > $length) { return mb_substr($string, 0, $length - 3, $encoding).'...'; } diff --git a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php index 3f95b42b00..bdca11099d 100644 --- a/src/Symfony/Component/Translation/Loader/XliffFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/XliffFileLoader.php @@ -153,15 +153,7 @@ class XliffFileLoader implements LoaderInterface private function utf8ToCharset($content, $encoding = null) { if ('UTF-8' !== $encoding && !empty($encoding)) { - if (function_exists('mb_convert_encoding')) { - return mb_convert_encoding($content, $encoding, 'UTF-8'); - } - - if (function_exists('iconv')) { - return iconv('UTF-8', $encoding, $content); - } - - throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); + return mb_convert_encoding($content, $encoding, 'UTF-8'); } return $content; diff --git a/src/Symfony/Component/Translation/Tests/Dumper/IcuResFileDumperTest.php b/src/Symfony/Component/Translation/Tests/Dumper/IcuResFileDumperTest.php index 117218aec7..618783c04c 100644 --- a/src/Symfony/Component/Translation/Tests/Dumper/IcuResFileDumperTest.php +++ b/src/Symfony/Component/Translation/Tests/Dumper/IcuResFileDumperTest.php @@ -16,9 +16,6 @@ use Symfony\Component\Translation\Dumper\IcuResFileDumper; class IcuResFileDumperTest extends \PHPUnit_Framework_TestCase { - /** - * @requires extension mbstring - */ public function testFormatCatalogue() { $catalogue = new MessageCatalogue('en'); diff --git a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php index 8f8224a5cb..01e64c3973 100644 --- a/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php +++ b/src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php @@ -59,9 +59,6 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array('foo' => 'bar', 'extra' => 'extra', 'key' => '', 'test' => 'with'), $catalogue->all('domain1')); } - /** - * @requires extension mbstring - */ public function testEncoding() { $loader = new XliffFileLoader(); diff --git a/src/Symfony/Component/Translation/composer.json b/src/Symfony/Component/Translation/composer.json index 71a7450002..07f2b9d10f 100644 --- a/src/Symfony/Component/Translation/composer.json +++ b/src/Symfony/Component/Translation/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { "symfony/config": "~2.8", diff --git a/src/Symfony/Component/Validator/Constraints/LengthValidator.php b/src/Symfony/Component/Validator/Constraints/LengthValidator.php index 7ef9f269d0..97374953e1 100644 --- a/src/Symfony/Component/Validator/Constraints/LengthValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LengthValidator.php @@ -42,29 +42,11 @@ class LengthValidator extends ConstraintValidator $invalidCharset = false; if ('UTF8' === $charset = strtoupper($constraint->charset)) { - $charset = 'UTF-8'; + $charset = 'UTF-8'; // iconv on Windows requires "UTF-8" instead of "UTF8" } - if ('UTF-8' === $charset) { - if (!preg_match('//u', $stringValue)) { - $invalidCharset = true; - } elseif (function_exists('utf8_decode')) { - $length = strlen(utf8_decode($stringValue)); - } else { - preg_replace('/./u', '', $stringValue, -1, $length); - } - } elseif (function_exists('mb_strlen')) { - if (@mb_check_encoding($stringValue, $constraint->charset)) { - $length = mb_strlen($stringValue, $constraint->charset); - } else { - $invalidCharset = true; - } - } elseif (function_exists('iconv_strlen')) { - $length = @iconv_strlen($stringValue, $constraint->charset); - $invalidCharset = false === $length; - } else { - $length = strlen($stringValue); - } + $length = @iconv_strlen($stringValue, $charset); + $invalidCharset = false === $length; if ($invalidCharset) { if ($this->context instanceof ExecutionContextInterface) { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php index b94fdae95c..cd501819d9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php @@ -87,9 +87,6 @@ class LengthValidatorTest extends AbstractConstraintValidatorTest ); } - /** - * @requires extension mbstring - */ public function getOneCharset() { return array( diff --git a/src/Symfony/Component/VarDumper/Caster/CutStub.php b/src/Symfony/Component/VarDumper/Caster/CutStub.php index 244829c5ba..8781f5cf3c 100644 --- a/src/Symfony/Component/VarDumper/Caster/CutStub.php +++ b/src/Symfony/Component/VarDumper/Caster/CutStub.php @@ -48,7 +48,7 @@ class CutStub extends Stub case 'string': $this->type = self::TYPE_STRING; $this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY; - $this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1); + $this->cut = self::STRING_BINARY === $this->class ? strlen($value) : mb_strlen($value, 'UTF-8'); $this->value = ''; break; } diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index a63af92acd..9e298c429c 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -185,9 +185,6 @@ abstract class AbstractCloner implements ClonerInterface $this->filter = $filter; $this->prevErrorHandler = set_error_handler(array($this, 'handleError')); try { - if (!function_exists('iconv')) { - $this->maxString = -1; - } $data = $this->doClone($var); } catch (\Exception $e) { } diff --git a/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php b/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php index cc4b2ef498..f8b9c10777 100644 --- a/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php @@ -30,7 +30,6 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface protected $indentPad = ' '; private $charset; - private $charsetConverter; /** * @param callable|resource|string|null $output A line dumper callable, an opened stream or an output path, defaults to static::$defaultOutput. @@ -82,29 +81,11 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface public function setCharset($charset) { $prev = $this->charset; - $this->charsetConverter = 'fallback'; $charset = strtoupper($charset); $charset = null === $charset || 'UTF-8' === $charset || 'UTF8' === $charset ? 'CP1252' : $charset; - $supported = true; - set_error_handler(function () use (&$supported) {$supported = false;}); - - if (function_exists('mb_encoding_aliases') && mb_encoding_aliases($charset)) { - $this->charset = $charset; - $this->charsetConverter = 'mbstring'; - } elseif (function_exists('iconv')) { - $supported = true; - iconv($charset, 'UTF-8', ''); - if ($supported) { - $this->charset = $charset; - $this->charsetConverter = 'iconv'; - } - } - if ('fallback' === $this->charsetConverter) { - $this->charset = 'ISO-8859-1'; - } - restore_error_handler(); + $this->charset = $charset; return $prev; } @@ -183,40 +164,13 @@ abstract class AbstractDumper implements DataDumperInterface, DumperInterface */ protected function utf8Encode($s) { - if ('mbstring' === $this->charsetConverter) { - return mb_convert_encoding($s, 'UTF-8', mb_check_encoding($s, $this->charset) ? $this->charset : '8bit'); + if (false !== $c = @iconv($this->charset, 'UTF-8', $s)) { + return $c; } - if ('iconv' === $this->charsetConverter) { - $valid = true; - set_error_handler(function () use (&$valid) {$valid = false;}); - $c = iconv($this->charset, 'UTF-8', $s); - restore_error_handler(); - if ($valid) { - return $c; - } + if ('CP1252' !== $this->charset && false !== $c = @iconv('CP1252', 'UTF-8', $s)) { + return $c; } - $s .= $s; - $len = strlen($s); - - for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) { - switch (true) { - case $s[$i] < "\x80": - $s[$j] = $s[$i]; - break; - - case $s[$i] < "\xC0": - $s[$j] = "\xC2"; - $s[++$j] = $s[$i]; - break; - - default: - $s[$j] = "\xC3"; - $s[++$j] = chr(ord($s[$i]) - 64); - break; - } - } - - return substr($s, 0, $j); + return iconv('CP850', 'UTF-8', $s); } } diff --git a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php index 37e4110abe..bca2abcb3d 100644 --- a/src/Symfony/Component/VarDumper/Dumper/CliDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/CliDumper.php @@ -91,9 +91,7 @@ class CliDumper extends AbstractDumper */ public function setMaxStringWidth($maxStringWidth) { - if (function_exists('iconv')) { - $this->maxStringWidth = (int) $maxStringWidth; - } + $this->maxStringWidth = (int) $maxStringWidth; } /** @@ -171,7 +169,7 @@ class CliDumper extends AbstractDumper $this->dumpLine($cursor->depth, true); } else { $attr = array( - 'length' => 0 <= $cut && function_exists('iconv_strlen') ? iconv_strlen($str, 'UTF-8') + $cut : 0, + 'length' => 0 <= $cut ? iconv_strlen($str, 'UTF-8') + $cut : 0, 'binary' => $bin, ); $str = explode("\n", $str); diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 0ae752166a..28af8e4cb2 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -442,30 +442,7 @@ EOHTML; } $this->lastDepth = $depth; - // Replaces non-ASCII UTF-8 chars by numeric HTML entities - $this->line = preg_replace_callback( - '/[\x80-\xFF]+/', - function ($m) { - $m = unpack('C*', $m[0]); - $i = 1; - $entities = ''; - - while (isset($m[$i])) { - if (0xF0 <= $m[$i]) { - $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; - } elseif (0xE0 <= $m[$i]) { - $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80; - } else { - $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80; - } - - $entities .= '&#'.$c.';'; - } - - return $entities; - }, - $this->line - ); + $this->line = mb_convert_encoding($this->line, 'HTML-ENTITIES', 'UTF-8'); if (-1 === $depth) { AbstractDumper::dumpLine(0); diff --git a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php index 14e5eb9d6d..56d286acb1 100644 --- a/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/HtmlDumperTest.php @@ -52,7 +52,7 @@ class HtmlDumperTest extends \PHPUnit_Framework_TestCase $closure54 = <<class: "Symfony\Component\VarDumper\Tests\HtmlDumperTest" - this: HtmlDumperTest {{$r} …} + this: HtmlDumperTest {{$r} &%s;} EOTXT; } @@ -68,8 +68,8 @@ EOTXT; 4 => INF 5 => -INF 6 => {$intMax} - "str" => "déjà\\n" - 7 => b"é\\x00" + "str" => "d&%s;j&%s;\\n" + 7 => b"&%s;\\x00" "[]" => [] "res" => stream resource @{$res} wrapper_type: "plainfile" @@ -109,7 +109,7 @@ EOTXT; "snobj" => &3 {#%d} "snobj2" => {#%d} "file" => "{$var['file']}" - b"bin-key-é" => "" + b"bin-key-&%s;" => "" ] @@ -120,9 +120,6 @@ EOTXT ); } - /** - * @requires extension mbstring - */ public function testCharset() { $var = mb_convert_encoding('Словарь', 'CP1251', 'UTF-8'); diff --git a/src/Symfony/Component/VarDumper/composer.json b/src/Symfony/Component/VarDumper/composer.json index 8bffc384cd..51c667cbf0 100644 --- a/src/Symfony/Component/VarDumper/composer.json +++ b/src/Symfony/Component/VarDumper/composer.json @@ -16,7 +16,8 @@ } ], "require": { - "php": ">=5.3.9" + "php": ">=5.3.9", + "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { "twig/twig": "~1.20|~2.0" diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index e3470aa5f5..ca0b603abf 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -52,7 +52,7 @@ class Inline return ''; } - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { + if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 04f2237be2..a6c0f291c2 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -62,7 +62,7 @@ class Parser $value = $this->cleanup($value); $this->lines = explode("\n", $value); - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { + if (2 /* MB_OVERLOAD_STRING */ & (int) ini_get('mbstring.func_overload')) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('UTF-8'); }