mbstring no longer required for Ratchet

This commit is contained in:
Chris Boden 2012-07-12 15:41:30 -04:00
parent 87bac1a0d3
commit 59725ebc2d
3 changed files with 14 additions and 2 deletions

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');
} }