1<?php 2 3/** 4 * @see https://github.com/laminas/laminas-stdlib for the canonical source repository 5 * @copyright https://github.com/laminas/laminas-stdlib/blob/master/COPYRIGHT.md 6 * @license https://github.com/laminas/laminas-stdlib/blob/master/LICENSE.md New BSD License 7 */ 8 9namespace Laminas\Stdlib\StringWrapper; 10 11use Laminas\Stdlib\Exception; 12 13class Intl extends AbstractStringWrapper 14{ 15 /** 16 * List of supported character sets (upper case) 17 * 18 * @var string[] 19 */ 20 protected static $encodings = ['UTF-8']; 21 22 /** 23 * Get a list of supported character encodings 24 * 25 * @return string[] 26 */ 27 public static function getSupportedEncodings() 28 { 29 return static::$encodings; 30 } 31 32 /** 33 * Constructor 34 * 35 * @throws Exception\ExtensionNotLoadedException 36 */ 37 public function __construct() 38 { 39 if (! extension_loaded('intl')) { 40 throw new Exception\ExtensionNotLoadedException( 41 'PHP extension "intl" is required for this wrapper' 42 ); 43 } 44 } 45 46 /** 47 * Returns the length of the given string 48 * 49 * @param string $str 50 * @return int|false 51 */ 52 public function strlen($str) 53 { 54 return grapheme_strlen($str); 55 } 56 57 /** 58 * Returns the portion of string specified by the start and length parameters 59 * 60 * @param string $str 61 * @param int $offset 62 * @param int|null $length 63 * @return string|false 64 */ 65 public function substr($str, $offset = 0, $length = null) 66 { 67 // Due fix of PHP #62759 The third argument returns an empty string if is 0 or null. 68 if ($length !== null) { 69 return grapheme_substr($str, $offset, $length); 70 } 71 72 return grapheme_substr($str, $offset); 73 } 74 75 /** 76 * Find the position of the first occurrence of a substring in a string 77 * 78 * @param string $haystack 79 * @param string $needle 80 * @param int $offset 81 * @return int|false 82 */ 83 public function strpos($haystack, $needle, $offset = 0) 84 { 85 return grapheme_strpos($haystack, $needle, $offset); 86 } 87} 88