Intl.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Stdlib\StringWrapper;
  10. use Zend\Stdlib\Exception;
  11. class Intl extends AbstractStringWrapper
  12. {
  13. /**
  14. * List of supported character sets (upper case)
  15. *
  16. * @var string[]
  17. */
  18. protected static $encodings = array('UTF-8');
  19. /**
  20. * Get a list of supported character encodings
  21. *
  22. * @return string[]
  23. */
  24. public static function getSupportedEncodings()
  25. {
  26. return static::$encodings;
  27. }
  28. /**
  29. * Constructor
  30. *
  31. * @throws Exception\ExtensionNotLoadedException
  32. */
  33. public function __construct()
  34. {
  35. if (!extension_loaded('intl')) {
  36. throw new Exception\ExtensionNotLoadedException(
  37. 'PHP extension "intl" is required for this wrapper'
  38. );
  39. }
  40. }
  41. /**
  42. * Returns the length of the given string
  43. *
  44. * @param string $str
  45. * @return int|false
  46. */
  47. public function strlen($str)
  48. {
  49. return grapheme_strlen($str);
  50. }
  51. /**
  52. * Returns the portion of string specified by the start and length parameters
  53. *
  54. * @param string $str
  55. * @param int $offset
  56. * @param int|null $length
  57. * @return string|false
  58. */
  59. public function substr($str, $offset = 0, $length = null)
  60. {
  61. return grapheme_substr($str, $offset, $length);
  62. }
  63. /**
  64. * Find the position of the first occurrence of a substring in a string
  65. *
  66. * @param string $haystack
  67. * @param string $needle
  68. * @param int $offset
  69. * @return int|false
  70. */
  71. public function strpos($haystack, $needle, $offset = 0)
  72. {
  73. return grapheme_strpos($haystack, $needle, $offset);
  74. }
  75. }