You are here

public function Escaper::__construct in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-escaper/src/Escaper.php \Zend\Escaper\Escaper::__construct()

Constructor: Single parameter allows setting of global encoding for use by the current object. If PHP 5.4 is detected, additional ENT_SUBSTITUTE flag is set for htmlspecialchars() calls.

Parameters

string $encoding:

Throws

Exception\InvalidArgumentException

File

vendor/zendframework/zend-escaper/src/Escaper.php, line 98

Class

Escaper
Context specific methods for use in secure output escaping

Namespace

Zend\Escaper

Code

public function __construct($encoding = null) {
  if ($encoding !== null) {
    $encoding = (string) $encoding;
    if ($encoding === '') {
      throw new Exception\InvalidArgumentException(get_class($this) . ' constructor parameter does not allow a blank value');
    }
    $encoding = strtolower($encoding);
    if (!in_array($encoding, $this->supportedEncodings)) {
      throw new Exception\InvalidArgumentException('Value of \'' . $encoding . '\' passed to ' . get_class($this) . ' constructor parameter is invalid. Provide an encoding supported by htmlspecialchars()');
    }
    $this->encoding = $encoding;
  }
  if (defined('ENT_SUBSTITUTE')) {
    $this->htmlSpecialCharsFlags |= ENT_SUBSTITUTE;
  }

  // set matcher callbacks
  $this->htmlAttrMatcher = array(
    $this,
    'htmlAttrMatcher',
  );
  $this->jsMatcher = array(
    $this,
    'jsMatcher',
  );
  $this->cssMatcher = array(
    $this,
    'cssMatcher',
  );
}