You are here

public function AbstractStringWrapper::setEncoding in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php \Zend\Stdlib\StringWrapper\AbstractStringWrapper::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 StringWrapperInterface::setEncoding

1 method overrides AbstractStringWrapper::setEncoding()
Native::setEncoding in vendor/zendframework/zend-stdlib/src/StringWrapper/Native.php
Set character encoding working with and convert to

File

vendor/zendframework/zend-stdlib/src/StringWrapper/AbstractStringWrapper.php, line 59

Class

AbstractStringWrapper

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 ($convertEncoding !== null) {
    $convertEncodingUpper = strtoupper($convertEncoding);
    if (!in_array($convertEncodingUpper, $supportedEncodings)) {
      throw new Exception\InvalidArgumentException('Wrapper doesn\'t support character encoding "' . $convertEncoding . '"');
    }
    $this->convertEncoding = $convertEncodingUpper;
  }
  else {
    $this->convertEncoding = null;
  }
  $this->encoding = $encodingUpper;
  return $this;
}