class Native in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-stdlib/src/StringWrapper/Native.php \Zend\Stdlib\StringWrapper\Native
Hierarchy
- class \Zend\Stdlib\StringWrapper\AbstractStringWrapper implements StringWrapperInterface
- class \Zend\Stdlib\StringWrapper\Native
Expanded class hierarchy of Native
File
- vendor/
zendframework/ zend-stdlib/ src/ StringWrapper/ Native.php, line 15
Namespace
Zend\Stdlib\StringWrapperView source
class Native extends AbstractStringWrapper {
/**
* The character encoding working on
* (overwritten to change defaut encoding)
*
* @var string
*/
protected $encoding = 'ASCII';
/**
* Check if the given character encoding is supported by this wrapper
* and the character encoding to convert to is also supported.
*
* @param string $encoding
* @param string|null $convertEncoding
* @return bool
*/
public static function isSupported($encoding, $convertEncoding = null) {
$encodingUpper = strtoupper($encoding);
$supportedEncodings = static::getSupportedEncodings();
if (!in_array($encodingUpper, $supportedEncodings)) {
return false;
}
// This adapter doesn't support to convert between encodings
if ($convertEncoding !== null && $encodingUpper !== strtoupper($convertEncoding)) {
return false;
}
return true;
}
/**
* Get a list of supported character encodings
*
* @return string[]
*/
public static function getSupportedEncodings() {
return StringUtils::getSingleByteEncodings();
}
/**
* Set character encoding working with and convert to
*
* @param string $encoding The character encoding to work with
* @param string|null $convertEncoding The character encoding to convert to
* @return StringWrapperInterface
*/
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;
}
/**
* Returns the length of the given string
*
* @param string $str
* @return int|false
*/
public function strlen($str) {
return strlen($str);
}
/**
* Returns the portion of string specified by the start and length parameters
*
* @param string $str
* @param int $offset
* @param int|null $length
* @return string|false
*/
public function substr($str, $offset = 0, $length = null) {
return substr($str, $offset, $length);
}
/**
* Find the position of the first occurrence of a substring in a string
*
* @param string $haystack
* @param string $needle
* @param int $offset
* @return int|false
*/
public function strpos($haystack, $needle, $offset = 0) {
return strpos($haystack, $needle, $offset);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractStringWrapper:: |
protected | property | An optionally character encoding to convert to | |
AbstractStringWrapper:: |
public | function |
Convert a string from defined character encoding to the defined convert encoding Overrides StringWrapperInterface:: |
2 |
AbstractStringWrapper:: |
public | function |
Get the defined character encoding to convert to Overrides StringWrapperInterface:: |
|
AbstractStringWrapper:: |
public | function |
Get the defined character encoding to work with Overrides StringWrapperInterface:: |
|
AbstractStringWrapper:: |
public | function |
Pad a string to a certain length with another string Overrides StringWrapperInterface:: |
|
AbstractStringWrapper:: |
public | function |
Wraps a string to a given number of characters Overrides StringWrapperInterface:: |
|
Native:: |
protected | property |
The character encoding working on
(overwritten to change defaut encoding) Overrides AbstractStringWrapper:: |
|
Native:: |
public static | function |
Get a list of supported character encodings Overrides StringWrapperInterface:: |
|
Native:: |
public static | function |
Check if the given character encoding is supported by this wrapper
and the character encoding to convert to is also supported. Overrides AbstractStringWrapper:: |
|
Native:: |
public | function |
Set character encoding working with and convert to Overrides AbstractStringWrapper:: |
|
Native:: |
public | function |
Returns the length of the given string Overrides StringWrapperInterface:: |
|
Native:: |
public | function |
Find the position of the first occurrence of a substring in a string Overrides StringWrapperInterface:: |
|
Native:: |
public | function |
Returns the portion of string specified by the start and length parameters Overrides StringWrapperInterface:: |