mbstring no longer required for Ratchet

This commit is contained in:
Chris Boden 2012-07-12 15:41:30 -04:00
parent f8a9eb56b5
commit 6d55e18dec
6 changed files with 22 additions and 13 deletions

View File

@ -12,6 +12,7 @@ CHANGELOG
* Ratchet passes every non-binary message AB test * Ratchet passes every non-binary message AB test
* Ratchet now relies on all stable dependancies * Ratchet now relies on all stable dependancies
* mbstring no longer required (but recommended if compliance is important to you)
* 0.1.4 (2012-06-17) * 0.1.4 (2012-06-17)

View File

@ -26,9 +26,11 @@
} }
, "require": { , "require": {
"php": ">=5.3.2" "php": ">=5.3.2"
, "ext-mbstring": "*" , "react/socket": "0.1.*"
, "guzzle/guzzle": "2.5.*" , "guzzle/guzzle": "2.5.*"
, "symfony/http-foundation": "2.1.*" , "symfony/http-foundation": "2.1.*"
, "react/socket": "0.1.*" }
, "require-dev": {
"react/socket": "0.1.*"
} }
} }

12
composer.lock generated
View File

@ -1,5 +1,5 @@
{ {
"hash": "66c73c46e4da8a18fdedf5ec2a9e5da5", "hash": "c2963a15ac8c0b7ffee78188dff24cd1",
"packages": [ "packages": [
{ {
"package": "evenement/evenement", "package": "evenement/evenement",
@ -23,12 +23,6 @@
"package": "react/stream", "package": "react/stream",
"version": "v0.1.0" "version": "v0.1.0"
}, },
{
"package": "symfony/event-dispatcher",
"version": "dev-master",
"alias-pretty-version": "2.1.x-dev",
"alias-version": "2.1.9999999.9999999-dev"
},
{ {
"package": "symfony/event-dispatcher", "package": "symfony/event-dispatcher",
"version": "dev-master", "version": "dev-master",
@ -44,8 +38,8 @@
{ {
"package": "symfony/http-foundation", "package": "symfony/http-foundation",
"version": "dev-master", "version": "dev-master",
"source-reference": "1a450955d5c487d85a7aaae4d8e306316c2a2f79", "source-reference": "3399f6f068cd41f1b42140699db1f1e6d3bcb361",
"commit-date": "1341951444" "commit-date": "1342107786"
} }
], ],
"packages-dev": null, "packages-dev": null,

View File

@ -53,9 +53,17 @@ class RFC6455 implements VersionInterface {
*/ */
private $closeCodes = array(); private $closeCodes = array();
/**
* Lookup if mbstring is available
* @var bool
*/
private $hasMbString = false;
public function __construct() { public function __construct() {
$this->_verifier = new HandshakeVerifier; $this->_verifier = new HandshakeVerifier;
$this->setCloseCodes(); $this->setCloseCodes();
$this->hasMbString = extension_loaded('mbstring');
} }
/** /**
@ -292,7 +300,7 @@ class RFC6455 implements VersionInterface {
* @return bool * @return bool
*/ */
function isUtf8($str) { function isUtf8($str) {
if (false === mb_check_encoding($str, 'UTF-8')) { if ($this->hasMbString && false === mb_check_encoding($str, 'UTF-8')) {
return false; return false;
} }

View File

@ -231,7 +231,7 @@ class Frame implements FrameInterface {
throw new \InvalidArgumentException("Masking key must be " . static::MASK_LENGTH ." characters"); throw new \InvalidArgumentException("Masking key must be " . static::MASK_LENGTH ." characters");
} }
if (!mb_check_encoding($maskingKey, 'US-ASCII')) { if (extension_loaded('mbstring') && true !== mb_check_encoding($maskingKey, 'US-ASCII')) {
throw new \InvalidArgumentException("Masking key MUST be ASCII"); throw new \InvalidArgumentException("Masking key MUST be ASCII");
} }

View File

@ -59,6 +59,10 @@ class HandshakeVerifier {
return false; return false;
} }
if (!extension_loaded('mbstring')) {
return true;
}
return mb_check_encoding($val, 'US-ASCII'); return mb_check_encoding($val, 'US-ASCII');
} }