StringWrapperInterface.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. declare(strict_types=1);
  3. namespace Laminas\Stdlib\StringWrapper;
  4. use const STR_PAD_RIGHT;
  5. interface StringWrapperInterface
  6. {
  7. /**
  8. * Check if the given character encoding is supported by this wrapper
  9. * and the character encoding to convert to is also supported.
  10. *
  11. * @param string $encoding
  12. * @param string|null $convertEncoding
  13. */
  14. public static function isSupported($encoding, $convertEncoding = null);
  15. /**
  16. * Get a list of supported character encodings
  17. *
  18. * @return string[]
  19. */
  20. public static function getSupportedEncodings();
  21. /**
  22. * Set character encoding working with and convert to
  23. *
  24. * @param string $encoding The character encoding to work with
  25. * @param string|null $convertEncoding The character encoding to convert to
  26. * @return StringWrapperInterface
  27. */
  28. public function setEncoding($encoding, $convertEncoding = null);
  29. /**
  30. * Get the defined character encoding to work with (upper case)
  31. *
  32. * @return string|null
  33. */
  34. public function getEncoding();
  35. /**
  36. * Get the defined character encoding to convert to (upper case)
  37. *
  38. * @return string|null
  39. */
  40. public function getConvertEncoding();
  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. * Returns the portion of string specified by the start and length parameters
  50. *
  51. * @param string $str
  52. * @param int $offset
  53. * @param int|null $length
  54. * @return string|false
  55. */
  56. public function substr($str, $offset = 0, $length = null);
  57. /**
  58. * Find the position of the first occurrence of a substring in a string
  59. *
  60. * @param string $haystack
  61. * @param string $needle
  62. * @param int $offset
  63. * @return int|false
  64. */
  65. public function strpos($haystack, $needle, $offset = 0);
  66. /**
  67. * Convert a string from defined encoding to the defined convert encoding
  68. *
  69. * @param string $str
  70. * @param bool $reverse
  71. * @return string|false
  72. */
  73. public function convert($str, $reverse = false);
  74. /**
  75. * Wraps a string to a given number of characters
  76. *
  77. * @param string $str
  78. * @param int $width
  79. * @param string $break
  80. * @param bool $cut
  81. * @return string
  82. */
  83. public function wordWrap($str, $width = 75, $break = "\n", $cut = false);
  84. /**
  85. * Pad a string to a certain length with another string
  86. *
  87. * @param string $input
  88. * @param int $padLength
  89. * @param string $padString
  90. * @param int $padType
  91. * @return string
  92. */
  93. public function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT);
  94. }