PHP Class lithium\g11n\Multibyte

Over time - as the importance of multibyte encoding support grew - a variety of extensions appeared. While each achieves its goal somewhat differently and might be preferred over the other, they still all do that one thing. What can a framework provide, those extensions aren't? It can provide abstractions that allow portable code. While this might not be a requirement for application code, it's a definite must for the framework's core code. As previously mentioned extensions appeared in a semi-evolutionary way. This leaves us with the situation where extensions are heterogeneously spread out over environments. There certainly is no clear winner and we're left with the situation of "supporting them all". Technically this class does very little in terms of abstraction. Its main purpose is to allow adapting to changing environments: virtually creating something you can rely on, something that's always there while it actually is there only in one way or the other. And - yes - some convenience methods are also on board.
Inheritance: extends lithium\core\Adaptable
ファイルを表示 Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Property Type Description
$_adapters Libraries::locate()-compatible path to adapters for this class.
$_configurations array Contains adapter configurations for Multibyte adapters.

Public Methods

Method Description
is ( string $string, array $options = [] ) : boolean Checks if a given string is UTF-8 encoded and is valid UTF-8.
strlen ( string $string, array $options = [] ) : integer Gets the string length. Multibyte enabled version of strlen().
strpos ( string $haystack, string $needle, integer $offset, array $options = [] ) : integer Finds the position of the _first_ occurrence of a string within a string.
strrpos ( string $haystack, string $needle, array $options = [] ) : integer Finds the position of the _last_ occurrence of a string within a string.
substr ( string $string, integer $start, integer $length = null, array $options = [] ) : string Returns the portion of string specified by the start and length parameters.

Method Details

is() public static method

In _quick_ mode it will check only for non ASCII characters being used indicating any multibyte encoding. Don't use quick mode for integrity validation of UTF-8 encoded strings. Meaning of RegExp: '[\x09\x0A\x0D\x20-\x7E]'; // ASCII '|[\xC2-\xDF][\x80-\xBF]'; // non-overlong 2-byte '|\xE0[\xA0-\xBF][\x80-\xBF]'; // excluding overlongs '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'; // straight 3-byte '|\xED[\x80-\x9F][\x80-\xBF]'; // excluding surrogates '|\xF0[\x90-\xBF][\x80-\xBF]{2}'; // planes 1-3 '|[\xF1-\xF3][\x80-\xBF]{3}'; // planes 4-15 '|\xF4[\x80-\x8F][\x80-\xBF]{2}'; // plane 16
public static is ( string $string, array $options = [] ) : boolean
$string string The string to analyze.
$options array Allows to toggle mode via the `'quick'` option, defaults to `false`.
return boolean Returns `true` if the string is UTF-8.

strlen() public static method

Gets the string length. Multibyte enabled version of strlen().
public static strlen ( string $string, array $options = [] ) : integer
$string string The string being measured for length.
$options array Allows for selecting the adapter to use via the `name` options. Will use the `'default'` adapter by default.
return integer The length of the string on success.

strpos() public static method

Multibyte enabled version of strpos(). Not all adapters must support interpreting - thus applying - passed numeric values as ordinal values of a character.
public static strpos ( string $haystack, string $needle, integer $offset, array $options = [] ) : integer
$haystack string The string being checked.
$needle string The string to find in the haystack.
$offset integer If specified, search will start this number of characters counted from the beginning of the string. The offset cannot be negative.
$options array Allows for selecting the adapter to use via the `name` options. Will use the `'default'` adapter by default.
return integer Returns the numeric position of the first occurrence of the needle in the haystack string. If needle is not found, it returns `false`.

strrpos() public static method

Multibyte enabled version of strrpos(). Not all adapters must support interpreting - thus applying - passed numeric values as ordinal values of a character. The Iconv adapter doesn't support an offset as strpos() does - this constitutes the lowest common denominator here.
public static strrpos ( string $haystack, string $needle, array $options = [] ) : integer
$haystack string The string being checked.
$needle string The string to find in the haystack.
$options array Allows for selecting the adapter to use via the `name` options. Will use the `'default'` adapter by default.
return integer Returns the numeric position of the last occurrence of the needle in the haystack string. If needle is not found, it returns `false`.

substr() public static method

Multibyte enabled version of substr().
public static substr ( string $string, integer $start, integer $length = null, array $options = [] ) : string
$string string The string to extract the substring from.
$start integer Position of first character in string (offset).
$length integer Maximum numbers of characters to use from string.
$options array Allows for selecting the adapter to use via the `name` options. Will use the `'default'` adapter by default.
return string The substring extracted from given string.

Property Details

$_adapters protected_oe static_oe property

Libraries::locate()-compatible path to adapters for this class.
See also: lithium\core\Libraries::locate()
protected static $_adapters

$_configurations protected_oe static_oe property

Contains adapter configurations for Multibyte adapters.
protected static array $_configurations
return array