You are here

public function Native::setEncoding in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-stdlib/src/StringWrapper/Native.php \Zend\Stdlib\StringWrapper\Native::setEncoding()

Set character encoding working with and convert to

Parameters

string $encoding The character encoding to work with:

string|null $convertEncoding The character encoding to convert to:

Return value

StringWrapperInterface

Overrides AbstractStringWrapper::setEncoding

File

vendor/zendframework/zend-stdlib/src/StringWrapper/Native.php, line 67

Class

Native

Namespace

Zend\Stdlib\StringWrapper

Code

public function setEncoding($encoding, $convertEncoding = null) {
  $supportedEncodings = static::getSupportedEncodings();
  $encodingUpper = strtoupper($encoding);
  if (!in_array($encodingUpper, $supportedEncodings)) {
    throw new Exception\InvalidArgumentException('Wrapper doesn\'t support character encoding "' . $encoding . '"');
  }
  if ($encodingUpper !== strtoupper($convertEncoding)) {
    $this->convertEncoding = $encodingUpper;
  }
  if ($convertEncoding !== null) {
    if ($encodingUpper !== strtoupper($convertEncoding)) {
      throw new Exception\InvalidArgumentException('Wrapper doesn\'t support to convert between character encodings');
    }
    $this->convertEncoding = $encodingUpper;
  }
  else {
    $this->convertEncoding = null;
  }
  $this->encoding = $encodingUpper;
  return $this;
}